/*
 * linux/arch/m68k/amiga/amifb.c -- Low level implementation of the Amiga frame
 *                                  buffer device
 *
 *    Copyright (C) 1995 Geert Uytterhoeven
 *
 *
 * This file is based on the Atari frame buffer device (atafb.c):
 *
 *    Copyright (C) 1994 Martin Schaller
 *                       Roman Hodek
 *
 *          with work by Andreas Schwab
 *                       Guenther Kelleter
 *
 * and on the original Amiga console driver (amicon.c):
 *
 *    Copyright (C) 1993 Hamish Macdonald
 *                       Greg Harp
 *    Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
 *
 *          with work by William Rucklidge (wjr@cs.cornell.edu)
 *                       Geert Uytterhoeven
 *                       Jes Sorensen (jds@kom.auc.dk)
 *
 *
 * History:
 *
 *   -  2 Dec 95: AGA version by Geert Uytterhoeven
 *
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 */


#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/malloc.h>
#include <linux/delay.h>
#include <linux/config.h>
#include <linux/interrupt.h>
#include <asm/segment.h>
#include <asm/system.h>
#include <asm/irq.h>
#include <asm/amigahw.h>
#include <asm/amigaints.h>
#include <asm/bootinfo.h>
#include <linux/fb.h>


#undef  CONFIG_AMIFB_OCS
#undef  CONFIG_AMIFB_ECS
#define CONFIG_AMIFB_AGA   /* Only AGA support at the moment */

#define USE_MONO_AMIFB_IF_NON_AGA


/* -------------------- BEGIN: TODO ----------------------------------------- **


   - scan the sources for `TODO'

   - timings and monspecs can be set via the kernel command line (cfr. Atari)

   - OCS and ECS

   - hardware cursor

   - Interlaced screen -> Interlaced sprite/hardware cursor


** -------------------- END: TODO ------------------------------------------- */


/*******************************************************************************


   Generic video timings
   ---------------------

   Timings used by the frame buffer interface:

   +----------+---------------------------------------------+----------+-------+
   |          |                ^                            |          |       |
   |          |                |upper_margin                |          |       |
   |          |                ¥                            |          |       |
   +----------###############################################----------+-------+
   |          #                ^                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |   left   #                |                            #  right   | hsync |
   |  margin  #                |       xres                 #  margin  |  len  |
   |<-------->#<---------------+--------------------------->#<-------->|<----->|
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |yres                        #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                |                            #          |       |
   |          #                ¥                            #          |       |
   +----------###############################################----------+-------+
   |          |                ^                            |          |       |
   |          |                |lower_margin                |          |       |
   |          |                ¥                            |          |       |
   +----------+---------------------------------------------+----------+-------+
   |          |                ^                            |          |       |
   |          |                |vsync_len                   |          |       |
   |          |                ¥                            |          |       |
   +----------+---------------------------------------------+----------+-------+


   Amiga video timings
   -------------------

   The Amiga native chipsets uses another timing scheme:

      - hsstrt:   Start of horizontal synchronization pulse
      - hsstop:   End of horizontal synchronization pulse
      - htotal:   Last value on the line (i.e. line length = htotal+1)
      - vsstrt:   Start of vertical synchronization pulse
      - vsstop:   Start of vertical synchronization pulse
      - vtotal:   Last line value (i.e. number of lines = vtotal+1)
      - hcenter:  Start of vertical retrace for interlace

   You can specify the blanking timings independently. Currently I just set
   them equal to the respective synchronization values:

      - hbstrt:   Start of horizontal blank
      - hbstop:   End of horizontal blank
      - vbstrt:   Start of vertical blank
      - vbstop:   Start of vertical blank

   Horizontal values are in color clock cycles (280 ns), vertical values are in
   scanlines.

   (0, 0) is somewhere in the upper-left corner :-)


   Amiga visible window definitions
   --------------------------------

   Currently I only have values for AGA, SHRES (28 MHz dotclock). Feel free to
   make corrections and/or additions.

   Within the above synchronization specifications, the visible window is
   defined by the following parameters (actual register resolutions may be
   different; all horizontal values are normalized with respect to the pixel
   clock):

      - diwstrt_h:   Horizontal start of the visible window
      - diwstop_h:   Horizontal stop+1(*) of the visible window
      - diwstrt_v:   Vertical start of the visible window
      - diwstop_v:   Vertical stop of the visible window
      - ddfstrt:     Horizontal start of display DMA
      - ddfstop:     Horizontal stop of display DMA
      - hscroll:     Horizontal display output delay

   Sprite positioning:

      - sprstrt_h:   Horizontal start-4 of sprite
      - sprstrt_v:   Vertical start of sprite

   (*) Even Commodore did it wrong in the AGA monitor drivers by not adding 1.

   Horizontal values are in dotclock cycles (35 ns), vertical values are in
   scanlines.

   (0, 0) is somewhere in the upper-left corner :-)


   Dependencies (AGA, SHRES (35 ns dotclock))
   -------------------------------------------

   Since there are much more parameters for the Amiga display than for the
   frame buffer interface, there must be some dependencies among the Amiga display
   parameters. Here's what I found out:

      - ddfstrt and ddfstop are best aligned to 64 pixels.
      - the chipset needs 64+4 horizontal pixels after the DMA start before the
        first pixel is output, so diwstrt_h = ddfstrt+64+4 if you want to
        display the first pixel on the line too. Increase diwstrt_h for virtual
        screen panning.
      - the display DMA always fetches 64 pixels at a time (*).
      - ddfstop is ddfstrt+#pixels-64.
      - diwstop_h = diwstrt_h+xres+1. Because of the additional 1 this can be 1
        more than htotal.
      - hscroll simply adds a delay to the display output. Smooth horizontal
        panning needs an extra 64 pixels on the left to prefetch the pixels that
        `fall off' on the left.
      - if ddfstrt < 192, the sprite DMA cycles are all stolen by the bitplane
        DMA, so it's best to make the DMA start as late as possible.
      - you really don't want to make ddfstrt < 128, since this will steal DMA
        cycles from the other DMA channels (audio, floppy and Chip RAM refresh).
      - I make diwstop_h and diwstop_v as large as possible.

   (*) This is for fmode = 3. Lower fmodes allow for more freedom w.r.t. the
       timings, but they limit the maximum display depth, and cause more stress
       on the custom chip bus.


   DMA priorities
   --------------

   Since there are limits on the earliest start value for display DMA and the
   display of sprites, I use the following policy on horizontal panning and
   the hardware cursor:

      - if you want to start display DMA too early, you loose the ability to
        do smooth horizontal panning (xpanstep 1 -> 64).
      - if you want to go even further, you loose the hardware cursor too.

   IMHO a hardware cursor is more important for X than horizontal scrolling,
   so that's my motivation.


   Implementation
   --------------

   aga_decode_var() converts the frame buffer values to the Amiga values. It's
   just a `straightforward' implementation of the above rules.


   Standard VGA timings
   --------------------

               xres  yres    left  right  upper  lower    hsync    vsync
               ----  ----    ----  -----  -----  -----    -----    -----
      80x25     720   400      27     45     35     12      108        2
      80x30     720   480      27     45     30      9      108        2

   These were taken from a XFree86 configuration file, recalculated for a 28 MHz
   dotclock (Amigas don't have a 25 MHz dotclock) and converted to frame buffer
   generic timings.

   As a comparison, graphics/monitor.h suggests the following:

               xres  yres    left  right  upper  lower    hsync    vsync
               ----  ----    ----  -----  -----  -----    -----    -----

      VGA       640   480      52    112     24     19    112 -      2 +
      VGA70     640   400      52    112     27     21    112 -      2 -


   Sync polarities
   ---------------

      VSYNC    HSYNC    Vertical size    Vertical total
      -----    -----    -------------    --------------
        +        +           Reserved          Reserved
        +        -                400               414
        -        +                350               362
        -        -                480               496

   Source: CL-GD542X Technical Reference Manual, Cirrus Logic, Oct 1992


   Broadcast video timings
   -----------------------

   Since broadcast video timings are `fixed' and only depend on the video
   system (PAL/NTSC), hsync_len and vsync_len are not used and must be set to
   zero. All xres/yres and margin values are defined within the `visible
   rectangle' of the display.

   According to the CCIR and RETMA specifications, we have the following values:

   CCIR -> PAL
   -----------

      - a scanline is 64 µs long, of which 52.48 µs are visible. This is about
        736 visible 70 ns pixels per line.
      - we have 625 scanlines, of which 575 are visible (interlaced); after
        rounding this becomes 576.

   RETMA -> NTSC
   -------------

      - a scanline is 63.5 µs long, of which 53.5 µs are visible.  This is about
        736 visible 70 ns pixels per line.
      - we have 525 scanlines, of which 485 are visible (interlaced); after
        rounding this becomes 484.

   Thus if you want a PAL compatible display, you have to do the following:

      - set the FB_SYNC_BROADCAST flag to indicate that standard broadcast
        timings are to be used.
      - make sure upper_margin+yres+lower_margin = 576 for an interlaced, 288
        for a non-interlaced and 144 for a doublescanned display.
      - make sure (left_margin+xres+right_margin)*pixclock is a reasonable
        approximation to 52.48 µs.

   The settings for a NTSC compatible display are straightforward.

   Note that in a strict sense the PAL and NTSC standards only define the
   encoding of the color part (chrominance) of the video signal and don't say
   anything about horizontal/vertical synchronization nor refresh rates.
   But since Amigas have RGB output, this issue isn't of any importance here.


                                                            -- Geert --

*******************************************************************************/


   /*
    *    Custom Chipset Definitions
    */

#define CUSTOM_OFS(fld) ((long)&((struct CUSTOM*)0)->fld)


   /*
    *    BPLCON0 -- Bitplane Control Register 0
    */

#define BPC0_HIRES      (0x8000)
#define BPC0_BPU2       (0x4000) /* Bit plane used count */
#define BPC0_BPU1       (0x2000)
#define BPC0_BPU0       (0x1000)
#define BPC0_HAM        (0x0800) /* HAM mode */
#define BPC0_DPF        (0x0400) /* Double playfield */
#define BPC0_COLOR      (0x0200) /* Enable colorburst */
#define BPC0_GAUD       (0x0100) /* Genlock audio enable */
#define BPC0_UHRES      (0x0080) /* Ultrahi res enable */
#define BPC0_SHRES      (0x0040) /* Super hi res mode */
#define BPC0_BYPASS     (0x0020) /* Bypass LUT - AGA */
#define BPC0_BPU3       (0x0010) /* AGA */
#define BPC0_LPEN       (0x0008) /* Light pen enable */
#define BPC0_LACE       (0x0004) /* Interlace */
#define BPC0_ERSY       (0x0002) /* External resync */
#define BPC0_ECSENA     (0x0001) /* ECS emulation disable */


   /*
    *    BPLCON2 -- Bitplane Control Register 2
    */

#define BPC2_ZDBPSEL2   (0x4000) /* Bitplane to be used for ZD - AGA */
#define BPC2_ZDBPSEL1   (0x2000)
#define BPC2_ZDBPSEL0   (0x1000)
#define BPC2_ZDBPEN     (0x0800) /* Enable ZD with ZDBPSELx - AGA */
#define BPC2_ZDCTEN     (0x0400) /* Enable ZD with palette bit #31 - AGA */
#define BPC2_KILLEHB    (0x0200) /* Kill EHB mode - AGA */
#define BPC2_RDRAM      (0x0100) /* Color table accesses read, not write - AGA */
#define BPC2_SOGEN      (0x0080) /* SOG output pin high - AGA */
#define BPC2_PF2PRI     (0x0040) /* PF2 priority over PF1 */
#define BPC2_PF2P2      (0x0020) /* PF2 priority wrt sprites */
#define BPC2_PF2P1      (0x0010)
#define BPC2_PF2P0      (0x0008)
#define BPC2_PF1P2      (0x0004) /* ditto PF1 */
#define BPC2_PF1P1      (0x0002)
#define BPC2_PF1P0      (0x0001)


   /*
    *    BPLCON3 -- Bitplane Control Register 3 (AGA)
    */

#define BPC3_BANK2      (0x8000) /* Bits to select color register bank */
#define BPC3_BANK1      (0x4000)
#define BPC3_BANK0      (0x2000)
#define BPC3_PF2OF2     (0x1000) /* Bits for color table offset when PF2 */
#define BPC3_PF2OF1     (0x0800)
#define BPC3_PF2OF0     (0x0400)
#define BPC3_LOCT       (0x0200) /* Color register writes go to low bits */
#define BPC3_SPRES1     (0x0080) /* Sprite resolution bits */
#define BPC3_SPRES0     (0x0040)
#define BPC3_BRDRBLNK   (0x0020) /* Border blanked? */
#define BPC3_BRDRTRAN   (0x0010) /* Border transparent? */
#define BPC3_ZDCLKEN    (0x0004) /* ZD pin is 14 MHz (HIRES) clock output */
#define BPC3_BRDRSPRT   (0x0002) /* Sprites in border? */
#define BPC3_EXTBLKEN   (0x0001) /* BLANK programmable */


   /*
    *    BPLCON4 -- Bitplane Control Register 4 (AGA)
    */

#define BPC4_BPLAM7     (0x8000) /* bitplane color XOR field */
#define BPC4_BPLAM6     (0x4000)
#define BPC4_BPLAM5     (0x2000)
#define BPC4_BPLAM4     (0x1000)
#define BPC4_BPLAM3     (0x0800)
#define BPC4_BPLAM2     (0x0400)
#define BPC4_BPLAM1     (0x0200)
#define BPC4_BPLAM0     (0x0100)
#define BPC4_ESPRM7     (0x0080) /* 4 high bits for even sprite colors */
#define BPC4_ESPRM6     (0x0040)
#define BPC4_ESPRM5     (0x0020)
#define BPC4_ESPRM4     (0x0010)
#define BPC4_OSPRM7     (0x0008) /* 4 high bits for odd sprite colors */
#define BPC4_OSPRM6     (0x0004)
#define BPC4_OSPRM5     (0x0002)
#define BPC4_OSPRM4     (0x0001)


   /*
    *    BEAMCON0 -- Beam Control Register
    */

#define BMC0_HARDDIS    (0x4000) /* Disable hardware limits */
#define BMC0_LPENDIS    (0x2000) /* Disable light pen latch */
#define BMC0_VARVBEN    (0x1000) /* Enable variable vertical blank */
#define BMC0_LOLDIS     (0x0800) /* Disable long/short line toggle */
#define BMC0_CSCBEN     (0x0400) /* Composite sync/blank */
#define BMC0_VARVSYEN   (0x0200) /* Enable variable vertical sync */
#define BMC0_VARHSYEN   (0x0100) /* Enable variable horizontal sync */
#define BMC0_VARBEAMEN  (0x0080) /* Enable variable beam counters */
#define BMC0_DUAL       (0x0080) /* Enable alternate horizontal beam counter */
#define BMC0_PAL        (0x0020) /* Set decodes for PAL */
#define BMC0_VARCSYEN   (0x0010) /* Enable variable composite sync */
#define BMC0_BLANKEN    (0x0008) /* Blank enable (no longer used on AGA) */
#define BMC0_CSYTRUE    (0x0004) /* CSY polarity */
#define BMC0_VSYTRUE    (0x0002) /* VSY polarity */
#define BMC0_HSYTRUE    (0x0001) /* HSY polarity */


   /*
    *    FMODE -- Fetch Mode Control Register (AGA)
    */

#define FMODE_SSCAN2    (0x8000) /* Sprite scan-doubling */
#define FMODE_BSCAN2    (0x4000) /* Use PF2 modulus every other line */
#define FMODE_SPAGEM    (0x0008) /* Sprite page mode */
#define FMODE_SPR32     (0x0004) /* Sprite 32 bit fetch */
#define FMODE_BPAGEM    (0x0002) /* Bitplane page mode */
#define FMODE_BPL32     (0x0001) /* Bitplane 32 bit fetch */


   /*
    *    Tags used to indicate a specific Pixel Clock
    *
    *    clk_shift is the shift value to get the timings in 35 ns units
    */

#define TAG_SHRES       (1)      /* SHRES, clk_shift = TAG_SHRES-1 */
#define TAG_HIRES       (2)      /* HIRES, clk_shift = TAG_HIRES-1 */
#define TAG_LORES       (3)      /* LORES, clk_shift = TAG_LORES-1 */


   /*
    *    Clock Definitions, Maximum Display Depth
    *
    *    These depend on the E-Clock or the Chipset, so they are filled in
    *    dynamically
    */

static u_long pixclock[3];       /* SHRES/HIRES/LORES: index = clk_shift */
static u_short maxdepth[3];      /* SHRES/HIRES/LORES: index = clk_shift */


   /*
    *    Broadcast Video Timings
    *
    *    Horizontal values are in 35 ns (SHRES) units
    *    Vertical values are in non-interlaced scanlines
    */

#define PAL_WINDOW_H    (1472)   /* PAL Window Limits */
#define PAL_WINDOW_V    (288)
#define PAL_DIWSTRT_H   (360)
#define PAL_DIWSTRT_V   (24)

#define NTSC_WINDOW_H   (1472)   /* NTSC Window Limits */
#define NTSC_WINDOW_V   (242)
#define NTSC_DIWSTRT_H  (360)
#define NTSC_DIWSTRT_V  (20)

#define PAL_HTOTAL      (1816)   /* Total line length */
#define NTSC_HTOTAL     (1816)   /* Needed for YWRAP */


   /*
    *    Monitor Specifications
    *
    *    These are typical for a `generic' Amiga monitor (e.g. A1960)
    */

static long vfmin = 50, vfmax = 90, hfmin = 15000, hfmax = 38000;

static u_short pwrsave = 0;      /* VESA suspend mode (not for PAL/NTSC) */


   /*
    *    Various macros
    */

#define up8(x)          (((x)+7) & ~7)
#define down8(x)        ((x) & ~7)
#define div8(x)         ((x)>>3)
#define mod8(x)         ((x) & 7)

#define up16(x)         (((x)+15) & ~15)
#define down16(x)       ((x) & ~15)
#define div16(x)        ((x)>>4)
#define mod16(x)        ((x) & 15)

#define up32(x)         (((x)+31) & ~31)
#define down32(x)       ((x) & ~31)
#define div32(x)        ((x)>>5)
#define mod32(x)        ((x) & 31)

#define up64(x)         (((x)+63) & ~63)
#define down64(x)       ((x) & ~63)
#define div64(x)        ((x)>>6)
#define mod64(x)        ((x) & 63)

#define min(a, b)       ((a) < (b) ? (a) : (b))
#define max(a, b)       ((a) > (b) ? (a) : (b))

#define highw(x)        ((u_long)(x)>>16 & 0xffff)
#define loww(x)         ((u_long)(x) & 0xffff)

#define arraysize(x)    (sizeof(x)/sizeof(*(x)))


   /*
    *    Chip RAM we reserve for the Frame Buffer (must be a multiple of 4K!)
    *
    *    This defines the Maximum Virtual Screen Size
    */

#define VIDEOMEMSIZE_AGA_2M   (1310720)   /* AGA (2MB) : max 1280*1024*256 */
#define VIDEOMEMSIZE_AGA_1M    (393216)   /* AGA (1MB) : max 1024*768*256 */
#define VIDEOMEMSIZE_ECS_2M    (655360)   /* ECS (2MB) : max 1280*1024*16 */
#define VIDEOMEMSIZE_ECS_1M    (393216)   /* ECS (1MB) : max 1024*768*16 */
#define VIDEOMEMSIZE_OCS       (262144)   /* OCS       : max ca. 800*600*16 */


static u_long videomemory;
static u_long videomemorysize;

#define assignchunk(name, type, ptr, size) \
{ \
   (name) = (type)(ptr); \
   ptr += size; \
}


   /*
    *    Copper Instructions
    */

#define CMOVE(val, reg)       (CUSTOM_OFS(reg)<<16 | (val))
#define CMOVE2(val, reg)      ((CUSTOM_OFS(reg)+2)<<16 | (val))
#define CWAIT(x, y)           (((y) & 0xff)<<24 | ((x) & 0xfe)<<16 | 0x0001fffe)
#define CEND                  (0xfffffffe)


typedef union {
   u_long l;
   u_short w[2];
} copins;


   /*
    *    Frame Header Copper List
    */

struct clist_hdr {
   copins bplcon0;
   copins diwstrt;
   copins diwstop;
   copins diwhigh;
   copins sprfix[8];
   copins sprstrtup[16];
   copins wait;
   copins jump;
   copins wait_forever;
};


   /*
    *    Long Frame/Short Frame Copper List
    */

struct clist_dyn {
   copins diwstrt;
   copins diwstop;
   copins diwhigh;
   copins bplcon0;
   copins sprpt[2];              /* Sprite 0 */
   copins rest[64];
};


static struct clist_hdr *clist_hdr;
static struct clist_dyn *clist_lof;
static struct clist_dyn *clist_shf;    /* Only used for Interlace */


   /*
    *    Hardware Cursor
    */

#define CRSR_RATE       (20)     /* Number of frames/flash toggle */

static u_long *lofsprite, *shfsprite, *dummysprite;
static u_short cursormode = FB_CURSOR_FLASH;


   /*
    *    Current Video Mode
    */

struct amiga_fb_par {

   /* General Values */

   int xres;                     /* vmode */
   int yres;                     /* vmode */
   int vxres;                    /* vmode */
   int vyres;                    /* vmode */
   int xoffset;                  /* vmode */
   int yoffset;                  /* vmode */
   u_short bpp;                  /* vmode */
   u_short clk_shift;            /* vmode */
   int vmode;                    /* vmode */
   u_short diwstrt_h;            /* vmode */
   u_short diwstrt_v;            /* vmode */
   u_long next_line;             /* modulo for next line */
   u_long next_plane;            /* modulo for next plane */
   short crsr_x;                 /* movecursor */
   short crsr_y;                 /* movecursor */

   /* OCS Hardware Registers */

   u_long bplpt0;                /* vmode, pan (Note: physical address) */
   u_short bplcon0;              /* vmode */
   u_short bplcon1;              /* vmode, pan */
   u_short bpl1mod;              /* vmode, pan */
   u_short bpl2mod;              /* vmode, pan */
   u_short diwstrt;              /* vmode */
   u_short diwstop;              /* vmode */
   u_short ddfstrt;              /* vmode, pan */
   u_short ddfstop;              /* vmode, pan */

#if defined(CONFIG_AMIFB_ECS) || defined(CONFIG_AMIFB_AGA)
   /* Additional ECS Hardware Registers */

   u_short diwhigh;              /* vmode */
   u_short bplcon3;              /* vmode */
   u_short beamcon0;             /* vmode */
   u_short htotal;               /* vmode */
   u_short hsstrt;               /* vmode */
   u_short hsstop;               /* vmode */
   u_short vtotal;               /* vmode */
   u_short vsstrt;               /* vmode */
   u_short vsstop;               /* vmode */
   u_short hcenter;              /* vmode */
#endif /* defined(CONFIG_AMIFB_ECS) || defined(CONFIG_AMIFB_AGA) */

#if defined(CONFIG_AMIFB_AGA)
   /* Additional AGA Hardware Registers */

   u_short fmode;                /* vmode */
#endif /* defined(CONFIG_AMIFB_AGA) */
};

static struct amiga_fb_par current_par;

static int current_par_valid = 0;
static int currcon = 0;

static struct display disp[MAX_NR_CONSOLES];
static struct fb_info fb_info;

static int node;        /* node of the /dev/fb?current file */


   /*
    *    The minimum period for audio depends on htotal (for OCS/ECS/AGA)
    *    (Imported from arch/m68k/amiga/amisound.c)
    */

extern volatile u_short amiga_audio_min_period;


   /*
    *    Since we can't read the palette on OCS/ECS, and since reading one
    *    single color palette entry requires 5 expensive custom chip bus
    *    accesses on AGA, we keep a copy of the current palette.
    */

#ifdef CONFIG_AMIFB_AGA
static struct { u_char red, green, blue, pad; } palette[256];
#else /* CONFIG_AMIFB_AGA */
static struct { u_char red, green, blue, pad; } palette[32];
#endif /* CONFIG_AMIFB_AGA */


   /*
    *    Latches and Flags for display changes during VBlank
    */

static volatile u_short do_vmode = 0;           /* Change the Video Mode */
static volatile short do_blank = 0;             /* (Un)Blank the Screen (±1) */
static volatile u_short do_movecursor = 0;      /* Move the Cursor */
static volatile u_short full_vmode_change = 1;  /* Full Change or Only Pan */
static volatile u_short is_blanked = 0;         /* Screen is Blanked */


   /*
    *    Switch for Chipset Independency
    */

static struct fb_hwswitch {

   /* Initialization */
   int (*init)(void);

   /* Display Control */
   int (*encode_fix)(struct fb_fix_screeninfo *fix, struct amiga_fb_par *par);
   int (*decode_var)(struct fb_var_screeninfo *var, struct amiga_fb_par *par);
   int (*encode_var)(struct fb_var_screeninfo *var, struct amiga_fb_par *par);
   int (*getcolreg)(u_int regno, u_int *red, u_int *green, u_int *blue,
                    u_int *transp);
   int (*setcolreg)(u_int regno, u_int red, u_int green, u_int blue,
                    u_int transp);
   int (*pan_display)(struct fb_var_screeninfo *var, struct amiga_fb_par *par);

   /* Routines Called by VBlank Interrupt to minimize flicker */
   void (*do_vmode)(void);
   void (*do_blank)(int blank);
   void (*do_movecursor)(void);
   void (*do_flashcursor)(void);
} *fbhw;


   /*
    *    Frame Buffer Name
    *
    *    The rest of the name is filled in by amiga_fb_init
    */

static char amiga_fb_name[16] = "Amiga ";


   /*
    *    Predefined Video Mode Names
    *
    *    The a2024-?? modes don't work yet because there's no A2024 driver.
    */

static char *amiga_fb_modenames[] = {

   /*
    *    Autodetect (Default) Video Mode
    */

   "default",

   /*
    *    AmigaOS Video Modes
    */
    
   "ntsc",              /* 640x200, 15 kHz, 60 Hz (NTSC) */
   "ntsc-lace",         /* 640x400, 15 kHz, 60 Hz interlaced (NTSC) */
   "pal",               /* 640x256, 15 kHz, 50 Hz (PAL) */
   "pal-lace",          /* 640x512, 15 kHz, 50 Hz interlaced (PAL) */
   "multiscan",         /* 640x480, 29 kHz, 57 Hz */
   "multiscan-lace",    /* 640x960, 29 kHz, 57 Hz interlaced */
   "a2024-10",          /* 1024x800, 10 Hz (Not yet supported) */
   "a2024-15",          /* 1024x800, 15 Hz (Not yet supported) */
   "euro36",            /* 640x200, 15 kHz, 72 Hz */
   "euro36-lace",       /* 640x400, 15 kHz, 72 Hz interlaced */
   "euro72",            /* 640x400, 29 kHz, 68 Hz */
   "euro72-lace",       /* 640x800, 29 kHz, 68 Hz interlaced */
   "super72",           /* 800x300, 23 kHz, 70 Hz */
   "super72-lace",      /* 800x600, 23 kHz, 70 Hz interlaced */
   "dblntsc",           /* 640x200, 27 kHz, 57 Hz doublescan */
   "dblntsc-ff",        /* 640x400, 27 kHz, 57 Hz */
   "dblntsc-lace",      /* 640x800, 27 kHz, 57 Hz interlaced */
   "dblpal",            /* 640x256, 27 kHz, 47 Hz doublescan */
   "dblpal-ff",         /* 640x512, 27 kHz, 47 Hz */
   "dblpal-lace",       /* 640x1024, 27 kHz, 47 Hz interlaced */

   /*
    *    VGA Video Modes
    */

   "vga",               /* 640x480, 31 kHz, 60 Hz (VGA) */
   "vga70",             /* 640x400, 31 kHz, 70 Hz (VGA) */

   /*
    *    User Defined Video Modes: to be set after boot up using e.g. fbset
    */

   "user0", "user1", "user2", "user3", "user4", "user5", "user6", "user7"
};


   /*
    *    Predefined Video Mode Definitions
    *
    *    Since the actual pixclock values depend on the E-Clock, we use the
    *    TAG_* values and fill in the real values during initialization.
    *    Thus we assume no one has pixel clocks of 333, 500 or 1000 GHz :-)
    */

static struct fb_var_screeninfo amiga_fb_predefined[] = {

   /*
    *    Autodetect (Default) Video Mode
    */

   { 0, },

   /*
    *    AmigaOS Video Modes
    */
    
   {
      /* ntsc */
      640, 200, 640, 200, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 78, 18, 24, 18, 0, 0,
      FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
   }, {
      /* ntsc-lace */
      640, 400, 640, 400, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 78, 18, 48, 36, 0, 0,
      FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
   }, {
      /* pal */
      640, 256, 640, 256, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 78, 18, 20, 12, 0, 0,
      FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
   }, {
      /* pal-lace */
      640, 512, 640, 512, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 78, 18, 40, 24, 0, 0,
      FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
   }, {
      /* multiscan */
      640, 480, 640, 480, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 164, 92, 9, 9, 80, 8,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* multiscan-lace */
      640, 960, 640, 960, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 164, 92, 18, 18, 80, 16,
      0, FB_VMODE_INTERLACED
   }, {
      /* a2024-10 (Not yet supported) */
      1024, 800, 1024, 800, 0, 0, 2, 0,
      {0, 2, 0}, {0, 2, 0}, {0, 2, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 0, 0, 0, 0, 0, 0,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* a2024-15 (Not yet supported) */
      1024, 800, 1024, 800, 0, 0, 2, 0,
      {0, 2, 0}, {0, 2, 0}, {0, 2, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 0, 0, 0, 0, 0, 0,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* euro36 */
      640, 200, 640, 200, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 92, 124, 6, 6, 52, 5,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* euro36-lace */
      640, 400, 640, 400, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_HIRES, 92, 124, 12, 12, 52, 10,
      0, FB_VMODE_INTERLACED
   }, {
      /* euro72 */
      640, 400, 640, 400, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 164, 92, 9, 9, 80, 8,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* euro72-lace */
      640, 800, 640, 800, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 164, 92, 18, 18, 80, 16,
      0, FB_VMODE_INTERLACED
   }, {
      /* super72 */
      800, 300, 800, 300, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 212, 140, 10, 11, 80, 7,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* super72-lace */
      800, 600, 800, 600, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 212, 140, 20, 22, 80, 14,
      0, FB_VMODE_INTERLACED
   }, {
      /* dblntsc */
      640, 200, 640, 200, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 18, 17, 80, 4,
      0, FB_VMODE_DOUBLE
   }, {
      /* dblntsc-ff */
      640, 400, 640, 400, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 36, 35, 80, 7,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* dblntsc-lace */
      640, 800, 640, 800, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 72, 70, 80, 14,
      0, FB_VMODE_INTERLACED
   }, {
      /* dblpal */
      640, 256, 640, 256, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 14, 13, 80, 4,
      0, FB_VMODE_DOUBLE
   }, {
      /* dblpal-ff */
      640, 512, 640, 512, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 28, 27, 80, 7,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* dblpal-lace */
      640, 1024, 640, 1024, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 196, 124, 56, 54, 80, 14,
      0, FB_VMODE_INTERLACED
   },

   /*
    *    VGA Video Modes
    */

   {
      /* vga */
      640, 480, 640, 480, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 64, 96, 30, 9, 112, 2,
      0, FB_VMODE_NONINTERLACED
   }, {
      /* vga70 */
      640, 400, 640, 400, 0, 0, 4, 0,
      {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
      0, 0, -1, -1, FB_ACCEL_NONE, TAG_SHRES, 64, 96, 35, 12, 112, 2,
      FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED
   },

   /*
    *    User Defined Video Modes
    */

   { 0, }, { 0, }, { 0, }, { 0, }, { 0, }, { 0, }, { 0, }, { 0, }
};


#define NUM_USER_MODES     (8)
#define NUM_TOTAL_MODES    arraysize(amiga_fb_predefined)
#define NUM_PREDEF_MODES   (NUM_TOTAL_MODES-NUM_USER_MODES)


static int amifb_ilbm = 0;       /* interleaved or normal bitplanes */

static int amifb_inverse = 0;
static int amifb_mode = 0;


   /*
    *    Support for Graphics Boards
    */

#ifdef CONFIG_FB_CYBER        /* Cybervision */
extern int Cyber_probe(void);
extern void Cyber_video_setup(char *options, int *ints);
extern struct fb_info *Cyber_fb_init(long *mem_start);

static int amifb_Cyber = 0;
#endif /* CONFIG_FB_CYBER */


   /*
    *    Some default modes
    */

#define DEFMODE_PAL        "pal"       /* for PAL OCS/ECS */
#define DEFMODE_NTSC       "ntsc"      /* for NTSC OCS/ECS */
#define DEFMODE_AMBER_PAL  "pal-lace"  /* for flicker fixed PAL (A3000) */
#define DEFMODE_AMBER_NTSC "ntsc-lace" /* for flicker fixed NTSC (A3000) */
#define DEFMODE_AGA        "vga70"     /* for AGA */


   /*
    *    Interface used by the world
    */

void amiga_video_setup(char *options, int *ints);

static int amiga_fb_get_fix(struct fb_fix_screeninfo *fix, int con);
static int amiga_fb_get_var(struct fb_var_screeninfo *var, int con);
static int amiga_fb_set_var(struct fb_var_screeninfo *var, int con);
static int amiga_fb_get_cmap(struct fb_cmap *cmap, int kspc, int con);
static int amiga_fb_set_cmap(struct fb_cmap *cmap, int kspc, int con);
static int amiga_fb_pan_display(struct fb_var_screeninfo *var, int con);

static int amiga_fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
                          u_long arg, int con);

static int amiga_fb_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix, int con);
static int amiga_fb_get_var_cursorinfo(struct fb_var_cursorinfo *var, int con);
static int amiga_fb_set_var_cursorinfo(struct fb_var_cursorinfo *var, int con);
static int amiga_fb_get_cursorstate(struct fb_cursorstate *state, int con);
static int amiga_fb_set_cursorstate(struct fb_cursorstate *state, int con);


   /*
    *    Interface to the low level console driver
    */

struct fb_info *amiga_fb_init(long *mem_start);
static int amifb_switch(int con);
static int amifb_updatevar(int con);
static void amifb_blank(int blank);


   /*
    *    Support for OCS
    */

#ifdef CONFIG_AMIFB_OCS
#error "OCS support: not yet implemented"
#endif /* CONFIG_AMIFB_OCS */


   /*
    *    Support for ECS
    */

#ifdef CONFIG_AMIFB_ECS
#error "ECS support: not yet implemented"
#endif /* CONFIG_AMIFB_ECS */


   /*
    *    Support for AGA
    */

#ifdef CONFIG_AMIFB_AGA
static int aga_init(void);
static int aga_encode_fix(struct fb_fix_screeninfo *fix,
                          struct amiga_fb_par *par);
static int aga_decode_var(struct fb_var_screeninfo *var,
                          struct amiga_fb_par *par);
static int aga_encode_var(struct fb_var_screeninfo *var,
                          struct amiga_fb_par *par);
static int aga_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
                         u_int *transp);
static int aga_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                         u_int transp);
static int aga_pan_display(struct fb_var_screeninfo *var,
                           struct amiga_fb_par *par);
static void aga_do_vmode(void);
static void aga_do_blank(int blank);
static void aga_do_movecursor(void);
static void aga_do_flashcursor(void);

static int aga_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix, int con);
static int aga_get_var_cursorinfo(struct fb_var_cursorinfo *var, int con);
static int aga_set_var_cursorinfo(struct fb_var_cursorinfo *var, int con);
static int aga_get_cursorstate(struct fb_cursorstate *state, int con);
static int aga_set_cursorstate(struct fb_cursorstate *state, int con);

static __inline__ void aga_build_clist_hdr(struct clist_hdr *cop);
static __inline__ void aga_update_clist_hdr(struct clist_hdr *cop,
                                            struct amiga_fb_par *par);
static void aga_build_clist_dyn(struct clist_dyn *cop,
                                struct clist_dyn *othercop, u_short shf,
                                struct amiga_fb_par *par);
#endif /* CONFIG_AMIFB_AGA */


   /*
    *    Internal routines
    */

static u_long chipalloc(u_long size);
static void amiga_fb_get_par(struct amiga_fb_par *par);
static void amiga_fb_set_par(struct amiga_fb_par *par);
static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
static struct fb_cmap *get_default_colormap(int bpp);
static int do_fb_get_cmap(struct fb_cmap *cmap, struct fb_var_screeninfo *var,
                          int kspc);
static int do_fb_set_cmap(struct fb_cmap *cmap, struct fb_var_screeninfo *var,
                          int kspc);
static void do_install_cmap(int con);
static void memcpy_fs(int fsfromto, void *to, void *from, int len);
static void copy_cmap(struct fb_cmap *from, struct fb_cmap *to, int fsfromto);
static int alloc_cmap(struct fb_cmap *cmap, int len, int transp);
static void amiga_fb_set_disp(int con);
static void amifb_interrupt(int irq, struct pt_regs *fp, void *dummy);
static char * strtoke(char * s,const char * ct);
static int get_video_mode(const char *name);
static void check_default_mode(void);


#ifdef USE_MONO_AMIFB_IF_NON_AGA

/******************************************************************************
*
* This is the old monochrome frame buffer device. It's invoked if we're running
* on a non-AGA machine, until the color support for OCS/ECS is finished.
*
******************************************************************************/

/*
 * atari/atafb.c -- Low level implementation of Atari frame buffer device
 * amiga/amifb.c -- Low level implementation of Amiga frame buffer device
 *
 *  Copyright (C) 1994 Martin Schaller & Roman Hodek & Geert Uytterhoeven
 *  
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 *
 * History:
 *   - 03 Jan 95: Original version my Martin Schaller: The TT driver and
 *                all the device independent stuff
 *   - 09 Jan 95: Roman: I've added the hardware abstraction (hw_switch)
 *                and wrote the Falcon, ST(E), and External drivers
 *                based on the original TT driver.
 *   - 26 Jan 95: Geert: Amiga version
 *   - 19 Feb 95: Hamish: added Jes Sorensen's ECS patches to the Amiga
 *		  frame buffer device.  This provides ECS support and the
 *		  following screen-modes: multiscan, multiscan-lace,
 * 		  super72, super72-lace, dblntsc, dblpal & euro72.
 *		  He suggests that we remove the old AGA screenmodes,
 *		  as they are non-standard, and some of them doesn't work
 *		  under ECS.
 */

static struct mono_mono_amiga_fb_par {
	u_long smem_start;
	u_long smem_len;
	struct geometry *geometry;
	ushort scr_max_height;			/* screen dimensions */
	ushort scr_max_width;
	ushort scr_height;
	ushort scr_width;
	ushort scr_depth;
	int bytes_per_row;			/* offset to one line below */
	ulong fgcol;
	ulong bgcol;
	ulong crsrcol;
	ushort scroll_latch;			/* Vblank support for hardware scroll */
	ushort y_wrap;
	ushort cursor_latch;			/* Hardware cursor */
	ushort *cursor, *dummy;
	ushort cursor_flash;
	ushort cursor_visible;
	ushort diwstrt_v, diwstrt_h;		/* display window control */
	ushort diwstop_v, diwstop_h;
	ushort bplcon0;				/* display mode */
	ushort htotal;
	u_char *bitplane[8];			/* pointers to display bitplanes */
	ulong plane_size;
	ushort *coplist1hdr;			/* List 1 static  component */
	ushort *coplist1dyn;			/* List 1 dynamic component */
	ushort *coplist2hdr;			/* List 2 static  component */
	ushort *coplist2dyn;			/* List 2 dynamic component */
} mono_current_par;


static ushort mono_cursor_data[] =
{
    0x2c81,0x2d00,
    0xf000,0x0000,
    0x0000,0x0000
};


/*
 *  Color definitions
 */

#define FG_COLOR		(0x000000)	/* black */
#define BG_COLOR		(0xaaaaaa)	/* lt. grey */
#define CRSR_COLOR		(0xff0000)	/* bright red */

#define FG_COLOR_INV		BG_COLOR
#define BG_COLOR_INV		FG_COLOR
#define CRSR_COLOR_INV		(0x6677aa)	/* a blue-ish color */

/*
 *  Split 24-bit RGB colors in 12-bit MSB (for OCS/ECS/AGA) and LSB (for AGA)
 */

#define COLOR_MSB(rgb)	(((rgb>>12)&0xf00)|((rgb>>8)&0x0f0)|((rgb>>4)&0x00f))
#define COLOR_LSB(rgb)	(((rgb>>8) &0xf00)|((rgb>>4)&0x0f0)|((rgb)   &0x00f))

/* Cursor definitions */

#define CRSR_FLASH		1	/* Cursor flashing on(1)/off(0) */
#define CRSR_BLOCK		1	/* Block(1) or line(0) cursor */


/* controlling screen blanking (read in VBL handler) */
static int mono_do_blank;
static int mono_do_unblank;
static unsigned short mono_save_bplcon3;

/*
 * mono_ecs_color_zero is used to keep custom.color[0] for the special ECS color-
 * table, as custom.color[0] is cleared at vblank interrupts.
 * -Jes (jds@kom.auc.dk)
 */

static ushort mono_ecs_color_zero;

static struct {
	int right_count;
	int done;
} mono_vblank;


static __inline__ void mono_init_vblank(void)
{
	mono_vblank.right_count = 0;
	mono_vblank.done = 0;
}

/* Geometry structure contains all useful information about given mode.
 *
 * Strictly speaking `scr_max_height' and `scr_max_width' is redundant
 * information with DIWSTRT value provided. Might be useful if modes
 * can be hotwired by user in future. It fits for the moment.
 *
 * At the moment, the code only distinguishes between OCS and AGA. ECS
 * lies somewhere in between - someone more familiar with it could make
 * appropriate modifications so that some advanced display modes are
 * available, without confusing the poor chipset. OCS modes use only the
 * bplcon0, diwstrt, diwstop, ddfstrt, ddfstop registers (a few others could
 * be used as well). -wjr
 *
 * The code now supports ECS as well, except for FMODE all control registers
 * are the same under ECS. A special color-table has to be generated though.
 * -Jes
 */
struct geometry {
    char *modename;	/* Name this thing */
    char isOCS;		/* Is it OCS or ECS/AGA */
    ushort bplcon0;	/* Values for bit plane control register 0 */
    ushort scr_width;
    ushort scr_height;
    ushort scr_depth;
    ushort scr_max_width;     /* Historical, might be useful still */
    ushort scr_max_height;
    ushort diwstrt_h;	/* Where the display window starts */
    ushort diwstrt_v;
    ushort alignment;	/* Pixels per scanline must be a multiple of this */
    /* OCS doesn't need anything past here */
    ushort bplcon2;
    ushort bplcon3;
    /* The rest of these control variable sync */
    ushort htotal;	/* Total hclocks */
    ushort hsstrt;	/* HSYNC start and stop */
    ushort hsstop;
    ushort hbstrt;	/* HBLANK start and stop */
    ushort hbstop;
    ushort vtotal;	/* Total vlines */
    ushort vsstrt;	/* VSYNC, VBLANK ditto */
    ushort vsstop;
    ushort vbstrt;
    ushort vbstop;
    ushort hcenter;	/* Center of line, for interlaced modes */
    ushort beamcon0;	/* Beam control */
    ushort fmode;	/* Memory fetch mode */
};

#define MAX_COP_LIST_ENTS 64
#define COP_MEM_REQ       (MAX_COP_LIST_ENTS*4*2)
#define SPR_MEM_REQ       (24)


static struct geometry mono_modes[] = {
	/* NTSC modes: !!! can't guarantee anything about overscan modes !!! */
	{
		"ntsc-lace", 1,
		BPC0_HIRES | BPC0_LACE,
		640, 400, 1,
		704, 480,
		0x71, 0x18,		/* diwstrt h,v */
		16			/* WORD aligned */
	}, {
		"ntsc", 1,
		BPC0_HIRES,
		640, 200, 1,
		704, 240,
		0x71, 0x18,
		16			/* WORD aligned */
	}, {
		"ntsc-lace-over", 1,
		BPC0_HIRES | BPC0_LACE,
		704, 480, 1,
		704, 480,
		0x71, 0x18,
		16			/* WORD aligned */
	}, {
		"ntsc-over", 1,
		BPC0_HIRES,
		704, 240, 1,
		704, 240,
		0x71, 0x18,
		16			/* WORD aligned */
	},
	/* PAL modes. Warning:
	 * 
	 * PAL overscan causes problems on my machine because maximum diwstop_h
	 * value seems to be ~0x1c2, rather than 0x1e0+ inferred by RKM 1.1
	 * and 0x1d5 inferred by original `amicon.c' source. Is this a hardware
	 * limitation of OCS/pal or 1084?. Or am I doing something stupid here?
	 *
	 * Included a couple of overscan modes that DO work on my machine,
	 * although not particularly useful.
	 */
	{
		"pal-lace", 1,
		BPC0_HIRES | BPC0_LACE,
		640, 512, 1,
		704, 592,
		0x71, 0x18,
		16			/* WORD aligned */
	}, {
		"pal", 1,
		BPC0_HIRES,
		640, 256, 1,
		704, 296,
		0x71, 0x18,
		16			/* WORD aligned */
	}, {
		"pal-lace-over", 1,
		BPC0_HIRES | BPC0_LACE,
		704, 592, 1,
		704, 582,
		0x5b, 0x18,
		16			/* WORD aligned */
	}, {
		"pal-over", 1,
		BPC0_HIRES,
		704, 296, 1,
		704, 296,
		0x5b, 0x18,
		16			/* WORD aligned */

	},
	/* ECS modes, these are real ECS modes */
	{
		"multiscan", 0,
		BPC0_SHRES | BPC0_ECSENA,	/* bplcon0 */
		640, 480, 1,
		640, 480,
		0x0041, 0x002c,			/* diwstrt h,v */
		64,	        		/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */

		0x0072,				/* htotal */
		0x000a,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0002,				/* hbstrt */
		0x001c,				/* hbstop */
		0x020c,				/* vtotal */
		0x0008,				/* vsstrt */
		0x0011,				/* vsstop */
		0x0000,				/* vbstrt */
		0x001c,				/* vbstop */
		0x0043,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	{
		"multiscan-lace", 0,
		BPC0_SHRES | BPC0_LACE | BPC0_ECSENA,	/* bplcon0 */
		640, 960, 1,
		640, 960,
		0x0041, 0x002c,			/* diwstrt h,v */
		64,	        		/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */

		0x0072,				/* htotal */
		0x000a,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0002,				/* hbstrt */
		0x001c,				/* hbstop */
		0x020c,				/* vtotal */
		0x0008,				/* vsstrt */
		0x0011,				/* vsstop */
		0x0000,				/* vbstrt */
		0x001c,				/* vbstop */
		0x0043,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* Super 72 - 800x300 72Hz noninterlaced mode. */
	{
		"super72", 0,
		BPC0_SHRES | BPC0_ECSENA,	/* bplcon0 */
		800, 304, 1,			/* need rows%8 == 0 */
		800, 304,			/* (cols too) */
		0x0051, 0x0021,			/* diwstrt h,v */
		64,				/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x0091,				/* htotal */
		0x000a,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0001,				/* hbstrt */
		0x001e,				/* hbstop */
		0x0156,				/* vtotal */
		0x0009,				/* vsstrt */
		0x0012,				/* vsstop */
		0x0000,				/* vbstrt */
		0x001c,				/* vbstop */
		0x0052,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* Super 72 lace - 800x600 72Hz interlaced mode. */
	{
		"super72-lace", 0,
		BPC0_SHRES | BPC0_LACE | BPC0_ECSENA,	/* bplcon0 */
		800, 600, 1,			/* need rows%8 == 0 */
		800, 600,			/* (cols too) */
		0x0051, 0x0021,			/* diwstrt h,v */
		64,     			/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,
						/* bplcon3 */
		0x0091,				/* htotal */
		0x000a,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0001,				/* hbstrt */
		0x001e,				/* hbstop */
		0x0150,				/* vtotal */
		0x0009,				/* vsstrt */
		0x0012,				/* vsstop */
		0x0000,				/* vbstrt */
		0x001c,				/* vbstop */
		0x0052,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* DblNtsc - 640x400 59Hz noninterlaced mode. */
	{
		"dblntsc", 0,
		BPC0_SHRES | BPC0_ECSENA,	/* bplcon0 */
		640, 400, 1,			/* need rows%8 == 0 */
		640, 400,			/* (cols too) */
		0x0049, 0x0021,			/* diwstrt h,v */
		64,				/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,
						/* bplcon3 */
		0x0079,				/* htotal */
		0x0007,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0001,				/* hbstrt */
		0x001e,				/* hbstop */
		0x01ec,				/* vtotal */
		0x0008,				/* vsstrt */
		0x0010,				/* vsstop */
		0x0000,				/* vbstrt */
		0x0019,				/* vbstop */
		0x0046,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* DblPal - 640x512 52Hz noninterlaced mode. */
	{
		"dblpal", 0,
		BPC0_SHRES | BPC0_ECSENA,	/* bplcon0 */
		640, 512, 1,			/* need rows%8 == 0 */
		640, 512,			/* (cols too) */
		0x0049, 0x0021,			/* diwstrt h,v */
		64,				/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,
						/* bplcon3 */
		0x0079,				/* htotal */
		0x0007,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0001,				/* hbstrt */
		0x001e,				/* hbstop */
		0x0234,				/* vtotal */
		0x0008,				/* vsstrt */
		0x0010,				/* vsstop */
		0x0000,				/* vbstrt */
		0x0019,				/* vbstop */
		0x0046,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* Euro72 - productivity - 640x400 71Hz noninterlaced mode. */
	{
		"euro72", 0,
		BPC0_SHRES | BPC0_ECSENA,	/* bplcon0 */
		640, 400, 1,			/* need rows%8 == 0 */
		640, 400,			/* (cols too) */
		0x0041, 0x0021,			/* diwstrt h,v */
		64,				/* 64-bit aligned */
		BPC2_KILLEHB,			/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
			BPC3_BRDRBLNK | BPC3_EXTBLKEN,
						/* bplcon3 */
		0x0071,				/* htotal */
		0x0009,				/* hsstrt */
		0x0013,				/* hsstop */
		0x0001,				/* hbstrt */
		0x001e,				/* hbstop */
		0x01be,				/* vtotal */
		0x0008,				/* vsstrt */
		0x0016,				/* vsstop */
		0x0000,				/* vbstrt */
		0x001f,				/* vbstop */
		0x0041,				/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,
						/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32	/* fmode */
	},
	/* AGA modes */
	{
	/*
	 * A 640x480, 60Hz noninterlaced AGA mode. It would be nice to be
	 * able to have some of these values computed dynamically, but that
	 * requires more knowledge of AGA than I have. At the moment,
	 * the values make it centered on my 1960 monitor. -wjr
	 *
	 * For random reasons to do with the way arguments are parsed,
	 * these names can't start with a digit.
	 *
	 * Don't count on being able to reduce scr_width and scr_height
	 * and ending up with a smaller but well-formed screen - this
	 * doesn't seem to work well at the moment.
	 */
		"aga640x480", 0,
		BPC0_SHRES | BPC0_ECSENA,			/* bplcon0 */
		640, 480, 1,
		640, 480,
		0x0041, 0x002b,						/* diwstrt h,v */
		64,										/* 64-bit aligned */
		BPC2_KILLEHB,							/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
		BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x0071,									/* htotal */
		0x000c,									/* hsstrt */
		0x001c,									/* hsstop */
		0x0008,									/* hbstrt */
		0x001e,									/* hbstop */
		0x020c,									/* vtotal */
		0x0001,									/* vsstrt */
		0x0003,									/* vsstop */
		0x0000,									/* vbstrt */
		0x000f,									/* vbstop */
		0x0046,									/* hcenter */
		BMC0_HARDDIS | BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
			BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,	/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32			/* fmode */
	}, {
		/* An 800x600 72Hz interlaced mode. */
		"aga800x600", 0,
		BPC0_SHRES | BPC0_LACE | BPC0_ECSENA,	/* bplcon0 */
		896, 624, 1,							/* need rows%8 == 0 */
		896, 624,								/* (cols too) */
		0x0041, 0x001e,						/* diwstrt h,v */
		64,						/* 64-bit aligned */
		BPC2_KILLEHB,							/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
		BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x0091,									/* htotal */
		0x000e,									/* hsstrt */
		0x001d,									/* hsstop */
		0x000a,									/* hbstrt */
		0x001e,									/* hbstop */
		0x0156,									/* vtotal */
		0x0001,									/* vsstrt */
		0x0003,									/* vsstop */
		0x0000,									/* vbstrt */
		0x000f,									/* vbstop */
		0x0050,									/* hcenter */
		BMC0_HARDDIS | BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN |
		BMC0_VARHSYEN | BMC0_VARBEAMEN | BMC0_BLANKEN,	/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32			/* fmode */
	},
	/*
	 * Additional AGA modes by Geert Uytterhoeven
	 */
	{
		/*
		 * A 720x400, 70 Hz noninterlaced AGA mode (29.27 kHz)
		 */
		"aga720x400", 0,
		BPC0_SHRES | BPC0_ECSENA,			/* bplcon0 */
		720, 400, 1,
		720, 400,
		0x0041, 0x0013,						/* diwstrt h,v */
		64,										/* 64-bit aligned */
		BPC2_KILLEHB,							/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
		BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x0079,									/* htotal */
		0x000e,									/* hsstrt */
		0x0018,									/* hsstop */
		0x0001,									/* hbstrt */
		0x0021,									/* hbstop */
		0x01a2,									/* vtotal */
		0x0003,									/* vsstrt */
		0x0005,									/* vsstop */
		0x0000,									/* vbstrt */
		0x0012,									/* vbstop */
		0x0046,									/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN | BMC0_VARHSYEN |
		BMC0_VARBEAMEN | BMC0_PAL | BMC0_VARCSYEN | BMC0_CSYTRUE |
		BMC0_VSYTRUE,							/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32			/* fmode */
	}, {
		/*
		 * A 640x400, 76 Hz noninterlaced AGA mode (31.89 kHz)
		 */
		"aga640x400", 0,
		BPC0_SHRES | BPC0_ECSENA,			/* bplcon0 */
		640, 400, 1,
		640, 400,
		0x0041, 0x0015,						/* diwstrt h,v */
		64,										/* 64-bit aligned */
		BPC2_KILLEHB,							/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
		BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x006f,									/* htotal */
		0x000d,									/* hsstrt */
		0x0018,									/* hsstop */
		0x0001,									/* hbstrt */
		0x0021,									/* hbstop */
		0x01a4,									/* vtotal */
		0x0003,									/* vsstrt */
		0x0005,									/* vsstop */
		0x0000,									/* vbstrt */
		0x0014,									/* vbstop */
		0x0046,									/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN | BMC0_VARHSYEN |
		BMC0_VARBEAMEN | BMC0_PAL | BMC0_VARCSYEN | BMC0_CSYTRUE |
		BMC0_VSYTRUE,							/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32			/* fmode */
	}, {
		/*
		 * A 640x480, 64 Hz noninterlaced AGA mode (31.89 kHz)
		 */
		"aga640x480a", 0,
		BPC0_SHRES | BPC0_ECSENA,			/* bplcon0 */
		640, 480, 1,
		640, 480,
		0x0041, 0x0015,						/* diwstrt h,v */
		64,										/* 64-bit aligned */
		BPC2_KILLEHB,							/* bplcon2 */
		BPC3_PF2OF1 | BPC3_PF2OF0 | BPC3_SPRES1 | BPC3_SPRES0 |
		BPC3_BRDRBLNK | BPC3_EXTBLKEN,	/* bplcon3 */
		0x006f,									/* htotal */
		0x000e,									/* hsstrt */
		0x0018,									/* hsstop */
		0x0001,									/* hbstrt */
		0x0021,									/* hbstop */
		0x01f4,									/* vtotal */
		0x0003,									/* vsstrt */
		0x0005,									/* vsstop */
		0x0000,									/* vbstrt */
		0x0014,									/* vbstop */
		0x0046,									/* hcenter */
		BMC0_VARVBEN | BMC0_LOLDIS | BMC0_VARVSYEN | BMC0_VARHSYEN |
		BMC0_VARBEAMEN | BMC0_PAL | BMC0_VARCSYEN | BMC0_CSYTRUE |
		BMC0_VSYTRUE,							/* beamcon0 */
		FMODE_BPAGEM | FMODE_BPL32			/* fmode */
	}
};

#define	NMODES	(sizeof(mono_modes) / sizeof(struct geometry))

static struct fb_var_screeninfo mono_mono_amiga_fb_predefined[] = {
	{ /* autodetect */
		0, 0, 0, 0, 0, 0, 0, 0,   		/* xres-grayscale */
		{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, 	/* red green blue tran*/
		0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 }
};

static int mono_num_mono_amiga_fb_predefined= sizeof(mono_mono_amiga_fb_predefined)/sizeof(struct fb_var_screeninfo);



/* Some default modes */
#define OCS_PAL_LOWEND_DEFMODE	5	/* PAL non-laced for 500/2000 */
#define OCS_PAL_3000_DEFMODE		4	/* PAL laced for 3000 */
#define OCS_NTSC_LOWEND_DEFMODE	1	/* NTSC non-laced for 500/2000 */
#define OCS_NTSC_3000_DEFMODE		0	/* NTSC laced for 3000 */
#define AGA_DEFMODE					8	/* 640x480 non-laced for AGA */

static int mono_amifb_inverse = 0;
static int mono_amifb_mode = -1;

static void mono_video_setup (char *options, int *ints)
{
}

/* Notes about copper scrolling:
 *
 * 1. The VBLANK routine dynamically rewrites a LIVE copper list that is
 *    currently being executed. Don't mess with it unless you know the
 *    complications. Fairly sure that double buffered lists doesn't
 *    make our life any easier.
 *
 * 2. The vblank code starts executing at logical line 0. Display must be
 *    set up and ready to run by line DIWSTRT_V, typically 0x2c, minimum
 *    value is 0x18 for maximum overscan.
 *
 *    Tests on my A500/030 for dynamically generating a 37 element copper
 *    list during the VBLANK period under AmigaDos required between
 *    0x10 and 0x14 scanlines. This should be pathological case, and
 *    should do better under Linux/68k. It is however IMPERATIVE that I am
 *    first in the VBLANK isr chain. Try to keep 'buildclist' as fast as
 *    possible. Don't think that it justifies assembler thou'
 *
 * 3. PAL 640x256 display (no overscan) has copper-wait y positions in range
 *    0x02c -> 0x12c. NTSC overscan uses values > 256 too. However counter
 *    is 8 bit, will wrap. RKM 1.1 suggests use of a WAIT(0x00,0xff),
 *    WAIT(x,y-0x100) pair to handle this case. This is WRONG - must use
 *    WAIT(0xe2,0xff) to ensure that wrap occurred by next copper
 *    instruction. Argghh!
 *
 * 4. RKM 1.1 suggests Copper-wait x positions are in range [0,0xe2].
 *    Horizontal blanking occurs in range 0x0f -> 0x35. Black screen
 *    shown in range 0x04 -> 0x47.
 *
 *    Experiments suggest that using WAIT(0x00,y), we can replace up to
 *    7 bitplane pointers before display fetch start. Using a 
 *    WAIT(0xe0,y-1) instead, we can replace 8 pointers that should be
 *    all that we need for a full AGA display. Should work because of
 *    fetch latency with bitmapped display.
 *
 *    I think that this works. Someone please tell me if something breaks.
 *
 * Is diwstop_h the right value to use for "close to the end of line"?
 * It seems to work for me, at least for the modes I've defined. -wjr
 *
 * I changed the Wait(diwstop_h, 0xff) for 256-line chunk skipping to
 * Wait(diwstop_h-2, 0xff) to make it work with the additional
 * `get-all-you-can-get-out-of-it' AGA modes. Maybe we should derive the
 * wait position from the HTOTAL value? - G.U.
 *
 * The Wait(diwstop_h-2, 0xff) didn't work in Super72 under ECS, instead
 * I changed it to Wait(htotal-4, 0xff). Dunno whether it works under AGA,
 * and don't ask my why it works. I'm trying to get some facts on this issue
 * from Commodore.
 * -Jes
 */

static __inline__ ushort *mono_build_clist_hdr(register struct display *p,
														ushort *cop,
														ushort *othercop)	/* Interlace: List for next frame */
{
  return 0;
}

static __inline__ ushort *mono_build_clist_dyn(register struct display *p,
														ushort *cop,
														int shf)				/* Interlace: Short frame */
{
  return 0;
}


static __inline__ void mono_build_cursor(register struct display *p)
{
}

static void mono_build_ecs_colors(ushort color1, ushort color2, ushort color3, 
                      ushort color4, ushort *table)
{
/*
 * This function calculates the special ECS color-tables needed when running
 * new screen-modes available under ECS. See the hardware reference manual
 * 3rd edition for details.
 * -Jes
 */
}

/* mono_display_init():
 *
 *    Fills out (struct display *) given a geometry structure
 */

static void mono_display_init(struct display *p,
                         struct geometry *geom, ushort inverse)
{
}


static void mono_amifb_interrupt(int irq, struct pt_regs *fp, void *data)
{
}


static int mono_amiga_fb_get_fix(struct fb_fix_screeninfo *fix, int con)
{
  return 0;
}


static int mono_amiga_fb_get_var(struct fb_var_screeninfo *var, int con)
{
  return 0;
}


static void mono_amiga_fb_set_disp(int con)
{
}


static int mono_amiga_fb_set_var(struct fb_var_screeninfo *var, int con)
{
  return 0;
}


static short mono_red_normal[] = {
	((BG_COLOR & 0xff0000)>>8) | ((BG_COLOR & 0xff0000)>>16),
	((FG_COLOR & 0xff0000)>>8) | ((FG_COLOR & 0xff0000)>>16)
};
static short mono_green_normal[] = {
	((BG_COLOR & 0x00ff00)) | ((BG_COLOR & 0x00ff00)>>8),
	((FG_COLOR & 0x00ff00)) | ((FG_COLOR & 0x00ff00)>>8)
};
static short mono_blue_normal[] = {
	((BG_COLOR & 0x0000ff)<<8) | ((BG_COLOR & 0x0000ff)),
	((FG_COLOR & 0x0000ff)<<8) | ((FG_COLOR & 0x0000ff))
};

static short mono_red_inverse[] = {
	((BG_COLOR_INV & 0xff0000)>>8) | ((BG_COLOR_INV & 0xff0000)>>16),
	((FG_COLOR_INV & 0xff0000)>>8) | ((FG_COLOR_INV & 0xff0000)>>16)
};
static short mono_green_inverse[] = {
	((BG_COLOR_INV & 0x00ff00)) | ((BG_COLOR_INV & 0x00ff00)>>8),
	((FG_COLOR_INV & 0x00ff00)) | ((FG_COLOR_INV & 0x00ff00)>>8)
};
static short mono_blue_inverse[] = {
	((BG_COLOR_INV & 0x0000ff)<<8) | ((BG_COLOR_INV & 0x0000ff)),
	((FG_COLOR_INV & 0x0000ff)<<8) | ((FG_COLOR & 0x0000ff))
};

static struct fb_cmap mono_default_cmap_normal = { 0, 2, mono_red_normal, mono_green_normal, mono_blue_normal, NULL };
static struct fb_cmap mono_default_cmap_inverse = { 0, 2, mono_red_inverse, mono_green_inverse, mono_blue_inverse, NULL };

static int mono_amiga_fb_get_cmap(struct fb_cmap *cmap, int kspc, int con)
{
return 0;
}


static int mono_amiga_fb_set_cmap(struct fb_cmap *cmap, int kspc, int con)
{
	/*
	 *		Not yet implemented
	 */
	return(-EINVAL);
}


static int mono_amiga_fb_pan_display(struct fb_var_screeninfo *var, int con)
{
	/*
	 *		Not yet implemented
	 */
	return(-EINVAL);
}


static int mono_amiga_fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
								  unsigned long arg, int con)
{
	return(-EINVAL);
}

static struct fb_ops mono_amiga_fb_ops = {
	mono_amiga_fb_get_fix, mono_amiga_fb_get_var, mono_amiga_fb_set_var, mono_amiga_fb_get_cmap,
	mono_amiga_fb_set_cmap, mono_amiga_fb_pan_display, mono_amiga_fb_ioctl	
};


static int mono_amifb_switch (int con)
{
  return 0;
}


static int mono_amifb_updatevar(int con)
{
  return 0;
}


static void mono_amifb_blank(int blank)
{
}


static struct fb_info *mono_amiga_fb_init(long *mem_start)
{
  return NULL;
}
#endif /* USE_MONO_AMIFB_IF_NON_AGA */


/* -------------------- OCS specific routines ------------------------------- */


#ifdef CONFIG_AMIFB_OCS
   /*
    *    Initialization
    *
    *    Allocate the required chip memory.
    *    Set the default video mode for this chipset. If a video mode was
    *    specified on the command line, it will override the default mode.
    */

static int ocs_init(void)
{
  return 0;
}
#endif /* CONFIG_AMIFB_OCS */


/* -------------------- ECS specific routines ------------------------------- */


#ifdef CONFIG_AMIFB_ECS
   /*
    *    Initialization
    *
    *    Allocate the required chip memory.
    *    Set the default video mode for this chipset. If a video mode was
    *    specified on the command line, it will override the default mode.
    */

static int ecs_init(void)
{
  return 0;
}
#endif /* CONFIG_AMIFB_ECS */


/* -------------------- AGA specific routines ------------------------------- */


#ifdef CONFIG_AMIFB_AGA
   /*
    *    Macros for the conversion from real world values to hardware register
    *    values (and vice versa).
    *
    *    This helps us to keep our attention on the real stuff...
    *
    *    Hardware limits:
    *
    *       parameter     min      max     step
    *       ---------     ---     ----     ----
    *       diwstrt_h       0     2047        1
    *       diwstrt_v       0     2047        1
    *       diwstop_h       0     2047        1
    *       diwstop_v       0     2047        1
    *
    *       ddfstrt         0     2032       16
    *       ddfstop         0     2032       16
    *
    *       htotal          8     2048        8
    *       hsstrt          0     2040        8
    *       hsstop          0     2040        8
    *       vtotal          1     2048        1
    *       vsstrt          0     2047        1
    *       vsstop          0     2047        1
    *       hcenter         0     2040        8
    *
    *       hbstrt          0     2047        1
    *       hbstop          0     2047        1
    *       vbstrt          0     2047        1
    *       vbstop          0     2047        1
    *
    *    Horizontal values are in 35 ns (SHRES) pixels
    *    Vertical values are in scanlines
    */

/* bplcon1 (smooth scrolling) */

#define hscroll2hw(hscroll) \
   (((hscroll)<<12 & 0x3000) | ((hscroll)<<8 & 0xc300) | \
    ((hscroll)<<4 & 0x0c00) | ((hscroll)<<2 & 0x00f0) | ((hscroll)>>2 & 0x000f))

#define hw2hscroll(hscroll) \
   (((hscroll)>>8 & 0x00c3) | ((hscroll)<<2 & 0x003c))

/* diwstrt/diwstop/diwhigh (visible display window) */

#define diwstrt2hw(diwstrt_h, diwstrt_v) \
   (((diwstrt_v)<<8 & 0xff00) | ((diwstrt_h)>>2 & 0x00ff))
#define diwstop2hw(distop_h, diwstop_v) \
   (((diwstop_v)<<8 & 0xff00) | ((diwstop_h)>>2 & 0x00ff))
#define diw2hw_high(diwstrt_h, diwstrt_v, distop_h, diwstop_v) \
   (((diwstop_h)<<3 & 0x2000) | ((diwstop_h)<<11 & 0x1800) | \
    ((diwstop_v) & 0x0700) | ((diwstrt_h)>>5 & 0x0020) | \
    ((diwstrt_h)<<3 & 0x0018) | ((diwstrt_v)>>8 & 0x0007))

#define hw2diwstrt_h(diwstrt, diwhigh) \
   (((diwhigh)<<5 & 0x0400) | ((diwstrt)<<2 & 0x03fc) | ((diwhigh)>>3 & 0x0003))
#define hw2diwstrt_v(diwstrt, diwhigh) \
   (((diwhigh)<<8 & 0x0700) | ((diwstrt)>>8 & 0x00ff))
#define hw2diwstop_h(diwstop, diwhigh) \
   (((diwhigh)>>3 & 0x0400) | ((diwstop)<<2 & 0x03fc) | \
    ((diwhigh)>>11 & 0x0003))
#define hw2diwstop_v(diwstop, diwhigh) \
   (((diwhigh) & 0x0700) | ((diwstop)>>8 & 0x00ff))

/* ddfstrt/ddfstop (display DMA) */

#define ddfstrt2hw(ddfstrt)   (div8(ddfstrt) & 0x00fe)
#define ddfstop2hw(ddfstop)   (div8(ddfstop) & 0x00fe)

#define hw2ddfstrt(ddfstrt)   ((ddfstrt)<<3)
#define hw2ddfstop(ddfstop)   ((ddfstop)<<3)

/* hsstrt/hsstop/htotal/vsstrt/vsstop/vtotal (sync timings) */

#define hsstrt2hw(hsstrt)     (div8(hsstrt))
#define hsstop2hw(hsstop)     (div8(hsstop))
#define htotal2hw(htotal)     (div8(htotal)-1)
#define vsstrt2hw(vsstrt)     (vsstrt)
#define vsstop2hw(vsstop)     (vsstop)
#define vtotal2hw(vtotal)     ((vtotal)-1)

#define hw2hsstrt(hsstrt)     ((hsstrt)<<3)
#define hw2hsstop(hsstop)     ((hsstop)<<3)
#define hw2htotal(htotal)     (((htotal)+1)<<3)
#define hw2vsstrt(vsstrt)     (vsstrt)
#define hw2vsstop(vsstop)     (vsstop)
#define hw2vtotal(vtotal)     ((vtotal)+1)

/* hbstrt/hbstop/vbstrt/vbstop (blanking timings) */

#define hbstrt2hw(hbstrt)     (((hbstrt)<<8 & 0x0700) | ((hbstrt)>>3 & 0x00ff))
#define hbstop2hw(hbstop)     (((hbstop)<<8 & 0x0700) | ((hbstop)>>3 & 0x00ff))
#define vbstrt2hw(vbstrt)     (vbstrt)
#define vbstop2hw(vbstop)     (vbstop)

#define hw2hbstrt(hbstrt)     (((hbstrt)<<3 & 0x07f8) | ((hbstrt)>>8 & 0x0007))
#define hw2hbstop(hbstop)     (((hbstop)<<3 & 0x07f8) | ((hbstop)>>8 & 0x0007))
#define hw2vbstrt(vbstrt)     (vbstrt)
#define hw2vbstop(vbstop)     (vbstop)

/* color */

#define rgb2hw_high(red, green, blue) \
   (((red)<<4 & 0xf00) | ((green) & 0x0f0) | ((blue)>>4 & 0x00f))
#define rgb2hw_low(red, green, blue) \
   (((red)<<8 & 0xf00) | ((green)<<4 & 0x0f0) | ((blue) & 0x00f))

#define hw2red(high, low)     (((high)>>4 & 0xf0) | ((low)>>8 & 0x0f))
#define hw2green(high, low)   (((high) & 0xf0) | ((low)>>4 & 0x0f))
#define hw2blue(high, low)    (((high)<<4 & 0xf0) | ((low) & 0x0f))

/* sprpos/sprctl (sprite positioning) */

#define spr2hw_pos(start_v, start_h) \
   (((start_v)<<8&0xff00) | ((start_h)>>3&0x00ff))
#define spr2hw_ctl(start_v, start_h, stop_v) \
   (((stop_v)<<8&0xff00) | ((start_v)>>3&0x0040) | ((stop_v)>>4&0x0020) | \
    ((start_h)<<3&0x0018) | ((start_v)>>6&0x0004) | ((stop_v)>>7&0x0002) | \
    ((start_h)>>2&0x0001))


   /*
    *    Hardware Cursor
    */

struct aga_cursorsprite {
   u_short sprpos;
   u_short pad1[3];
   u_short sprctl;
   u_short pad2[3];
   union {
      struct {
         u_long data[64*4];
         u_long trailer[4];
      } nonlaced;
      struct {
         u_long data[32*4];
         u_long trailer[4];
      } laced;
   } u;
};

struct aga_dummysprite {
   u_short sprpos;
   u_short pad1[3];
   u_short sprctl;
   u_short pad2[3];
   u_long data[4];
   u_long trailer[4];
};


   /*
    *    Pixel modes for Bitplanes and Sprites
    */

static u_short bplpixmode[3] = {
   BPC0_SHRES,                   /*  35 ns / 28 MHz */
   BPC0_HIRES,                   /*  70 ns / 14 MHz */
   0                             /* 140 ns /  7 MHz */
};

static u_short sprpixmode[3] = {
   BPC3_SPRES1 | BPC3_SPRES0,    /*  35 ns / 28 MHz */
   BPC3_SPRES1,                  /*  70 ns / 14 MHz */
   BPC3_SPRES0                   /* 140 ns /  7 MHz */
};


   /*
    *    Initialization
    *
    *    Allocate the required chip memory.
    *    Set the default video mode for this chipset. If a video mode was
    *    specified on the command line, it will override the default mode.
    */

static int aga_init(void)
{
  return 0;
}


   /*
    *    This function should fill in the `fix' structure based on the
    *    values in the `par' structure.
    */

static int aga_encode_fix(struct fb_fix_screeninfo *fix,
                          struct amiga_fb_par *par)
{
  return 0;
}


   /*
    *    Get the video params out of `var'. If a value doesn't fit, round
    *    it up, if it's too big, return -EINVAL.
    */

static int aga_decode_var(struct fb_var_screeninfo *var,
                          struct amiga_fb_par *par)
{
  return 0;
}


   /*
    *    Fill the `var' structure based on the values in `par' and maybe
    *    other values read out of the hardware.
    */

static int aga_encode_var(struct fb_var_screeninfo *var,
                          struct amiga_fb_par *par)
{
  return 0;
}


   /*
    *    Read a single color register and split it into
    *    colors/transparent. Return != 0 for invalid regno.
    */

static int aga_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
                         u_int *transp)
{
  return 0;
}


   /*
    *    Set a single color register. The values supplied are already
    *    rounded down to the hardware's capabilities (according to the
    *    entries in the var structure). Return != 0 for invalid regno.
    */

static int aga_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                         u_int transp)
{
  return 0;
}


   /*
    *    Pan or Wrap the Display
    *
    *    This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
    *    in `var'.
    */

static int aga_pan_display(struct fb_var_screeninfo *var,
                           struct amiga_fb_par *par)
{
  return 0;
}


   /*
    *    Change the video mode (called by VBlank interrupt)
    */

void aga_do_vmode(void)
{
}


   /*
    *    (Un)Blank the screen (called by VBlank interrupt)
    */

void aga_do_blank(int blank)
{
}


   /*
    *    Move the cursor (called by VBlank interrupt)
    */

void aga_do_movecursor(void)
{
}


   /*
    *    Flash the cursor (called by VBlank interrupt)
    */

void aga_do_flashcursor(void)
{
}


#if 1
static int aga_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix, int con)
{
  return 0;
}


static int aga_get_var_cursorinfo(struct fb_var_cursorinfo *var, int con)
{
  return 0;
}


static int aga_set_var_cursorinfo(struct fb_var_cursorinfo *var, int con)
{
  return 0;
}


static int aga_get_cursorstate(struct fb_cursorstate *state, int con)
{
  return 0;
}


static int aga_set_cursorstate(struct fb_cursorstate *state, int con)
{
  return 0;
}
#endif


   /*
    *    Build the Frame Header Copper List
    */

static __inline__ void aga_build_clist_hdr(struct clist_hdr *cop)
{
}


   /*
    *    Update the Frame Header Copper List
    */

static __inline__ void aga_update_clist_hdr(struct clist_hdr *cop,
                                            struct amiga_fb_par *par)
{
}


   /*
    *    Build the Long Frame/Short Frame Copper List
    */

static void aga_build_clist_dyn(struct clist_dyn *cop,
                                struct clist_dyn *othercop, u_short shf,
                                struct amiga_fb_par *par)
{
}
#endif /* CONFIG_AMIFB_AGA */


/* -------------------- Interfaces to hardware functions -------------------- */


#ifdef CONFIG_AMIFB_OCS
static struct fb_hwswitch ocs_switch = {
   ocs_init, ocs_encode_fix, ocs_decode_var, ocs_encode_var, ocs_getcolreg,
   ocs_setcolreg, ocs_pan_display, ocs_do_vmode, ocs_do_blank,
   ocs_do_movecursor, ocs_do_flashcursor
};
#endif /* CONFIG_AMIFB_OCS */

#ifdef CONFIG_AMIFB_ECS
static struct fb_hwswitch ecs_switch = {
   ecs_init, ecs_encode_fix, ecs_decode_var, ecs_encode_var, ecs_getcolreg,
   ecs_setcolreg, ecs_pan_display, ecs_do_vmode, ecs_do_blank,
   ecs_do_movecursor, ecs_do_flashcursor
};
#endif /* CONFIG_AMIFB_ECS */

#ifdef CONFIG_AMIFB_AGA
static struct fb_hwswitch aga_switch = {
   aga_init, aga_encode_fix, aga_decode_var, aga_encode_var, aga_getcolreg,
   aga_setcolreg, aga_pan_display, aga_do_vmode, aga_do_blank,
   aga_do_movecursor, aga_do_flashcursor
};
#endif /* CONFIG_AMIFB_AGA */


/* -------------------- Generic routines ------------------------------------ */


   /*
    *    Allocate, Clear and Align a Block of Chip Memory
    */

static u_long chipalloc(u_long size)
{
  return 0;
}


   /*
    *    Fill the hardware's `par' structure.
    */

static void amiga_fb_get_par(struct amiga_fb_par *par)
{
}


static void amiga_fb_set_par(struct amiga_fb_par *par)
{
}


static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
{
  return 0;
}


   /*
    *    Default Colormaps
    */

static u_short red2[] =
   { 0x0000, 0xc000 };
static u_short green2[] =
   { 0x0000, 0xc000 };
static u_short blue2[] =
   { 0x0000, 0xc000 };

static u_short red4[] =
   { 0x0000, 0xc000, 0x8000, 0xffff };
static u_short green4[] =
   { 0x0000, 0xc000, 0x8000, 0xffff };
static u_short blue4[] =
   { 0x0000, 0xc000, 0x8000, 0xffff };

static u_short red8[] =
   { 0x0000, 0x0000, 0x0000, 0x0000, 0xc000, 0xc000, 0xc000, 0xc000 };
static u_short green8[] =
   { 0x0000, 0x0000, 0xc000, 0xc000, 0x0000, 0x0000, 0xc000, 0xc000 };
static u_short blue8[] =
   { 0x0000, 0xc000, 0x0000, 0xc000, 0x0000, 0xc000, 0x0000, 0xc000 };

static u_short red16[] =
   { 0x0000, 0x0000, 0x0000, 0x0000, 0xc000, 0xc000, 0xc000, 0xc000,
     0x8000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff };
static u_short green16[] =
   { 0x0000, 0x0000, 0xc000, 0xc000, 0x0000, 0x0000, 0xc000, 0xc000,
     0x8000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff };
static u_short blue16[] =
   { 0x0000, 0xc000, 0x0000, 0xc000, 0x0000, 0xc000, 0x0000, 0xc000,
     0x8000, 0xffff, 0x0000, 0xffff, 0x0000, 0xffff, 0x0000, 0xffff };


static struct fb_cmap default_2_colors =
   { 0, 2, red2, green2, blue2, NULL };
static struct fb_cmap default_8_colors =
   { 0, 8, red8, green8, blue8, NULL };
static struct fb_cmap default_4_colors =
   { 0, 4, red4, green4, blue4, NULL };
static struct fb_cmap default_16_colors =
   { 0, 16, red16, green16, blue16, NULL };


static struct fb_cmap *get_default_colormap(int bpp)
{
   switch (bpp) {
      case 1:
         return(&default_2_colors);
         break;
      case 2:
         return(&default_4_colors);
         break;
      case 3:
         return(&default_8_colors);
         break;
      default:
         return(&default_16_colors);
         break;
   }
}


#define CNVT_TOHW(val,width)     ((((val)<<(width))+0x7fff-(val))>>16)
#define CNVT_FROMHW(val,width)   (((width) ? ((((val)<<16)-(val)) / \
                                              ((1<<(width))-1)) : 0))

static int do_fb_get_cmap(struct fb_cmap *cmap, struct fb_var_screeninfo *var,
                          int kspc)
{
  return 0;
}


static int do_fb_set_cmap(struct fb_cmap *cmap, struct fb_var_screeninfo *var,
                          int kspc)
{
  return 0;
}


static void do_install_cmap(int con)
{
}


static void memcpy_fs(int fsfromto, void *to, void *from, int len)
{
}


static void copy_cmap(struct fb_cmap *from, struct fb_cmap *to, int fsfromto)
{
}


static int alloc_cmap(struct fb_cmap *cmap, int len, int transp)
{
  return 0;
}


   /*
    *    Get the Fixed Part of the Display
    */

static int amiga_fb_get_fix(struct fb_fix_screeninfo *fix, int con)
{
  return 0;
}


   /*
    *    Get the User Defined Part of the Display
    */

static int amiga_fb_get_var(struct fb_var_screeninfo *var, int con)
{
  return 0;
}


static void amiga_fb_set_disp(int con)
{
}


   /*
    *    Set the User Defined Part of the Display
    */

static int amiga_fb_set_var(struct fb_var_screeninfo *var, int con)
{
  return 0;
}


   /*
    *    Get the Colormap
    */

static int amiga_fb_get_cmap(struct fb_cmap *cmap, int kspc, int con)
{
  return 0;
}


   /*
    *    Set the Colormap
    */

static int amiga_fb_set_cmap(struct fb_cmap *cmap, int kspc, int con)
{
  return 0;
}


   /*
    *    Pan or Wrap the Display
    *
    *    This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
    */

static int amiga_fb_pan_display(struct fb_var_screeninfo *var, int con)
{
  return 0;
}


   /*
    *    Amiga Frame Buffer Specific ioctls
    */

static int amiga_fb_ioctl(struct inode *inode, struct file *file,
                          u_int cmd, u_long arg, int con)
{
  return 0;
}


#ifdef CONFIG_AMIFB_AGA
   /*
    *    Hardware Cursor
    */

static int amiga_fb_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix, int con)
{
  return 0;
}


static int amiga_fb_get_var_cursorinfo(struct fb_var_cursorinfo *var, int con)
{
  return 0;
}


static int amiga_fb_set_var_cursorinfo(struct fb_var_cursorinfo *var, int con)
{
  return 0;
}


static int amiga_fb_get_cursorstate(struct fb_cursorstate *state, int con)
{
  return 0;
}


static int amiga_fb_set_cursorstate(struct fb_cursorstate *state, int con)
{
  return 0;
}
#endif /* CONFIG_AMIFB_AGA */


static struct fb_ops amiga_fb_ops = {
   amiga_fb_get_fix, amiga_fb_get_var, amiga_fb_set_var, amiga_fb_get_cmap,
   amiga_fb_set_cmap, amiga_fb_pan_display, amiga_fb_ioctl
};


void amiga_video_setup(char *options, int *ints)
{
}


   /*
    *    Initialization
    */

struct fb_info *amiga_fb_init(long *mem_start)
{
  return NULL;
}


static int amifb_switch(int con)
{
  return 0;
}


   /*
    *    Update the `var' structure (called by fbcon.c)
    *
    *    This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
    *    Since it's called by a kernel driver, no range checking is done.
    */

static int amifb_updatevar(int con)
{
  return 0;
}


   /*
    *    Blank the display.
    */

static void amifb_blank(int blank)
{
}


   /*
    *    VBlank Display Interrupt
    */

static void amifb_interrupt(int irq, struct pt_regs *fp, void *dummy)
{
}


   /*
    *    A strtok which returns empty strings, too
    */

static char * strtoke(char * s,const char * ct)
{
  return NULL;
}


   /*
    *    Get a Video Modes
    */

static int get_video_mode(const char *name)
{
  return 0;
}


   /*
    *    Check the Default Video Mode
    */

static void check_default_mode(void)
{
}
