Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * linux/drivers/video/sstfb.h -- voodoo graphics frame buffer
0004  *
0005  *     Copyright (c) 2000,2001 Ghozlane Toumi <gtoumi@messel.emse.fr>
0006  *
0007  *     Created 28 Aug 2001 by Ghozlane Toumi
0008  */
0009 
0010 
0011 #ifndef _SSTFB_H_
0012 #define _SSTFB_H_
0013 
0014 /*
0015  *
0016  *  Debug Stuff
0017  *
0018  */
0019 
0020 #ifdef SST_DEBUG
0021 #  define dprintk(X...)     printk("sstfb: " X)
0022 #  define SST_DEBUG_REG  1
0023 #  define SST_DEBUG_FUNC 1
0024 #  define SST_DEBUG_VAR  1
0025 #else
0026 #  define dprintk(X...)     no_printk(X)
0027 #  define SST_DEBUG_REG  0
0028 #  define SST_DEBUG_FUNC 0
0029 #  define SST_DEBUG_VAR  0
0030 #endif
0031 
0032 #if (SST_DEBUG_REG > 0)
0033 #  define r_dprintk(X...)   dprintk(X)
0034 #else
0035 #  define r_dprintk(X...)
0036 #endif
0037 #if (SST_DEBUG_REG > 1)
0038 #  define r_ddprintk(X...)  dprintk(" " X)
0039 #else
0040 #  define r_ddprintk(X...)
0041 #endif
0042 
0043 #if (SST_DEBUG_FUNC > 0)
0044 #  define f_dprintk(X...)   dprintk(X)
0045 #else
0046 #  define f_dprintk(X...)
0047 #endif
0048 #if (SST_DEBUG_FUNC > 1)
0049 #  define f_ddprintk(X...)  dprintk(" " X)
0050 #else
0051 #  define f_ddprintk(X...)  no_printk(X)
0052 #endif
0053 #if (SST_DEBUG_FUNC > 2)
0054 #  define f_dddprintk(X...) dprintk(" " X)
0055 #else
0056 #  define f_dddprintk(X...)
0057 #endif
0058 
0059 #if (SST_DEBUG_VAR > 0)
0060 #  define v_dprintk(X...)   dprintk(X)
0061 #  define print_var(V, X...)    \
0062    {                \
0063      dprintk(X);        \
0064      printk(" :\n");        \
0065      sst_dbg_print_var(V);  \
0066    }
0067 #else
0068 #  define v_dprintk(X...)
0069 #  define print_var(X,Y...)
0070 #endif
0071 
0072 #define POW2(x)     (1ul<<(x))
0073 
0074 /*
0075  *
0076  *  Const
0077  *
0078  */
0079 
0080 /* pci stuff */
0081 #define PCI_INIT_ENABLE     0x40
0082 #  define PCI_EN_INIT_WR      BIT(0)
0083 #  define PCI_EN_FIFO_WR      BIT(1)
0084 #  define PCI_REMAP_DAC       BIT(2)
0085 #define PCI_VCLK_ENABLE     0xc0    /* enable video */
0086 #define PCI_VCLK_DISABLE    0xe0
0087 
0088 /* register offsets from memBaseAddr */
0089 #define STATUS          0x0000
0090 #  define STATUS_FBI_BUSY     BIT(7)
0091 #define FBZMODE         0x0110
0092 #  define EN_CLIPPING         BIT(0)    /* enable clipping */
0093 #  define EN_RGB_WRITE        BIT(9)    /* enable writes to rgb area */
0094 #  define EN_ALPHA_WRITE      BIT(10)
0095 #  define ENGINE_INVERT_Y     BIT(17)   /* invert Y origin (pipe) */
0096 #define LFBMODE         0x0114
0097 #  define LFB_565         0     /* bits 3:0 .16 bits RGB */
0098 #  define LFB_888         4     /* 24 bits RGB */
0099 #  define LFB_8888        5     /* 32 bits ARGB */
0100 #  define WR_BUFF_FRONT       0     /* write buf select (front) */
0101 #  define WR_BUFF_BACK        (1 << 4)  /* back */
0102 #  define RD_BUFF_FRONT       0     /* read buff select (front) */
0103 #  define RD_BUFF_BACK        (1 << 6)  /* back */
0104 #  define EN_PXL_PIPELINE     BIT(8)    /* pixel pipeline (clip..)*/
0105 #  define LFB_WORD_SWIZZLE_WR     BIT(11)   /* enable write-wordswap (big-endian) */
0106 #  define LFB_BYTE_SWIZZLE_WR     BIT(12)   /* enable write-byteswap (big-endian) */
0107 #  define LFB_INVERT_Y        BIT(13)   /* invert Y origin (LFB) */
0108 #  define LFB_WORD_SWIZZLE_RD     BIT(15)   /* enable read-wordswap (big-endian) */
0109 #  define LFB_BYTE_SWIZZLE_RD     BIT(16)   /* enable read-byteswap (big-endian) */
0110 #define CLIP_LEFT_RIGHT     0x0118
0111 #define CLIP_LOWY_HIGHY     0x011c
0112 #define NOPCMD          0x0120
0113 #define FASTFILLCMD     0x0124
0114 #define SWAPBUFFCMD     0x0128
0115 #define FBIINIT4        0x0200      /* misc controls */
0116 #  define FAST_PCI_READS      0     /* 1 waitstate */
0117 #  define SLOW_PCI_READS      BIT(0)    /* 2 ws */
0118 #  define LFB_READ_AHEAD      BIT(1)
0119 #define BACKPORCH       0x0208
0120 #define VIDEODIMENSIONS     0x020c
0121 #define FBIINIT0        0x0210      /* misc+fifo  controls */
0122 #  define DIS_VGA_PASSTHROUGH     BIT(0)
0123 #  define FBI_RESET       BIT(1)
0124 #  define FIFO_RESET          BIT(2)
0125 #define FBIINIT1        0x0214      /* PCI + video controls */
0126 #  define VIDEO_MASK          0x8080010f    /* masks video related bits V1+V2*/
0127 #  define FAST_PCI_WRITES     0     /* 0 ws */
0128 #  define SLOW_PCI_WRITES     BIT(1)    /* 1 ws */
0129 #  define EN_LFB_READ         BIT(3)
0130 #  define TILES_IN_X_SHIFT    4
0131 #  define VIDEO_RESET         BIT(8)
0132 #  define EN_BLANKING         BIT(12)
0133 #  define EN_DATA_OE          BIT(13)
0134 #  define EN_BLANK_OE         BIT(14)
0135 #  define EN_HVSYNC_OE        BIT(15)
0136 #  define EN_DCLK_OE          BIT(16)
0137 #  define SEL_INPUT_VCLK_2X   0     /* bit 17 */
0138 #  define SEL_INPUT_VCLK_SLAVE    BIT(17)
0139 #  define SEL_SOURCE_VCLK_SLAVE   0     /* bits 21:20 */
0140 #  define SEL_SOURCE_VCLK_2X_DIV2 (0x01 << 20)
0141 #  define SEL_SOURCE_VCLK_2X_SEL  (0x02 << 20)
0142 #  define EN_24BPP        BIT(22)
0143 #  define TILES_IN_X_MSB_SHIFT    24        /* v2 */
0144 #  define VCLK_2X_SEL_DEL_SHIFT   27        /* vclk out delay 0,4,6,8ns */
0145 #  define VCLK_DEL_SHIFT      29        /* vclk in delay */
0146 #define FBIINIT2        0x0218      /* Dram controls */
0147 #  define EN_FAST_RAS_READ    BIT(5)
0148 #  define EN_DRAM_OE          BIT(6)
0149 #  define EN_FAST_RD_AHEAD_WR     BIT(7)
0150 #  define VIDEO_OFFSET_SHIFT      11        /* unit: #rows tile 64x16/2 */
0151 #  define SWAP_DACVSYNC       0
0152 #  define SWAP_DACDATA0       (1 << 9)
0153 #  define SWAP_FIFO_STALL     (2 << 9)
0154 #  define EN_RD_AHEAD_FIFO    BIT(21)
0155 #  define EN_DRAM_REFRESH     BIT(22)
0156 #  define DRAM_REFRESH_16     (0x30 << 23)  /* dram 16 ms */
0157 #define DAC_READ        FBIINIT2    /* in remap mode */
0158 #define FBIINIT3        0x021c      /* fbi controls */
0159 #  define DISABLE_TEXTURE     BIT(6)
0160 #  define Y_SWAP_ORIGIN_SHIFT     22        /* Y swap subtraction value */
0161 #define HSYNC           0x0220
0162 #define VSYNC           0x0224
0163 #define DAC_DATA        0x022c
0164 #  define DAC_READ_CMD        BIT(11)   /* set read dacreg mode */
0165 #define FBIINIT5        0x0244      /* v2 specific */
0166 #  define FBIINIT5_MASK       0xfa40ffff    /* mask video bits*/
0167 #  define HDOUBLESCAN         BIT(20)
0168 #  define VDOUBLESCAN         BIT(21)
0169 #  define HSYNC_HIGH          BIT(23)
0170 #  define VSYNC_HIGH          BIT(24)
0171 #  define INTERLACE       BIT(26)
0172 #define FBIINIT6        0x0248      /* v2 specific */
0173 #  define TILES_IN_X_LSB_SHIFT    30        /* v2 */
0174 #define FBIINIT7        0x024c      /* v2 specific */
0175 
0176 #define BLTSRCBASEADDR      0x02c0  /* BitBLT Source base address */
0177 #define BLTDSTBASEADDR      0x02c4  /* BitBLT Destination base address */
0178 #define BLTXYSTRIDES        0x02c8  /* BitBLT Source and Destination strides */
0179 #define BLTSRCCHROMARANGE   0x02cc  /* BitBLT Source Chroma key range */
0180 #define BLTDSTCHROMARANGE   0x02d0  /* BitBLT Destination Chroma key range */
0181 #define BLTCLIPX        0x02d4  /* BitBLT Min/Max X clip values */
0182 #define BLTCLIPY        0x02d8  /* BitBLT Min/Max Y clip values */
0183 #define BLTSRCXY        0x02e0  /* BitBLT Source starting XY coordinates */
0184 #define BLTDSTXY        0x02e4  /* BitBLT Destination starting XY coordinates */
0185 #define BLTSIZE         0x02e8  /* BitBLT width and height */
0186 #define BLTROP          0x02ec  /* BitBLT Raster operations */
0187 #  define BLTROP_COPY         0x0cccc
0188 #  define BLTROP_INVERT       0x05555
0189 #  define BLTROP_XOR          0x06666
0190 #define BLTCOLOR        0x02f0  /* BitBLT and foreground background colors */
0191 #define BLTCOMMAND      0x02f8  /* BitBLT command mode (v2 specific) */
0192 # define BLT_SCR2SCR_BITBLT   0   /* Screen-to-Screen BitBLT */
0193 # define BLT_CPU2SCR_BITBLT   1   /* CPU-to-screen BitBLT */
0194 # define BLT_RECFILL_BITBLT   2   /* BitBLT Rectangle Fill */
0195 # define BLT_16BPP_FMT        2   /* 16 BPP (5-6-5 RGB) */
0196 #define BLTDATA         0x02fc  /* BitBLT data for CPU-to-Screen BitBLTs */
0197 #  define LAUNCH_BITBLT       BIT(31) /* Launch BitBLT in BltCommand, bltDstXY or bltSize */
0198 
0199 /* Dac Registers */
0200 #define DACREG_WMA      0x0 /* pixel write mode address */
0201 #define DACREG_LUT      0x01    /* color value */
0202 #define DACREG_RMR      0x02    /* pixel mask */
0203 #define DACREG_RMA      0x03    /* pixel read mode address */
0204 /*Dac registers in indexed mode (TI, ATT dacs) */
0205 #define DACREG_ADDR_I       DACREG_WMA
0206 #define DACREG_DATA_I       DACREG_RMR
0207 #define DACREG_RMR_I        0x00
0208 #define DACREG_CR0_I        0x01
0209 #  define DACREG_CR0_EN_INDEXED   BIT(0)    /* enable indexec mode */
0210 #  define DACREG_CR0_8BIT     BIT(1)    /* set dac to 8 bits/read */
0211 #  define DACREG_CR0_PWDOWN   BIT(3)    /* powerdown dac */
0212 #  define DACREG_CR0_16BPP    0x30      /* mode 3 */
0213 #  define DACREG_CR0_24BPP    0x50      /* mode 5 */
0214 #define DACREG_CR1_I        0x05
0215 #define DACREG_CC_I     0x06
0216 #  define DACREG_CC_CLKA      BIT(7)    /* clk A controlled by regs */
0217 #  define DACREG_CC_CLKA_C    (2<<4)    /* clk A uses reg C */
0218 #  define DACREG_CC_CLKB      BIT(3)    /* clk B controlled by regs */
0219 #  define DACREG_CC_CLKB_D    3     /* clkB uses reg D */
0220 #define DACREG_AC0_I        0x48        /* clock A reg C */
0221 #define DACREG_AC1_I        0x49
0222 #define DACREG_BD0_I        0x6c        /* clock B reg D */
0223 #define DACREG_BD1_I        0x6d
0224 
0225 /* identification constants */
0226 #define DACREG_MIR_TI       0x97
0227 #define DACREG_DIR_TI       0x09
0228 #define DACREG_MIR_ATT      0x84
0229 #define DACREG_DIR_ATT      0x09
0230 /* ics dac specific registers */
0231 #define DACREG_ICS_PLLWMA   0x04    /* PLL write mode address */
0232 #define DACREG_ICS_PLLDATA  0x05    /* PLL data /parameter */
0233 #define DACREG_ICS_CMD      0x06    /* command */
0234 #  define DACREG_ICS_CMD_16BPP    0x50  /* ics color mode 6 (16bpp bypass)*/
0235 #  define DACREG_ICS_CMD_24BPP    0x70  /* ics color mode 7 (24bpp bypass)*/
0236 #  define DACREG_ICS_CMD_PWDOWN BIT(0)  /* powerdown dac */
0237 #define DACREG_ICS_PLLRMA   0x07    /* PLL read mode address */
0238 /*
0239  * pll parameter register:
0240  * indexed : write addr to PLLWMA, write data in PLLDATA.
0241  * for reads use PLLRMA .
0242  * 8 freq registers (0-7) for video clock (CLK0)
0243  * 2 freq registers (a-b) for graphic clock (CLK1)
0244  */
0245 #define DACREG_ICS_PLL_CLK0_1_INI 0x55  /* initial pll M value for freq f1  */
0246 #define DACREG_ICS_PLL_CLK0_7_INI 0x71  /* f7 */
0247 #define DACREG_ICS_PLL_CLK1_B_INI 0x79  /* fb */
0248 #define DACREG_ICS_PLL_CTRL 0x0e
0249 #  define DACREG_ICS_CLK0     BIT(5)
0250 #  define DACREG_ICS_CLK0_0   0
0251 #  define DACREG_ICS_CLK1_A   0 /* bit4 */
0252 
0253 /* sst default init registers */
0254 #define FBIINIT0_DEFAULT DIS_VGA_PASSTHROUGH
0255 
0256 #define FBIINIT1_DEFAULT    \
0257     (           \
0258       FAST_PCI_WRITES   \
0259 /*    SLOW_PCI_WRITES*/ \
0260     | VIDEO_RESET       \
0261     | 10 << TILES_IN_X_SHIFT\
0262     | SEL_SOURCE_VCLK_2X_SEL\
0263     | EN_LFB_READ       \
0264     )
0265 
0266 #define FBIINIT2_DEFAULT    \
0267     (           \
0268      SWAP_DACVSYNC      \
0269     | EN_DRAM_OE        \
0270     | DRAM_REFRESH_16   \
0271     | EN_DRAM_REFRESH   \
0272     | EN_FAST_RAS_READ  \
0273     | EN_RD_AHEAD_FIFO  \
0274     | EN_FAST_RD_AHEAD_WR   \
0275     )
0276 
0277 #define FBIINIT3_DEFAULT    \
0278     ( DISABLE_TEXTURE )
0279 
0280 #define FBIINIT4_DEFAULT    \
0281     (           \
0282       FAST_PCI_READS    \
0283 /*    SLOW_PCI_READS*/  \
0284     | LFB_READ_AHEAD    \
0285     )
0286 /* Careful with this one : writing back the data just read will trash the DAC
0287    reading some fields give logic value on pins, but setting this field will
0288    set the source signal driving the pin. conclusion : just use the default
0289    as a base before writing back .
0290 */
0291 #define FBIINIT6_DEFAULT    (0x0)
0292 
0293 /*
0294  *
0295  * Misc Const
0296  *
0297  */
0298 
0299 /* ioctl to enable/disable VGA passthrough */
0300 #define SSTFB_SET_VGAPASS   _IOW('F', 0xdd, __u32)
0301 #define SSTFB_GET_VGAPASS   _IOR('F', 0xdd, __u32)
0302 
0303 
0304 /* used to know witch clock to set */
0305 enum {
0306     VID_CLOCK=0,
0307     GFX_CLOCK=1,
0308 };
0309 
0310 /* freq max */
0311 #define DAC_FREF    14318   /* DAC reference freq (Khz) */
0312 #define VCO_MAX     260000
0313 
0314 /*
0315  *  driver structs
0316  */
0317 
0318 struct pll_timing {
0319     unsigned int m;
0320     unsigned int n;
0321     unsigned int p;
0322 };
0323 
0324 struct dac_switch {
0325     const char *name;
0326     int (*detect) (struct fb_info *info);
0327     int (*set_pll) (struct fb_info *info, const struct pll_timing *t, const int clock);
0328     void (*set_vidmod) (struct fb_info *info, const int bpp);
0329 };
0330 
0331 struct sst_spec {
0332     char * name;
0333     int default_gfx_clock;  /* 50000 for voodoo1, 75000 for voodoo2 */
0334     int max_gfxclk;     /* ! in Mhz ie 60 for voodoo 1 */
0335 };
0336 
0337 struct sstfb_par {
0338     u32 palette[16];
0339     unsigned int yDim;
0340     unsigned int hSyncOn;   /* hsync_len */
0341     unsigned int hSyncOff;  /* left_margin + xres + right_margin */
0342     unsigned int hBackPorch;/* left_margin */
0343     unsigned int vSyncOn;
0344     unsigned int vSyncOff;
0345     unsigned int vBackPorch;
0346     struct pll_timing pll;
0347     unsigned int tiles_in_X;/* num of tiles in X res */
0348     u8 __iomem *mmio_vbase;
0349     struct dac_switch   dac_sw; /* dac specific functions */
0350     struct pci_dev      *dev;
0351     int type;
0352     u8  revision;
0353     u8  vgapass;    /* VGA pass through: 1=enabled, 0=disabled */
0354 };
0355 
0356 #endif /* _SSTFB_H_ */