1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * linux/drivers/video/fm2fb.c -- BSC FrameMaster II/Rainbow II frame buffer
3*4882a593Smuzhiyun * device
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 1998 Steffen A. Mork (linux-dev@morknet.de)
6*4882a593Smuzhiyun * Copyright (C) 1999 Geert Uytterhoeven
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Written for 2.0.x by Steffen A. Mork
9*4882a593Smuzhiyun * Ported to 2.1.x by Geert Uytterhoeven
10*4882a593Smuzhiyun * Ported to new api by James Simmons
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
13*4882a593Smuzhiyun * License. See the file COPYING in the main directory of this archive for
14*4882a593Smuzhiyun * more details.
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <linux/module.h>
18*4882a593Smuzhiyun #include <linux/mm.h>
19*4882a593Smuzhiyun #include <linux/fb.h>
20*4882a593Smuzhiyun #include <linux/init.h>
21*4882a593Smuzhiyun #include <linux/zorro.h>
22*4882a593Smuzhiyun #include <asm/io.h>
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun * Some technical notes:
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * The BSC FrameMaster II (or Rainbow II) is a simple very dumb
28*4882a593Smuzhiyun * frame buffer which allows to display 24 bit true color images.
29*4882a593Smuzhiyun * Each pixel is 32 bit width so it's very easy to maintain the
30*4882a593Smuzhiyun * frame buffer. One long word has the following layout:
31*4882a593Smuzhiyun * AARRGGBB which means: AA the alpha channel byte, RR the red
32*4882a593Smuzhiyun * channel, GG the green channel and BB the blue channel.
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun * The FrameMaster II supports the following video modes.
35*4882a593Smuzhiyun * - PAL/NTSC
36*4882a593Smuzhiyun * - interlaced/non interlaced
37*4882a593Smuzhiyun * - composite sync/sync/sync over green
38*4882a593Smuzhiyun *
39*4882a593Smuzhiyun * The resolution is to the following both ones:
40*4882a593Smuzhiyun * - 768x576 (PAL)
41*4882a593Smuzhiyun * - 768x480 (NTSC)
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * This means that pixel access per line is fixed due to the
44*4882a593Smuzhiyun * fixed line width. In case of maximal resolution the frame
45*4882a593Smuzhiyun * buffer needs an amount of memory of 1.769.472 bytes which
46*4882a593Smuzhiyun * is near to 2 MByte (the allocated address space of Zorro2).
47*4882a593Smuzhiyun * The memory is channel interleaved. That means every channel
48*4882a593Smuzhiyun * owns four VRAMs. Unfortunately most FrameMasters II are
49*4882a593Smuzhiyun * not assembled with memory for the alpha channel. In this
50*4882a593Smuzhiyun * case it could be possible to add the frame buffer into the
51*4882a593Smuzhiyun * normal memory pool.
52*4882a593Smuzhiyun *
53*4882a593Smuzhiyun * At relative address 0x1ffff8 of the frame buffers base address
54*4882a593Smuzhiyun * there exists a control register with the number of
55*4882a593Smuzhiyun * four control bits. They have the following meaning:
56*4882a593Smuzhiyun * bit value meaning
57*4882a593Smuzhiyun *
58*4882a593Smuzhiyun * 0 1 0=interlaced/1=non interlaced
59*4882a593Smuzhiyun * 1 2 0=video out disabled/1=video out enabled
60*4882a593Smuzhiyun * 2 4 0=normal mode as jumpered via JP8/1=complement mode
61*4882a593Smuzhiyun * 3 8 0=read onboard ROM/1 normal operation (required)
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun * As mentioned above there are several jumper. I think there
64*4882a593Smuzhiyun * is not very much information about the FrameMaster II in
65*4882a593Smuzhiyun * the world so I add these information for completeness.
66*4882a593Smuzhiyun *
67*4882a593Smuzhiyun * JP1 interlace selection (1-2 non interlaced/2-3 interlaced)
68*4882a593Smuzhiyun * JP2 wait state creation (leave as is!)
69*4882a593Smuzhiyun * JP3 wait state creation (leave as is!)
70*4882a593Smuzhiyun * JP4 modulate composite sync on green output (1-2 composite
71*4882a593Smuzhiyun * sync on green channel/2-3 normal composite sync)
72*4882a593Smuzhiyun * JP5 create test signal, shorting this jumper will create
73*4882a593Smuzhiyun * a white screen
74*4882a593Smuzhiyun * JP6 sync creation (1-2 composite sync/2-3 H-sync output)
75*4882a593Smuzhiyun * JP8 video mode (1-2 PAL/2-3 NTSC)
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * With the following jumpering table you can connect the
78*4882a593Smuzhiyun * FrameMaster II to a normal TV via SCART connector:
79*4882a593Smuzhiyun * JP1: 2-3
80*4882a593Smuzhiyun * JP4: 2-3
81*4882a593Smuzhiyun * JP6: 2-3
82*4882a593Smuzhiyun * JP8: 1-2 (means PAL for Europe)
83*4882a593Smuzhiyun *
84*4882a593Smuzhiyun * NOTE:
85*4882a593Smuzhiyun * There is no other possibility to change the video timings
86*4882a593Smuzhiyun * except the interlaced/non interlaced, sync control and the
87*4882a593Smuzhiyun * video mode PAL (50 Hz)/NTSC (60 Hz). Inside this
88*4882a593Smuzhiyun * FrameMaster II driver are assumed values to avoid anomalies
89*4882a593Smuzhiyun * to a future X server. Except the pixel clock is really
90*4882a593Smuzhiyun * constant at 30 MHz.
91*4882a593Smuzhiyun *
92*4882a593Smuzhiyun * 9 pin female video connector:
93*4882a593Smuzhiyun *
94*4882a593Smuzhiyun * 1 analog red 0.7 Vss
95*4882a593Smuzhiyun * 2 analog green 0.7 Vss
96*4882a593Smuzhiyun * 3 analog blue 0.7 Vss
97*4882a593Smuzhiyun * 4 H-sync TTL
98*4882a593Smuzhiyun * 5 V-sync TTL
99*4882a593Smuzhiyun * 6 ground
100*4882a593Smuzhiyun * 7 ground
101*4882a593Smuzhiyun * 8 ground
102*4882a593Smuzhiyun * 9 ground
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * Some performance notes:
105*4882a593Smuzhiyun * The FrameMaster II was not designed to display a console
106*4882a593Smuzhiyun * this driver would do! It was designed to display still true
107*4882a593Smuzhiyun * color images. Imagine: When scroll up a text line there
108*4882a593Smuzhiyun * must copied ca. 1.7 MBytes to another place inside this
109*4882a593Smuzhiyun * frame buffer. This means 1.7 MByte read and 1.7 MByte write
110*4882a593Smuzhiyun * over the slow 16 bit wide Zorro2 bus! A scroll of one
111*4882a593Smuzhiyun * line needs 1 second so do not expect to much from this
112*4882a593Smuzhiyun * driver - he is at the limit!
113*4882a593Smuzhiyun *
114*4882a593Smuzhiyun */
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /*
117*4882a593Smuzhiyun * definitions
118*4882a593Smuzhiyun */
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun #define FRAMEMASTER_SIZE 0x200000
121*4882a593Smuzhiyun #define FRAMEMASTER_REG 0x1ffff8
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun #define FRAMEMASTER_NOLACE 1
124*4882a593Smuzhiyun #define FRAMEMASTER_ENABLE 2
125*4882a593Smuzhiyun #define FRAMEMASTER_COMPL 4
126*4882a593Smuzhiyun #define FRAMEMASTER_ROM 8
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun static volatile unsigned char *fm2fb_reg;
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun static struct fb_fix_screeninfo fb_fix = {
131*4882a593Smuzhiyun .smem_len = FRAMEMASTER_REG,
132*4882a593Smuzhiyun .type = FB_TYPE_PACKED_PIXELS,
133*4882a593Smuzhiyun .visual = FB_VISUAL_TRUECOLOR,
134*4882a593Smuzhiyun .line_length = (768 << 2),
135*4882a593Smuzhiyun .mmio_len = (8),
136*4882a593Smuzhiyun .accel = FB_ACCEL_NONE,
137*4882a593Smuzhiyun };
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun static int fm2fb_mode = -1;
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun #define FM2FB_MODE_PAL 0
142*4882a593Smuzhiyun #define FM2FB_MODE_NTSC 1
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun static struct fb_var_screeninfo fb_var_modes[] = {
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun /* 768 x 576, 32 bpp (PAL) */
147*4882a593Smuzhiyun 768, 576, 768, 576, 0, 0, 32, 0,
148*4882a593Smuzhiyun { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
149*4882a593Smuzhiyun 0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
150*4882a593Smuzhiyun 33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
151*4882a593Smuzhiyun }, {
152*4882a593Smuzhiyun /* 768 x 480, 32 bpp (NTSC - not supported yet */
153*4882a593Smuzhiyun 768, 480, 768, 480, 0, 0, 32, 0,
154*4882a593Smuzhiyun { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
155*4882a593Smuzhiyun 0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
156*4882a593Smuzhiyun 33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun };
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun /*
161*4882a593Smuzhiyun * Interface used by the world
162*4882a593Smuzhiyun */
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun static int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
165*4882a593Smuzhiyun u_int transp, struct fb_info *info);
166*4882a593Smuzhiyun static int fm2fb_blank(int blank, struct fb_info *info);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun static const struct fb_ops fm2fb_ops = {
169*4882a593Smuzhiyun .owner = THIS_MODULE,
170*4882a593Smuzhiyun .fb_setcolreg = fm2fb_setcolreg,
171*4882a593Smuzhiyun .fb_blank = fm2fb_blank,
172*4882a593Smuzhiyun .fb_fillrect = cfb_fillrect,
173*4882a593Smuzhiyun .fb_copyarea = cfb_copyarea,
174*4882a593Smuzhiyun .fb_imageblit = cfb_imageblit,
175*4882a593Smuzhiyun };
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /*
178*4882a593Smuzhiyun * Blank the display.
179*4882a593Smuzhiyun */
fm2fb_blank(int blank,struct fb_info * info)180*4882a593Smuzhiyun static int fm2fb_blank(int blank, struct fb_info *info)
181*4882a593Smuzhiyun {
182*4882a593Smuzhiyun unsigned char t = FRAMEMASTER_ROM;
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun if (!blank)
185*4882a593Smuzhiyun t |= FRAMEMASTER_ENABLE | FRAMEMASTER_NOLACE;
186*4882a593Smuzhiyun fm2fb_reg[0] = t;
187*4882a593Smuzhiyun return 0;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /*
191*4882a593Smuzhiyun * Set a single color register. The values supplied are already
192*4882a593Smuzhiyun * rounded down to the hardware's capabilities (according to the
193*4882a593Smuzhiyun * entries in the var structure). Return != 0 for invalid regno.
194*4882a593Smuzhiyun */
fm2fb_setcolreg(u_int regno,u_int red,u_int green,u_int blue,u_int transp,struct fb_info * info)195*4882a593Smuzhiyun static int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
196*4882a593Smuzhiyun u_int transp, struct fb_info *info)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun if (regno < 16) {
199*4882a593Smuzhiyun red >>= 8;
200*4882a593Smuzhiyun green >>= 8;
201*4882a593Smuzhiyun blue >>= 8;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun ((u32*)(info->pseudo_palette))[regno] = (red << 16) |
204*4882a593Smuzhiyun (green << 8) | blue;
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun return 0;
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun /*
211*4882a593Smuzhiyun * Initialisation
212*4882a593Smuzhiyun */
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun static int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun static const struct zorro_device_id fm2fb_devices[] = {
217*4882a593Smuzhiyun { ZORRO_PROD_BSC_FRAMEMASTER_II },
218*4882a593Smuzhiyun { ZORRO_PROD_HELFRICH_RAINBOW_II },
219*4882a593Smuzhiyun { 0 }
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun MODULE_DEVICE_TABLE(zorro, fm2fb_devices);
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun static struct zorro_driver fm2fb_driver = {
224*4882a593Smuzhiyun .name = "fm2fb",
225*4882a593Smuzhiyun .id_table = fm2fb_devices,
226*4882a593Smuzhiyun .probe = fm2fb_probe,
227*4882a593Smuzhiyun };
228*4882a593Smuzhiyun
fm2fb_probe(struct zorro_dev * z,const struct zorro_device_id * id)229*4882a593Smuzhiyun static int fm2fb_probe(struct zorro_dev *z, const struct zorro_device_id *id)
230*4882a593Smuzhiyun {
231*4882a593Smuzhiyun struct fb_info *info;
232*4882a593Smuzhiyun unsigned long *ptr;
233*4882a593Smuzhiyun int is_fm;
234*4882a593Smuzhiyun int x, y;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun is_fm = z->id == ZORRO_PROD_BSC_FRAMEMASTER_II;
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun if (!zorro_request_device(z,"fm2fb"))
239*4882a593Smuzhiyun return -ENXIO;
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun info = framebuffer_alloc(16 * sizeof(u32), &z->dev);
242*4882a593Smuzhiyun if (!info) {
243*4882a593Smuzhiyun zorro_release_device(z);
244*4882a593Smuzhiyun return -ENOMEM;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
248*4882a593Smuzhiyun framebuffer_release(info);
249*4882a593Smuzhiyun zorro_release_device(z);
250*4882a593Smuzhiyun return -ENOMEM;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun /* assigning memory to kernel space */
254*4882a593Smuzhiyun fb_fix.smem_start = zorro_resource_start(z);
255*4882a593Smuzhiyun info->screen_base = ioremap(fb_fix.smem_start, FRAMEMASTER_SIZE);
256*4882a593Smuzhiyun fb_fix.mmio_start = fb_fix.smem_start + FRAMEMASTER_REG;
257*4882a593Smuzhiyun fm2fb_reg = (unsigned char *)(info->screen_base+FRAMEMASTER_REG);
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun strcpy(fb_fix.id, is_fm ? "FrameMaster II" : "Rainbow II");
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun /* make EBU color bars on display */
262*4882a593Smuzhiyun ptr = (unsigned long *)fb_fix.smem_start;
263*4882a593Smuzhiyun for (y = 0; y < 576; y++) {
264*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0xffffff;/* white */
265*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0xffff00;/* yellow */
266*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0x00ffff;/* cyan */
267*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0x00ff00;/* green */
268*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0xff00ff;/* magenta */
269*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0xff0000;/* red */
270*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0x0000ff;/* blue */
271*4882a593Smuzhiyun for (x = 0; x < 96; x++) *ptr++ = 0x000000;/* black */
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun fm2fb_blank(0, info);
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun if (fm2fb_mode == -1)
276*4882a593Smuzhiyun fm2fb_mode = FM2FB_MODE_PAL;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun info->fbops = &fm2fb_ops;
279*4882a593Smuzhiyun info->var = fb_var_modes[fm2fb_mode];
280*4882a593Smuzhiyun info->pseudo_palette = info->par;
281*4882a593Smuzhiyun info->par = NULL;
282*4882a593Smuzhiyun info->fix = fb_fix;
283*4882a593Smuzhiyun info->flags = FBINFO_DEFAULT;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun if (register_framebuffer(info) < 0) {
286*4882a593Smuzhiyun fb_dealloc_cmap(&info->cmap);
287*4882a593Smuzhiyun iounmap(info->screen_base);
288*4882a593Smuzhiyun framebuffer_release(info);
289*4882a593Smuzhiyun zorro_release_device(z);
290*4882a593Smuzhiyun return -EINVAL;
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun fb_info(info, "%s frame buffer device\n", fb_fix.id);
293*4882a593Smuzhiyun return 0;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
fm2fb_setup(char * options)296*4882a593Smuzhiyun int __init fm2fb_setup(char *options)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun char *this_opt;
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun if (!options || !*options)
301*4882a593Smuzhiyun return 0;
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun while ((this_opt = strsep(&options, ",")) != NULL) {
304*4882a593Smuzhiyun if (!strncmp(this_opt, "pal", 3))
305*4882a593Smuzhiyun fm2fb_mode = FM2FB_MODE_PAL;
306*4882a593Smuzhiyun else if (!strncmp(this_opt, "ntsc", 4))
307*4882a593Smuzhiyun fm2fb_mode = FM2FB_MODE_NTSC;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun return 0;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun
fm2fb_init(void)312*4882a593Smuzhiyun int __init fm2fb_init(void)
313*4882a593Smuzhiyun {
314*4882a593Smuzhiyun char *option = NULL;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun if (fb_get_options("fm2fb", &option))
317*4882a593Smuzhiyun return -ENODEV;
318*4882a593Smuzhiyun fm2fb_setup(option);
319*4882a593Smuzhiyun return zorro_register_driver(&fm2fb_driver);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun module_init(fm2fb_init);
323*4882a593Smuzhiyun MODULE_LICENSE("GPL");
324