162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *  linux/drivers/video/fm2fb.c -- BSC FrameMaster II/Rainbow II frame buffer
362306a36Sopenharmony_ci *				   device
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *	Copyright (C) 1998 Steffen A. Mork (linux-dev@morknet.de)
662306a36Sopenharmony_ci *	Copyright (C) 1999 Geert Uytterhoeven
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci *  Written for 2.0.x by Steffen A. Mork
962306a36Sopenharmony_ci *  Ported to 2.1.x by Geert Uytterhoeven
1062306a36Sopenharmony_ci *  Ported to new api by James Simmons
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci *  This file is subject to the terms and conditions of the GNU General Public
1362306a36Sopenharmony_ci *  License. See the file COPYING in the main directory of this archive for
1462306a36Sopenharmony_ci *  more details.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <linux/module.h>
1862306a36Sopenharmony_ci#include <linux/mm.h>
1962306a36Sopenharmony_ci#include <linux/fb.h>
2062306a36Sopenharmony_ci#include <linux/init.h>
2162306a36Sopenharmony_ci#include <linux/zorro.h>
2262306a36Sopenharmony_ci#include <asm/io.h>
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/*
2562306a36Sopenharmony_ci *	Some technical notes:
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci *	The BSC FrameMaster II (or Rainbow II) is a simple very dumb
2862306a36Sopenharmony_ci *	frame buffer which allows to display 24 bit true color images.
2962306a36Sopenharmony_ci *	Each pixel is 32 bit width so it's very easy to maintain the
3062306a36Sopenharmony_ci *	frame buffer. One long word has the following layout:
3162306a36Sopenharmony_ci *	AARRGGBB which means: AA the alpha channel byte, RR the red
3262306a36Sopenharmony_ci *	channel, GG the green channel and BB the blue channel.
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci *	The FrameMaster II supports the following video modes.
3562306a36Sopenharmony_ci *	- PAL/NTSC
3662306a36Sopenharmony_ci *	- interlaced/non interlaced
3762306a36Sopenharmony_ci *	- composite sync/sync/sync over green
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci *	The resolution is to the following both ones:
4062306a36Sopenharmony_ci *	- 768x576 (PAL)
4162306a36Sopenharmony_ci *	- 768x480 (NTSC)
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci *	This means that pixel access per line is fixed due to the
4462306a36Sopenharmony_ci *	fixed line width. In case of maximal resolution the frame
4562306a36Sopenharmony_ci *	buffer needs an amount of memory of 1.769.472 bytes which
4662306a36Sopenharmony_ci *	is near to 2 MByte (the allocated address space of Zorro2).
4762306a36Sopenharmony_ci *	The memory is channel interleaved. That means every channel
4862306a36Sopenharmony_ci *	owns four VRAMs. Unfortunately most FrameMasters II are
4962306a36Sopenharmony_ci *	not assembled with memory for the alpha channel. In this
5062306a36Sopenharmony_ci *	case it could be possible to add the frame buffer into the
5162306a36Sopenharmony_ci *	normal memory pool.
5262306a36Sopenharmony_ci *
5362306a36Sopenharmony_ci *	At relative address 0x1ffff8 of the frame buffers base address
5462306a36Sopenharmony_ci *	there exists a control register with the number of
5562306a36Sopenharmony_ci *	four control bits. They have the following meaning:
5662306a36Sopenharmony_ci *	bit value meaning
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci *	 0    1   0=interlaced/1=non interlaced
5962306a36Sopenharmony_ci *	 1    2   0=video out disabled/1=video out enabled
6062306a36Sopenharmony_ci *	 2    4   0=normal mode as jumpered via JP8/1=complement mode
6162306a36Sopenharmony_ci *	 3    8   0=read  onboard ROM/1 normal operation (required)
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci *	As mentioned above there are several jumper. I think there
6462306a36Sopenharmony_ci *	is not very much information about the FrameMaster II in
6562306a36Sopenharmony_ci *	the world so I add these information for completeness.
6662306a36Sopenharmony_ci *
6762306a36Sopenharmony_ci *	JP1  interlace selection (1-2 non interlaced/2-3 interlaced)
6862306a36Sopenharmony_ci *	JP2  wait state creation (leave as is!)
6962306a36Sopenharmony_ci *	JP3  wait state creation (leave as is!)
7062306a36Sopenharmony_ci *	JP4  modulate composite sync on green output (1-2 composite
7162306a36Sopenharmony_ci *	     sync on green channel/2-3 normal composite sync)
7262306a36Sopenharmony_ci *	JP5  create test signal, shorting this jumper will create
7362306a36Sopenharmony_ci *	     a white screen
7462306a36Sopenharmony_ci *	JP6  sync creation (1-2 composite sync/2-3 H-sync output)
7562306a36Sopenharmony_ci *	JP8  video mode (1-2 PAL/2-3 NTSC)
7662306a36Sopenharmony_ci *
7762306a36Sopenharmony_ci *	With the following jumpering table you can connect the
7862306a36Sopenharmony_ci *	FrameMaster II to a normal TV via SCART connector:
7962306a36Sopenharmony_ci *	JP1:  2-3
8062306a36Sopenharmony_ci *	JP4:  2-3
8162306a36Sopenharmony_ci *	JP6:  2-3
8262306a36Sopenharmony_ci *	JP8:  1-2 (means PAL for Europe)
8362306a36Sopenharmony_ci *
8462306a36Sopenharmony_ci *	NOTE:
8562306a36Sopenharmony_ci *	There is no other possibility to change the video timings
8662306a36Sopenharmony_ci *	except the interlaced/non interlaced, sync control and the
8762306a36Sopenharmony_ci *	video mode PAL (50 Hz)/NTSC (60 Hz). Inside this
8862306a36Sopenharmony_ci *	FrameMaster II driver are assumed values to avoid anomalies
8962306a36Sopenharmony_ci *	to a future X server. Except the pixel clock is really
9062306a36Sopenharmony_ci *	constant at 30 MHz.
9162306a36Sopenharmony_ci *
9262306a36Sopenharmony_ci *	9 pin female video connector:
9362306a36Sopenharmony_ci *
9462306a36Sopenharmony_ci *	1  analog red 0.7 Vss
9562306a36Sopenharmony_ci *	2  analog green 0.7 Vss
9662306a36Sopenharmony_ci *	3  analog blue 0.7 Vss
9762306a36Sopenharmony_ci *	4  H-sync TTL
9862306a36Sopenharmony_ci *	5  V-sync TTL
9962306a36Sopenharmony_ci *	6  ground
10062306a36Sopenharmony_ci *	7  ground
10162306a36Sopenharmony_ci *	8  ground
10262306a36Sopenharmony_ci *	9  ground
10362306a36Sopenharmony_ci *
10462306a36Sopenharmony_ci *	Some performance notes:
10562306a36Sopenharmony_ci *	The FrameMaster II was not designed to display a console
10662306a36Sopenharmony_ci *	this driver would do! It was designed to display still true
10762306a36Sopenharmony_ci *	color images. Imagine: When scroll up a text line there
10862306a36Sopenharmony_ci *	must copied ca. 1.7 MBytes to another place inside this
10962306a36Sopenharmony_ci *	frame buffer. This means 1.7 MByte read and 1.7 MByte write
11062306a36Sopenharmony_ci *	over the slow 16 bit wide Zorro2 bus! A scroll of one
11162306a36Sopenharmony_ci *	line needs 1 second so do not expect to much from this
11262306a36Sopenharmony_ci *	driver - he is at the limit!
11362306a36Sopenharmony_ci *
11462306a36Sopenharmony_ci */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/*
11762306a36Sopenharmony_ci *	definitions
11862306a36Sopenharmony_ci */
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define FRAMEMASTER_SIZE	0x200000
12162306a36Sopenharmony_ci#define FRAMEMASTER_REG		0x1ffff8
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define FRAMEMASTER_NOLACE	1
12462306a36Sopenharmony_ci#define FRAMEMASTER_ENABLE	2
12562306a36Sopenharmony_ci#define FRAMEMASTER_COMPL	4
12662306a36Sopenharmony_ci#define FRAMEMASTER_ROM		8
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_cistatic volatile unsigned char *fm2fb_reg;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cistatic struct fb_fix_screeninfo fb_fix = {
13162306a36Sopenharmony_ci	.smem_len =	FRAMEMASTER_REG,
13262306a36Sopenharmony_ci	.type =		FB_TYPE_PACKED_PIXELS,
13362306a36Sopenharmony_ci	.visual =	FB_VISUAL_TRUECOLOR,
13462306a36Sopenharmony_ci	.line_length =	(768 << 2),
13562306a36Sopenharmony_ci	.mmio_len =	(8),
13662306a36Sopenharmony_ci	.accel =	FB_ACCEL_NONE,
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_cistatic int fm2fb_mode = -1;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci#define FM2FB_MODE_PAL	0
14262306a36Sopenharmony_ci#define FM2FB_MODE_NTSC	1
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistatic struct fb_var_screeninfo fb_var_modes[] = {
14562306a36Sopenharmony_ci    {
14662306a36Sopenharmony_ci	/* 768 x 576, 32 bpp (PAL) */
14762306a36Sopenharmony_ci	768, 576, 768, 576, 0, 0, 32, 0,
14862306a36Sopenharmony_ci	{ 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
14962306a36Sopenharmony_ci	0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
15062306a36Sopenharmony_ci	33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
15162306a36Sopenharmony_ci    }, {
15262306a36Sopenharmony_ci	/* 768 x 480, 32 bpp (NTSC - not supported yet */
15362306a36Sopenharmony_ci	768, 480, 768, 480, 0, 0, 32, 0,
15462306a36Sopenharmony_ci	{ 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
15562306a36Sopenharmony_ci	0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
15662306a36Sopenharmony_ci	33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
15762306a36Sopenharmony_ci    }
15862306a36Sopenharmony_ci};
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci    /*
16162306a36Sopenharmony_ci     *  Interface used by the world
16262306a36Sopenharmony_ci     */
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_cistatic int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
16562306a36Sopenharmony_ci                           u_int transp, struct fb_info *info);
16662306a36Sopenharmony_cistatic int fm2fb_blank(int blank, struct fb_info *info);
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_cistatic const struct fb_ops fm2fb_ops = {
16962306a36Sopenharmony_ci	.owner		= THIS_MODULE,
17062306a36Sopenharmony_ci	FB_DEFAULT_IOMEM_OPS,
17162306a36Sopenharmony_ci	.fb_setcolreg	= fm2fb_setcolreg,
17262306a36Sopenharmony_ci	.fb_blank	= fm2fb_blank,
17362306a36Sopenharmony_ci};
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci    /*
17662306a36Sopenharmony_ci     *  Blank the display.
17762306a36Sopenharmony_ci     */
17862306a36Sopenharmony_cistatic int fm2fb_blank(int blank, struct fb_info *info)
17962306a36Sopenharmony_ci{
18062306a36Sopenharmony_ci	unsigned char t = FRAMEMASTER_ROM;
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci	if (!blank)
18362306a36Sopenharmony_ci		t |= FRAMEMASTER_ENABLE | FRAMEMASTER_NOLACE;
18462306a36Sopenharmony_ci	fm2fb_reg[0] = t;
18562306a36Sopenharmony_ci	return 0;
18662306a36Sopenharmony_ci}
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci    /*
18962306a36Sopenharmony_ci     *  Set a single color register. The values supplied are already
19062306a36Sopenharmony_ci     *  rounded down to the hardware's capabilities (according to the
19162306a36Sopenharmony_ci     *  entries in the var structure). Return != 0 for invalid regno.
19262306a36Sopenharmony_ci     */
19362306a36Sopenharmony_cistatic int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
19462306a36Sopenharmony_ci                         u_int transp, struct fb_info *info)
19562306a36Sopenharmony_ci{
19662306a36Sopenharmony_ci	if (regno < 16) {
19762306a36Sopenharmony_ci		red >>= 8;
19862306a36Sopenharmony_ci		green >>= 8;
19962306a36Sopenharmony_ci		blue >>= 8;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci		((u32*)(info->pseudo_palette))[regno] = (red << 16) |
20262306a36Sopenharmony_ci			(green << 8) | blue;
20362306a36Sopenharmony_ci	}
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	return 0;
20662306a36Sopenharmony_ci}
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci    /*
20962306a36Sopenharmony_ci     *  Initialisation
21062306a36Sopenharmony_ci     */
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_cistatic int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id);
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_cistatic const struct zorro_device_id fm2fb_devices[] = {
21562306a36Sopenharmony_ci	{ ZORRO_PROD_BSC_FRAMEMASTER_II },
21662306a36Sopenharmony_ci	{ ZORRO_PROD_HELFRICH_RAINBOW_II },
21762306a36Sopenharmony_ci	{ 0 }
21862306a36Sopenharmony_ci};
21962306a36Sopenharmony_ciMODULE_DEVICE_TABLE(zorro, fm2fb_devices);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_cistatic struct zorro_driver fm2fb_driver = {
22262306a36Sopenharmony_ci	.name		= "fm2fb",
22362306a36Sopenharmony_ci	.id_table	= fm2fb_devices,
22462306a36Sopenharmony_ci	.probe		= fm2fb_probe,
22562306a36Sopenharmony_ci};
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_cistatic int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id)
22862306a36Sopenharmony_ci{
22962306a36Sopenharmony_ci	struct fb_info *info;
23062306a36Sopenharmony_ci	unsigned long *ptr;
23162306a36Sopenharmony_ci	int is_fm;
23262306a36Sopenharmony_ci	int x, y;
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci	is_fm = z->id == ZORRO_PROD_BSC_FRAMEMASTER_II;
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci	if (!zorro_request_device(z,"fm2fb"))
23762306a36Sopenharmony_ci		return -ENXIO;
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	info = framebuffer_alloc(16 * sizeof(u32), &z->dev);
24062306a36Sopenharmony_ci	if (!info) {
24162306a36Sopenharmony_ci		zorro_release_device(z);
24262306a36Sopenharmony_ci		return -ENOMEM;
24362306a36Sopenharmony_ci	}
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci	if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
24662306a36Sopenharmony_ci		framebuffer_release(info);
24762306a36Sopenharmony_ci		zorro_release_device(z);
24862306a36Sopenharmony_ci		return -ENOMEM;
24962306a36Sopenharmony_ci	}
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci	/* assigning memory to kernel space */
25262306a36Sopenharmony_ci	fb_fix.smem_start = zorro_resource_start(z);
25362306a36Sopenharmony_ci	info->screen_base = ioremap(fb_fix.smem_start, FRAMEMASTER_SIZE);
25462306a36Sopenharmony_ci	fb_fix.mmio_start = fb_fix.smem_start + FRAMEMASTER_REG;
25562306a36Sopenharmony_ci	fm2fb_reg  = (unsigned char *)(info->screen_base+FRAMEMASTER_REG);
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci	strcpy(fb_fix.id, is_fm ? "FrameMaster II" : "Rainbow II");
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	/* make EBU color bars on display */
26062306a36Sopenharmony_ci	ptr = (unsigned long *)fb_fix.smem_start;
26162306a36Sopenharmony_ci	for (y = 0; y < 576; y++) {
26262306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0xffffff;/* white */
26362306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0xffff00;/* yellow */
26462306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0x00ffff;/* cyan */
26562306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0x00ff00;/* green */
26662306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0xff00ff;/* magenta */
26762306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0xff0000;/* red */
26862306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0x0000ff;/* blue */
26962306a36Sopenharmony_ci		for (x = 0; x < 96; x++) *ptr++ = 0x000000;/* black */
27062306a36Sopenharmony_ci	}
27162306a36Sopenharmony_ci	fm2fb_blank(0, info);
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	if (fm2fb_mode == -1)
27462306a36Sopenharmony_ci		fm2fb_mode = FM2FB_MODE_PAL;
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci	info->fbops = &fm2fb_ops;
27762306a36Sopenharmony_ci	info->var = fb_var_modes[fm2fb_mode];
27862306a36Sopenharmony_ci	info->pseudo_palette = info->par;
27962306a36Sopenharmony_ci	info->par = NULL;
28062306a36Sopenharmony_ci	info->fix = fb_fix;
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci	if (register_framebuffer(info) < 0) {
28362306a36Sopenharmony_ci		fb_dealloc_cmap(&info->cmap);
28462306a36Sopenharmony_ci		iounmap(info->screen_base);
28562306a36Sopenharmony_ci		framebuffer_release(info);
28662306a36Sopenharmony_ci		zorro_release_device(z);
28762306a36Sopenharmony_ci		return -EINVAL;
28862306a36Sopenharmony_ci	}
28962306a36Sopenharmony_ci	fb_info(info, "%s frame buffer device\n", fb_fix.id);
29062306a36Sopenharmony_ci	return 0;
29162306a36Sopenharmony_ci}
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_cistatic int __init fm2fb_setup(char *options)
29462306a36Sopenharmony_ci{
29562306a36Sopenharmony_ci	char *this_opt;
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_ci	if (!options || !*options)
29862306a36Sopenharmony_ci		return 0;
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_ci	while ((this_opt = strsep(&options, ",")) != NULL) {
30162306a36Sopenharmony_ci		if (!strncmp(this_opt, "pal", 3))
30262306a36Sopenharmony_ci			fm2fb_mode = FM2FB_MODE_PAL;
30362306a36Sopenharmony_ci		else if (!strncmp(this_opt, "ntsc", 4))
30462306a36Sopenharmony_ci			fm2fb_mode = FM2FB_MODE_NTSC;
30562306a36Sopenharmony_ci	}
30662306a36Sopenharmony_ci	return 0;
30762306a36Sopenharmony_ci}
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_cistatic int __init fm2fb_init(void)
31062306a36Sopenharmony_ci{
31162306a36Sopenharmony_ci	char *option = NULL;
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci	if (fb_get_options("fm2fb", &option))
31462306a36Sopenharmony_ci		return -ENODEV;
31562306a36Sopenharmony_ci	fm2fb_setup(option);
31662306a36Sopenharmony_ci	return zorro_register_driver(&fm2fb_driver);
31762306a36Sopenharmony_ci}
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_cimodule_init(fm2fb_init);
32062306a36Sopenharmony_ciMODULE_LICENSE("GPL");
321