2 * linux/arch/m68knommu/console/68328fb.c -- Low level implementation of the
3 * mc68328 LCD frame buffer device
5 * Copyright (C) 1998,1999 Kenneth Albanowski <kjahds@kjahds.com>,
6 * The Silver Hammer Group, Ltd.
9 * This file is based on the Amiga CyberVision frame buffer device (Cyberfb.c):
11 * Copyright (C) 1996 Martin Apel
15 * This file is based on the Amiga frame buffer device (amifb.c):
17 * Copyright (C) 1995 Geert Uytterhoeven
21 * - 17 Feb 98: Original version by Kenneth Albanowski <kjahds@kjahds.com>
24 * This file is subject to the terms and conditions of the GNU General Public
25 * License. See the file COPYING in the main directory of this archive
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/string.h>
34 #include <linux/tty.h>
35 #include <linux/slab.h>
36 #include <linux/delay.h>
37 #include <linux/config.h>
38 #include <asm/segment.h>
39 #include <asm/system.h>
41 #include <asm/pgtable.h>
44 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
46 static struct fb_info fb_info;
49 * mc68328vision Graphics Board
52 #define CYBER8_WIDTH 1152
53 #define CYBER8_HEIGHT 886
54 #define CYBER8_PIXCLOCK 12500 /* ++Geert: Just a guess */
56 #define CYBER16_WIDTH 800
57 #define CYBER16_HEIGHT 600
58 #define CYBER16_PIXCLOCK 25000 /* ++Geert: Just a guess */
60 #define PALM_WIDTH 160
61 #define PALM_HEIGHT 160
63 /*static int mc68328Key = 0;
64 static u_char mc68328_colour_table [256][4];*/
67 * Predefined Video Mode Names
70 static char *mc68328_fb_modenames[] = {
73 * Autodetect (Default) Video Mode
79 * Predefined Video Modes
82 "Palm", /* Palm Pilot devices, 1.0 and higher */
83 "Palm Grey", /* Palm Pilot devices, 1.0 and higher */
89 "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy",
91 "dummy", "dummy", "dummy", "dummy", "dummy", "dummy", "dummy",
93 "dummy", "dummy", "dummy", "dummy",
96 * User Defined Video Modes
98 * This doesn't work yet!!
101 "user0", "user1", "user2", "user3", "user4", "user5", "user6",
107 * Predefined Video Mode Definitions
110 static struct fb_var_screeninfo mc68328_fb_predefined[] = {
113 * Autodetect (Default) Video Mode
119 * Predefined Video Modes
124 PALM_WIDTH, PALM_HEIGHT, PALM_WIDTH, PALM_HEIGHT,
127 {0, 1, 0}, {0, 1, 0}, {0, 1, 0}, {0, 0, 0},
129 -1, -1, /* phys height, width */
131 0, 0, 0, 0, 0, 0, 0, /* timing */
133 FB_VMODE_NONINTERLACED},
136 PALM_WIDTH, PALM_HEIGHT, PALM_WIDTH, PALM_HEIGHT,
139 {0, 2, 0}, {0, 2, 0}, {0, 2, 0}, {0, 0, 0},
141 -1, -1, /* phys height, width */
143 0, 0, 0, 0, 0, 0, 0, /* timing */
145 FB_VMODE_NONINTERLACED},
151 {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,},
152 {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,},
156 * User Defined Video Modes
159 {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}, {0,}
162 static struct fb_fix_screeninfo mc68328_fix __initdata = {
164 .smem_len = 160 * 160 /8;
165 .type = FB_TYPE_PACKED_PIXELS;
166 .accel = FB_ACCEL_NONE;
169 #define NUM_TOTAL_MODES arraysize(mc68328_fb_predefined)
170 #define NUM_PREDEF_MODES (3)
172 static int mc68328fb_inverse = 0;
173 static int mc68328fb_mode = 0;
174 static int mc68328fbCursorMode = 0;
180 #define PALM_DEFMODE (1)
181 #define CYBER16_DEFMODE (2)
184 * Interface used by the world
186 int mc68328_fb_init(void);
188 static int mc68328fb_setcolreg(u_int regno, u_int red, u_int green,
189 u_int blue, u_int transp);
190 static void mc68328fb_blank(int blank, struct fb_info *info);
193 * Accelerated Functions used by the low level console driver
196 void mc68328_WaitQueue(u_short fifo);
197 void mc68328_WaitBlit(void);
198 void mc68328_BitBLT(u_short curx, u_short cury, u_short destx,
199 u_short desty, u_short width, u_short height,
201 void mc68328_RectFill(u_short x, u_short y, u_short width, u_short height,
202 u_short mode, u_short color);
203 void mc68328_MoveCursor(u_short x, u_short y);
208 static int get_video_mode(const char *name);
211 * Set a single color register. The values supplied are already
212 * rounded down to the hardware's capabilities (according to the
213 * entries in the var structure). Return != 0 for invalid regno.
216 static int mc68328fb_setcolreg(u_int regno, u_int red, u_int green,
217 u_int blue, u_int transp)
224 *(mc68328Regs + 0x3c8) = (char) regno;
225 mc68328_colour_table[regno][0] = red & 0xff;
226 mc68328_colour_table[regno][1] = green & 0xff;
227 mc68328_colour_table[regno][2] = blue & 0xff;
228 mc68328_colour_table[regno][3] = transp;
230 *(mc68328Regs + 0x3c9) = (red & 0xff) >> 2;
231 *(mc68328Regs + 0x3c9) = (green & 0xff) >> 2;
232 *(mc68328Regs + 0x3c9) = (blue & 0xff) >> 2;
239 * (Un)Blank the screen
242 static void mc68328fb_blank(int blank, struct fb_info *info)
246 (*(volatile unsigned char *) 0xFFFFFA27) &= ~128;
248 (*(volatile unsigned char *) 0xFFFFFA27) |= 128;
253 /**************************************************************
254 * We are waiting for "fifo" FIFO-slots empty
256 void mc68328_WaitQueue(u_short fifo)
260 /**************************************************************
261 * We are waiting for Hardware (Graphics Engine) not busy
263 void mc68328_WaitBlit(void)
267 /**************************************************************
268 * BitBLT - Through the Plane
270 void mc68328_BitBLT(u_short curx, u_short cury, u_short destx,
271 u_short desty, u_short width, u_short height,
275 u_short blitcmd = S3_BITBLT;
277 /* Set drawing direction */
278 /* -Y, X maj, -X (default) */
280 blitcmd |= 0x0020; /* Drawing direction +X */
283 destx += (width - 1);
287 blitcmd |= 0x0080; /* Drawing direction +Y */
289 cury += (height - 1);
290 desty += (height - 1);
293 mc68328_WaitQueue(0x8000);
295 *((u_short volatile *) (mc68328Regs + S3_PIXEL_CNTL)) = 0xa000;
296 *((u_short volatile *) (mc68328Regs + S3_FRGD_MIX)) =
299 *((u_short volatile *) (mc68328Regs + S3_CUR_X)) = curx;
300 *((u_short volatile *) (mc68328Regs + S3_CUR_Y)) = cury;
302 *((u_short volatile *) (mc68328Regs + S3_DESTX_DIASTP)) = destx;
303 *((u_short volatile *) (mc68328Regs + S3_DESTY_AXSTP)) = desty;
305 *((u_short volatile *) (mc68328Regs + S3_MIN_AXIS_PCNT)) =
307 *((u_short volatile *) (mc68328Regs + S3_MAJ_AXIS_PCNT)) =
310 *((u_short volatile *) (mc68328Regs + S3_CMD)) = blitcmd;
314 /**************************************************************
315 * Rectangle Fill Solid
317 void mc68328_RectFill(u_short x, u_short y, u_short width, u_short height,
318 u_short mode, u_short color)
321 u_short blitcmd = S3_FILLEDRECT;
323 mc68328_WaitQueue(0x8000);
325 *((u_short volatile *) (mc68328Regs + S3_PIXEL_CNTL)) = 0xa000;
326 *((u_short volatile *) (mc68328Regs + S3_FRGD_MIX)) =
329 *((u_short volatile *) (mc68328Regs + S3_MULT_MISC)) = 0xe000;
330 *((u_short volatile *) (mc68328Regs + S3_FRGD_COLOR)) = color;
332 *((u_short volatile *) (mc68328Regs + S3_CUR_X)) = x;
333 *((u_short volatile *) (mc68328Regs + S3_CUR_Y)) = y;
335 *((u_short volatile *) (mc68328Regs + S3_MIN_AXIS_PCNT)) =
337 *((u_short volatile *) (mc68328Regs + S3_MAJ_AXIS_PCNT)) =
340 *((u_short volatile *) (mc68328Regs + S3_CMD)) = blitcmd;
345 /**************************************************************
346 * Move cursor to x, y
348 void mc68328_MoveCursor(u_short x, u_short y)
350 (*(volatile unsigned short *) 0xFFFFFA18) =
351 (mc68328fbCursorMode << 14) | x;
352 (*(volatile unsigned short *) 0xFFFFFA1A) = y;
354 *(mc68328Regs + S3_CRTC_ADR) = 0x39;
355 *(mc68328Regs + S3_CRTC_DATA) = 0xa0;
357 *(mc68328Regs + S3_CRTC_ADR) = S3_HWGC_ORGX_H;
358 *(mc68328Regs + S3_CRTC_DATA) = (char) ((x & 0x0700) >> 8);
359 *(mc68328Regs + S3_CRTC_ADR) = S3_HWGC_ORGX_L;
360 *(mc68328Regs + S3_CRTC_DATA) = (char) (x & 0x00ff);
362 *(mc68328Regs + S3_CRTC_ADR) = S3_HWGC_ORGY_H;
363 *(mc68328Regs + S3_CRTC_DATA) = (char) ((y & 0x0700) >> 8);
364 *(mc68328Regs + S3_CRTC_ADR) = S3_HWGC_ORGY_L;
365 *(mc68328Regs + S3_CRTC_DATA) = (char) (y & 0x00ff);
369 /* -------------------- Generic routines ------------------------------------ */
375 static u_short red16[] =
376 { 0xc000, 0x0000, 0x0000, 0x0000, 0xc000, 0xc000, 0xc000, 0x0000,
377 0x8000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff
379 static u_short green16[] =
380 { 0xc000, 0x0000, 0xc000, 0xc000, 0x0000, 0x0000, 0xc000, 0x0000,
381 0x8000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff
383 static u_short blue16[] =
384 { 0xc000, 0x0000, 0x0000, 0xc000, 0x0000, 0xc000, 0x0000, 0x0000,
385 0x8000, 0xffff, 0x0000, 0xffff, 0x0000, 0xffff, 0x0000, 0xffff
389 static struct fb_cmap default_16_colors =
390 { 0, 16, red16, green16, blue16, NULL };
393 static struct fb_cmap *get_default_colormap(int bpp)
395 return (&default_16_colors);
399 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7fff-(val))>>16)
400 #define CNVT_FROMHW(val,width) (((width) ? ((((val)<<16)-(val)) / \
401 ((1<<(width))-1)) : 0))
403 static struct fb_ops mc68328_fb_ops = {
404 .owner = THIS_MODULE,
405 .fb_setcolreg = mc68328fb_setcolreg,
406 .fb_fillrect = cfbfillrect,
407 .fb_copyarea = cfbcopyarea,
408 .fb_imageblit = cfbimgblt,
409 .fb_cursor = softcursor,
417 int __init mc68328_fb_init(void)
419 if (mc68328fb_mode == -1)
420 mc68328fb_mode = PALM_DEFMODE;
421 mc68328_fix.smem_start = (*(volatile unsigned long *) 0xFFFFFA00);
422 /*kernel_map (board_addr + 0x01400000, 0x00400000, */
424 info->var = mc68328_fb_predefined[mc68328fb_mode];
426 if (info->var.bits_per_pixel == 1)
427 fix->visual = FB_VISUAL_MONO01;
429 fix->visual = FB_VISUAL_DIRECTCOLOR;
430 info->screen_base = (u_char *) mc68328_fix.smem_start;
432 if (register_framebuffer(&fb_info) < 0)
433 panic("Cannot register frame buffer\n");
441 static int get_video_mode(const char *name)
445 for (i = 1; i < NUM_PREDEF_MODES; i++)
446 if (!strcmp(name, mc68328_fb_modenames[i]))