ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / video / sstfb.h
1 /*
2  * linux/drivers/video/sstfb.h -- voodoo graphics frame buffer
3  *
4  *     Copyright (c) 2000,2001 Ghozlane Toumi <gtoumi@messel.emse.fr>
5  *
6  *     Created 28 Aug 2001 by Ghozlane Toumi
7  */
8
9
10 #ifndef _SSTFB_H_
11 #define _SSTFB_H_
12
13 /*
14  *
15  *  Debug Stuff
16  *
17  */
18
19 #ifdef SST_DEBUG
20 #  define dprintk(X...)         printk("sstfb: " X)
21 #else
22 #  define dprintk(X...)
23 #  undef SST_DEBUG_REG
24 #  undef SST_DEBUG_FUNC
25 #  undef SST_DEBUG_VAR
26 #endif
27
28 #if (SST_DEBUG_REG > 0)
29 #  define r_dprintk(X...)       dprintk(X)
30 #else
31 #  define r_dprintk(X...)
32 #endif
33 #if (SST_DEBUG_REG > 1)
34 #  define r_ddprintk(X...)      dprintk(" " X)
35 #else
36 #  define r_ddprintk(X...)
37 #endif
38
39 #if (SST_DEBUG_FUNC > 0)
40 #  define f_dprintk(X...)       dprintk(X)
41 #else
42 #  define f_dprintk(X...)
43 #endif
44 #if (SST_DEBUG_FUNC > 1)
45 #  define f_ddprintk(X...)      dprintk(" " X)
46 #else
47 #  define f_ddprintk(X...)
48 #endif
49 #if (SST_DEBUG_FUNC > 2)
50 #  define f_dddprintk(X...)     dprintk(" " X)
51 #else
52 #  define f_dddprintk(X...)
53 #endif
54
55 #if (SST_DEBUG_VAR > 0)
56 #  define v_dprintk(X...)       dprintk(X)
57 #  define print_var(V, X...)    \
58    {                            \
59      dprintk(X);                \
60      printk(" :\n");            \
61      sst_dbg_print_var(V);      \
62    }
63 #else
64 #  define v_dprintk(X...)
65 #  define print_var(X,Y...)
66 #endif
67
68 #define eprintk(X...)   printk(KERN_ERR "sstfb: " X)
69 #define iprintk(X...)   printk(KERN_INFO "sstfb: " X)
70 #define wprintk(X...)   printk(KERN_WARNING "sstfb: " X)
71
72 #define BIT(x)          (1ul<<(x))
73 #define POW2(x)         (1ul<<(x))
74
75 #ifndef ABS
76 # define ABS(x)         (((x)<0)?-(x):(x))
77 #endif
78
79 /*
80  *
81  *  Const
82  *
83  */
84
85 /* pci stuff */
86 #define PCI_INIT_ENABLE         0x40
87 #  define PCI_EN_INIT_WR          BIT(0)
88 #  define PCI_EN_FIFO_WR          BIT(1)
89 #  define PCI_REMAP_DAC           BIT(2)
90 #define PCI_VCLK_ENABLE         0xc0    /* enable video */
91 #define PCI_VCLK_DISABLE        0xe0
92
93 /* register offsets from memBaseAddr */
94 #define STATUS                  0x0000
95 #  define STATUS_FBI_BUSY         BIT(7)
96 #define FBZMODE                 0x0110
97 #  define EN_CLIPPING             BIT(0)        /* enable clipping */
98 #  define EN_RGB_WRITE            BIT(9)        /* enable writes to rgb area */
99 #  define EN_ALPHA_WRITE          BIT(10)
100 #  define ENGINE_INVERT_Y         BIT(17)       /* invert Y origin (pipe) */
101 #define LFBMODE                 0x0114
102 #  define LFB_565                 0             /* bits 3:0 .16 bits RGB */
103 #  define LFB_888                 4             /* 24 bits RGB */
104 #  define LFB_8888                5             /* 32 bits ARGB */
105 #  define WR_BUFF_FRONT           0             /* write buf select (front) */
106 #  define WR_BUFF_BACK            (1 << 4)      /* back */
107 #  define RD_BUFF_FRONT           0             /* read buff select (front) */
108 #  define RD_BUFF_BACK            (1 << 6)      /* back */
109 #  define EN_PXL_PIPELINE         BIT(8)        /* pixel pipeline (clip..)*/
110 #  define LFB_WORD_SWIZZLE_WR     BIT(11)       /* enable write-wordswap (big-endian) */
111 #  define LFB_BYTE_SWIZZLE_WR     BIT(12)       /* enable write-byteswap (big-endian) */
112 #  define LFB_INVERT_Y            BIT(13)       /* invert Y origin (LFB) */
113 #  define LFB_WORD_SWIZZLE_RD     BIT(15)       /* enable read-wordswap (big-endian) */
114 #  define LFB_BYTE_SWIZZLE_RD     BIT(16)       /* enable read-byteswap (big-endian) */
115 #define CLIP_LEFT_RIGHT         0x0118
116 #define CLIP_LOWY_HIGHY         0x011c
117 #define NOPCMD                  0x0120
118 #define FASTFILLCMD             0x0124
119 #define SWAPBUFFCMD             0x0128
120 #define FBIINIT4                0x0200          /* misc controls */
121 #  define FAST_PCI_READS          0             /* 1 waitstate */
122 #  define SLOW_PCI_READS          BIT(0)        /* 2 ws */
123 #  define LFB_READ_AHEAD          BIT(1)
124 #define BACKPORCH               0x0208
125 #define VIDEODIMENSIONS         0x020c
126 #define FBIINIT0                0x0210          /* misc+fifo  controls */
127 #  define EN_VGA_PASSTHROUGH      BIT(0)
128 #  define FBI_RESET               BIT(1)
129 #  define FIFO_RESET              BIT(2)
130 #define FBIINIT1                0x0214          /* PCI + video controls */
131 #  define VIDEO_MASK              0x8080010f    /* masks video related bits V1+V2*/
132 #  define FAST_PCI_WRITES         0             /* 0 ws */
133 #  define SLOW_PCI_WRITES         BIT(1)        /* 1 ws */
134 #  define EN_LFB_READ             BIT(3)
135 #  define TILES_IN_X_SHIFT        4
136 #  define VIDEO_RESET             BIT(8)
137 #  define EN_BLANKING             BIT(12)
138 #  define EN_DATA_OE              BIT(13)
139 #  define EN_BLANK_OE             BIT(14)
140 #  define EN_HVSYNC_OE            BIT(15)
141 #  define EN_DCLK_OE              BIT(16)
142 #  define SEL_INPUT_VCLK_2X       0             /* bit 17 */
143 #  define SEL_INPUT_VCLK_SLAVE    BIT(17)
144 #  define SEL_SOURCE_VCLK_SLAVE   0             /* bits 21:20 */
145 #  define SEL_SOURCE_VCLK_2X_DIV2 (0x01 << 20)
146 #  define SEL_SOURCE_VCLK_2X_SEL  (0x02 << 20)
147 #  define EN_24BPP                BIT(22)
148 #  define TILES_IN_X_MSB_SHIFT    24            /* v2 */
149 #  define VCLK_2X_SEL_DEL_SHIFT   27            /* vclk out delay 0,4,6,8ns */
150 #  define VCLK_DEL_SHIFT          29            /* vclk in delay */
151 #define FBIINIT2                0x0218          /* Dram controls */
152 #  define EN_FAST_RAS_READ        BIT(5)
153 #  define EN_DRAM_OE              BIT(6)
154 #  define EN_FAST_RD_AHEAD_WR     BIT(7)
155 #  define VIDEO_OFFSET_SHIFT      11            /* unit: #rows tile 64x16/2 */
156 #  define SWAP_DACVSYNC           0
157 #  define SWAP_DACDATA0           (1 << 9)
158 #  define SWAP_FIFO_STALL         (2 << 9)
159 #  define EN_RD_AHEAD_FIFO        BIT(21)
160 #  define EN_DRAM_REFRESH         BIT(22)
161 #  define DRAM_REFRESH_16         (0x30 << 23)  /* dram 16 ms */
162 #define DAC_READ                FBIINIT2        /* in remap mode */
163 #define FBIINIT3                0x021c          /* fbi controls */
164 #  define DISABLE_TEXTURE         BIT(6)
165 #  define Y_SWAP_ORIGIN_SHIFT     22            /* Y swap substraction value */
166 #define HSYNC                   0x0220
167 #define VSYNC                   0x0224
168 #define DAC_DATA                0x022c
169 #  define DAC_READ_CMD            BIT(11)       /* set read dacreg mode */
170 #define FBIINIT5                0x0244          /* v2 specific */
171 #  define FBIINIT5_MASK           0xfa40ffff    /* mask video bits*/
172 #  define HDOUBLESCAN             BIT(20)
173 #  define VDOUBLESCAN             BIT(21)
174 #  define HSYNC_HIGH              BIT(23)
175 #  define VSYNC_HIGH              BIT(24)
176 #  define INTERLACE               BIT(26)
177 #define FBIINIT6                0x0248          /* v2 specific */
178 #  define TILES_IN_X_LSB_SHIFT    30            /* v2 */
179 #define FBIINIT7                0x024c          /* v2 specific */
180
181 #define BLTSRCBASEADDR          0x02c0  /* BitBLT Source base address */
182 #define BLTDSTBASEADDR          0x02c4  /* BitBLT Destination base address */
183 #define BLTXYSTRIDES            0x02c8  /* BitBLT Source and Destination strides */
184 #define BLTSRCCHROMARANGE       0x02cc  /* BitBLT Source Chroma key range */
185 #define BLTDSTCHROMARANGE       0x02d0  /* BitBLT Destination Chroma key range */
186 #define BLTCLIPX                0x02d4  /* BitBLT Min/Max X clip values */
187 #define BLTCLIPY                0x02d8  /* BitBLT Min/Max Y clip values */
188 #define BLTSRCXY                0x02e0  /* BitBLT Source starting XY coordinates */
189 #define BLTDSTXY                0x02e4  /* BitBLT Destination starting XY coordinates */
190 #define BLTSIZE                 0x02e8  /* BitBLT width and height */
191 #define BLTROP                  0x02ec  /* BitBLT Raster operations */
192 #  define BLTROP_COPY             0x0cccc
193 #  define BLTROP_INVERT           0x05555
194 #  define BLTROP_XOR              0x06666
195 #define BLTCOLOR                0x02f0  /* BitBLT and foreground background colors */
196 #define BLTCOMMAND              0x02f8  /* BitBLT command mode (v2 specific) */
197 # define BLT_SCR2SCR_BITBLT       0       /* Screen-to-Screen BitBLT */
198 # define BLT_CPU2SCR_BITBLT       1       /* CPU-to-screen BitBLT */
199 # define BLT_RECFILL_BITBLT       2       /* BitBLT Rectangle Fill */
200 # define BLT_16BPP_FMT            2       /* 16 BPP (5-6-5 RGB) */
201 #define BLTDATA                 0x02fc  /* BitBLT data for CPU-to-Screen BitBLTs */
202 #  define LAUNCH_BITBLT           BIT(31) /* Launch BitBLT in BltCommand, bltDstXY or bltSize */
203
204 /* Dac Registers */
205 #define DACREG_WMA              0x0     /* pixel write mode address */
206 #define DACREG_LUT              0x01    /* color value */
207 #define DACREG_RMR              0x02    /* pixel mask */
208 #define DACREG_RMA              0x03    /* pixel read mode address */
209 /*Dac registers in indexed mode (TI, ATT dacs) */
210 #define DACREG_ADDR_I           DACREG_WMA
211 #define DACREG_DATA_I           DACREG_RMR
212 #define DACREG_RMR_I            0x00
213 #define DACREG_CR0_I            0x01
214 #  define DACREG_CR0_EN_INDEXED   BIT(0)        /* enable indexec mode */
215 #  define DACREG_CR0_8BIT         BIT(1)        /* set dac to 8 bits/read */
216 #  define DACREG_CR0_PWDOWN       BIT(3)        /* powerdown dac */
217 #  define DACREG_CR0_16BPP        0x30          /* mode 3 */
218 #  define DACREG_CR0_24BPP        0x50          /* mode 5 */
219 #define DACREG_CR1_I            0x05
220 #define DACREG_CC_I             0x06
221 #  define DACREG_CC_CLKA          BIT(7)        /* clk A controled by regs */
222 #  define DACREG_CC_CLKA_C        (2<<4)        /* clk A uses reg C */
223 #  define DACREG_CC_CLKB          BIT(3)        /* clk B controled by regs */
224 #  define DACREG_CC_CLKB_D        3             /* clkB uses reg D */
225 #define DACREG_AC0_I            0x48            /* clock A reg C */
226 #define DACREG_AC1_I            0x49
227 #define DACREG_BD0_I            0x6c            /* clock B reg D */
228 #define DACREG_BD1_I            0x6d
229
230 /* identification constants */
231 #define DACREG_MIR_TI           0x97
232 #define DACREG_DIR_TI           0x09
233 #define DACREG_MIR_ATT          0x84
234 #define DACREG_DIR_ATT          0x09
235 /* ics dac specific registers */
236 #define DACREG_ICS_PLLWMA       0x04    /* PLL write mode address */
237 #define DACREG_ICS_PLLDATA      0x05    /* PLL data /parameter */
238 #define DACREG_ICS_CMD          0x06    /* command */
239 #  define DACREG_ICS_CMD_16BPP    0x50  /* ics color mode 6 (16bpp bypass)*/
240 #  define DACREG_ICS_CMD_24BPP    0x70  /* ics color mode 7 (24bpp bypass)*/
241 #  define DACREG_ICS_CMD_PWDOWN BIT(0)  /* powerdown dac */
242 #define DACREG_ICS_PLLRMA       0x07    /* PLL read mode address */
243 /*
244  * pll parameter register:
245  * indexed : write addr to PLLWMA, write data in PLLDATA.
246  * for reads use PLLRMA .
247  * 8 freq registers (0-7) for video clock (CLK0)
248  * 2 freq registers (a-b) for graphic clock (CLK1)
249  */
250 #define DACREG_ICS_PLL_CLK0_1_INI 0x55  /* initial pll M value for freq f1  */
251 #define DACREG_ICS_PLL_CLK0_7_INI 0x71  /* f7 */
252 #define DACREG_ICS_PLL_CLK1_B_INI 0x79  /* fb */
253 #define DACREG_ICS_PLL_CTRL     0x0e
254 #  define DACREG_ICS_CLK0         BIT(5)
255 #  define DACREG_ICS_CLK0_0       0
256 #  define DACREG_ICS_CLK1_A       0     /* bit4 */
257
258 /* sst default init registers */
259 #define FBIINIT0_DEFAULT EN_VGA_PASSTHROUGH
260
261 #define FBIINIT1_DEFAULT        \
262         (                       \
263           FAST_PCI_WRITES       \
264 /*        SLOW_PCI_WRITES*/     \
265         | VIDEO_RESET           \
266         | 10 << TILES_IN_X_SHIFT\
267         | SEL_SOURCE_VCLK_2X_SEL\
268         | EN_LFB_READ           \
269         )
270
271 #define FBIINIT2_DEFAULT        \
272         (                       \
273          SWAP_DACVSYNC          \
274         | EN_DRAM_OE            \
275         | DRAM_REFRESH_16       \
276         | EN_DRAM_REFRESH       \
277         | EN_FAST_RAS_READ      \
278         | EN_RD_AHEAD_FIFO      \
279         | EN_FAST_RD_AHEAD_WR   \
280         )
281
282 #define FBIINIT3_DEFAULT        \
283         ( DISABLE_TEXTURE )
284
285 #define FBIINIT4_DEFAULT        \
286         (                       \
287           FAST_PCI_READS        \
288 /*        SLOW_PCI_READS*/      \
289         | LFB_READ_AHEAD        \
290         )
291 /* Careful with this one : writing back the data just read will trash the DAC
292    reading some fields give logic value on pins, but setting this field will
293    set the source signal driving the pin. conclusion : just use the default
294    as a base before writing back .
295 */
296 #define FBIINIT6_DEFAULT        (0x0)
297
298 /*
299  *
300  * Misc Const
301  *
302  */
303
304 /* used to know witch clock to set */
305 enum {
306         VID_CLOCK=0,
307         GFX_CLOCK=1,
308 };
309
310 /* freq max */
311 #define DAC_FREF        14318   /* DAC reference freq (Khz) */
312 #define VCO_MAX         260000
313
314 /*
315  *  driver structs
316  */
317
318 struct pll_timing {
319         unsigned int m;
320         unsigned int n;
321         unsigned int p;
322 };
323
324 struct dac_switch {
325         char * name;
326         int (*detect) (struct fb_info *info);
327         int (*set_pll) (struct fb_info *info, const struct pll_timing *t, const int clock);
328         void (*set_vidmod) (struct fb_info *info, const int bpp);
329 };
330
331 struct sst_spec {
332         char * name;
333         int default_gfx_clock;  /* 50000 for voodoo1, 75000 for voodoo2 */
334         int max_gfxclk;         /* ! in Mhz ie 60 for voodoo 1 */
335 };
336
337 struct sstfb_par {
338         unsigned int yDim;
339         unsigned int hSyncOn;   /* hsync_len */
340         unsigned int hSyncOff;  /* left_margin + xres + right_margin */
341         unsigned int hBackPorch;/* left_margin */
342         unsigned int vSyncOn;
343         unsigned int vSyncOff;
344         unsigned int vBackPorch;
345         struct pll_timing pll;
346         unsigned int tiles_in_X;/* num of tiles in X res */
347         unsigned long mmio_vbase;
348         struct dac_switch       dac_sw; /* dac specific functions */
349         struct pci_dev          *dev;
350         int     type;
351         u8      revision;
352         int     gfx_clock;      /* status */
353 };
354
355 #endif /* _SSTFB_H_ */