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