162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *      linux/drivers/video/maxinefb.c
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *	DECstation 5000/xx onboard framebuffer support ... derived from:
562306a36Sopenharmony_ci *	"HP300 Topcat framebuffer support (derived from macfb of all things)
662306a36Sopenharmony_ci *	Phil Blundell <philb@gnu.org> 1998", the original code can be
762306a36Sopenharmony_ci *      found in the file hpfb.c in the same directory.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *      DECstation related code Copyright (C) 1999,2000,2001 by
1062306a36Sopenharmony_ci *      Michael Engel <engel@unix-ag.org> and
1162306a36Sopenharmony_ci *      Karsten Merker <merker@linuxtag.org>.
1262306a36Sopenharmony_ci *      This file is subject to the terms and conditions of the GNU General
1362306a36Sopenharmony_ci *      Public License.  See the file COPYING in the main directory of this
1462306a36Sopenharmony_ci *      archive for more details.
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/*
1962306a36Sopenharmony_ci * Changes:
2062306a36Sopenharmony_ci * 2001/01/27 removed debugging and testing code, fixed fb_ops
2162306a36Sopenharmony_ci *            initialization which had caused a crash before,
2262306a36Sopenharmony_ci *            general cleanup, first official release (KM)
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#include <linux/module.h>
2762306a36Sopenharmony_ci#include <linux/kernel.h>
2862306a36Sopenharmony_ci#include <linux/errno.h>
2962306a36Sopenharmony_ci#include <linux/string.h>
3062306a36Sopenharmony_ci#include <linux/mm.h>
3162306a36Sopenharmony_ci#include <linux/delay.h>
3262306a36Sopenharmony_ci#include <linux/init.h>
3362306a36Sopenharmony_ci#include <linux/fb.h>
3462306a36Sopenharmony_ci#include <video/maxinefb.h>
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/* bootinfo.h defines the machine type values, needed when checking */
3762306a36Sopenharmony_ci/* whether are really running on a maxine, KM                       */
3862306a36Sopenharmony_ci#include <asm/bootinfo.h>
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cistatic struct fb_info fb_info;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistatic const struct fb_var_screeninfo maxinefb_defined = {
4362306a36Sopenharmony_ci	.xres =		1024,
4462306a36Sopenharmony_ci	.yres =		768,
4562306a36Sopenharmony_ci	.xres_virtual =	1024,
4662306a36Sopenharmony_ci	.yres_virtual =	768,
4762306a36Sopenharmony_ci	.bits_per_pixel =8,
4862306a36Sopenharmony_ci	.activate =	FB_ACTIVATE_NOW,
4962306a36Sopenharmony_ci	.height =	-1,
5062306a36Sopenharmony_ci	.width =	-1,
5162306a36Sopenharmony_ci	.vmode =	FB_VMODE_NONINTERLACED,
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic struct fb_fix_screeninfo maxinefb_fix __initdata = {
5562306a36Sopenharmony_ci	.id =		"Maxine",
5662306a36Sopenharmony_ci	.smem_len =	(1024*768),
5762306a36Sopenharmony_ci	.type =		FB_TYPE_PACKED_PIXELS,
5862306a36Sopenharmony_ci	.visual =	FB_VISUAL_PSEUDOCOLOR,
5962306a36Sopenharmony_ci	.line_length =	1024,
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/* Handle the funny Inmos RamDAC/video controller ... */
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_civoid maxinefb_ims332_write_register(int regno, register unsigned int val)
6562306a36Sopenharmony_ci{
6662306a36Sopenharmony_ci	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
6762306a36Sopenharmony_ci	unsigned char *wptr;
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	wptr = regs + 0xa0000 + (regno << 4);
7062306a36Sopenharmony_ci	*((volatile unsigned int *) (regs)) = (val >> 8) & 0xff00;
7162306a36Sopenharmony_ci	*((volatile unsigned short *) (wptr)) = val;
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciunsigned int maxinefb_ims332_read_register(int regno)
7562306a36Sopenharmony_ci{
7662306a36Sopenharmony_ci	register unsigned char *regs = (char *) MAXINEFB_IMS332_ADDRESS;
7762306a36Sopenharmony_ci	unsigned char *rptr;
7862306a36Sopenharmony_ci	register unsigned int j, k;
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	rptr = regs + 0x80000 + (regno << 4);
8162306a36Sopenharmony_ci	j = *((volatile unsigned short *) rptr);
8262306a36Sopenharmony_ci	k = *((volatile unsigned short *) regs);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	return (j & 0xffff) | ((k & 0xff00) << 8);
8562306a36Sopenharmony_ci}
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* Set the palette */
8862306a36Sopenharmony_cistatic int maxinefb_setcolreg(unsigned regno, unsigned red, unsigned green,
8962306a36Sopenharmony_ci			      unsigned blue, unsigned transp, struct fb_info *info)
9062306a36Sopenharmony_ci{
9162306a36Sopenharmony_ci	/* value to be written into the palette reg. */
9262306a36Sopenharmony_ci	unsigned long hw_colorvalue = 0;
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	if (regno > 255)
9562306a36Sopenharmony_ci		return 1;
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	red   >>= 8;    /* The cmap fields are 16 bits    */
9862306a36Sopenharmony_ci	green >>= 8;    /* wide, but the harware colormap */
9962306a36Sopenharmony_ci	blue  >>= 8;    /* registers are only 8 bits wide */
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci	hw_colorvalue = (blue << 16) + (green << 8) + (red);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	maxinefb_ims332_write_register(IMS332_REG_COLOR_PALETTE + regno,
10462306a36Sopenharmony_ci				       hw_colorvalue);
10562306a36Sopenharmony_ci	return 0;
10662306a36Sopenharmony_ci}
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cistatic const struct fb_ops maxinefb_ops = {
10962306a36Sopenharmony_ci	.owner		= THIS_MODULE,
11062306a36Sopenharmony_ci	FB_DEFAULT_IOMEM_OPS,
11162306a36Sopenharmony_ci	.fb_setcolreg	= maxinefb_setcolreg,
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ciint __init maxinefb_init(void)
11562306a36Sopenharmony_ci{
11662306a36Sopenharmony_ci	unsigned long fboff;
11762306a36Sopenharmony_ci	unsigned long fb_start;
11862306a36Sopenharmony_ci	int i;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	if (fb_get_options("maxinefb", NULL))
12162306a36Sopenharmony_ci		return -ENODEV;
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	/* Validate we're on the proper machine type */
12462306a36Sopenharmony_ci	if (mips_machtype != MACH_DS5000_XX) {
12562306a36Sopenharmony_ci		return -EINVAL;
12662306a36Sopenharmony_ci	}
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	printk(KERN_INFO "Maxinefb: Personal DECstation detected\n");
12962306a36Sopenharmony_ci	printk(KERN_INFO "Maxinefb: initializing onboard framebuffer\n");
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	/* Framebuffer display memory base address */
13262306a36Sopenharmony_ci	fb_start = DS5000_xx_ONBOARD_FBMEM_START;
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	/* Clear screen */
13562306a36Sopenharmony_ci	for (fboff = fb_start; fboff < fb_start + 0x1ffff; fboff++)
13662306a36Sopenharmony_ci		*(volatile unsigned char *)fboff = 0x0;
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	maxinefb_fix.smem_start = fb_start;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	/* erase hardware cursor */
14162306a36Sopenharmony_ci	for (i = 0; i < 512; i++) {
14262306a36Sopenharmony_ci		maxinefb_ims332_write_register(IMS332_REG_CURSOR_RAM + i,
14362306a36Sopenharmony_ci					       0);
14462306a36Sopenharmony_ci		/*
14562306a36Sopenharmony_ci		   if (i&0x8 == 0)
14662306a36Sopenharmony_ci		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0x0f);
14762306a36Sopenharmony_ci		   else
14862306a36Sopenharmony_ci		   maxinefb_ims332_write_register (IMS332_REG_CURSOR_RAM + i, 0xf0);
14962306a36Sopenharmony_ci		 */
15062306a36Sopenharmony_ci	}
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	fb_info.fbops = &maxinefb_ops;
15362306a36Sopenharmony_ci	fb_info.screen_base = (char *)maxinefb_fix.smem_start;
15462306a36Sopenharmony_ci	fb_info.var = maxinefb_defined;
15562306a36Sopenharmony_ci	fb_info.fix = maxinefb_fix;
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci	fb_alloc_cmap(&fb_info.cmap, 256, 0);
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	if (register_framebuffer(&fb_info) < 0)
16062306a36Sopenharmony_ci		return 1;
16162306a36Sopenharmony_ci	return 0;
16262306a36Sopenharmony_ci}
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_cistatic void __exit maxinefb_exit(void)
16562306a36Sopenharmony_ci{
16662306a36Sopenharmony_ci	unregister_framebuffer(&fb_info);
16762306a36Sopenharmony_ci}
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#ifdef MODULE
17062306a36Sopenharmony_ciMODULE_LICENSE("GPL");
17162306a36Sopenharmony_ci#endif
17262306a36Sopenharmony_cimodule_init(maxinefb_init);
17362306a36Sopenharmony_cimodule_exit(maxinefb_exit);
17462306a36Sopenharmony_ci
175