blob: d6f94742c9f27bbe49421452797d63b56a3033f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/savagefb.h -- S3 Savage Framebuffer Driver
3 *
4 * Copyright (c) 2001 Denis Oliver Kropp <dok@convergence.de>
5 *
6 * This file is subject to the terms and conditions of the GNU General
7 * Public License. See the file COPYING in the main directory of this
8 * archive for more details.
9 */
10
11
12#ifndef __SAVAGEFB_H__
13#define __SAVAGEFB_H__
14
15#include <linux/i2c.h>
16#include <linux/i2c-id.h>
17#include <linux/i2c-algo-bit.h>
18#include "../edid.h"
19
20#ifdef SAVAGEFB_DEBUG
21# define DBG(x) printk (KERN_DEBUG "savagefb: %s\n", (x));
22#else
23# define DBG(x)
24# define SavagePrintRegs(...)
25#endif
26
27
28#define PCI_CHIP_SAVAGE4 0x8a22
29#define PCI_CHIP_SAVAGE3D 0x8a20
30#define PCI_CHIP_SAVAGE3D_MV 0x8a21
31#define PCI_CHIP_SAVAGE2000 0x9102
32#define PCI_CHIP_SAVAGE_MX_MV 0x8c10
33#define PCI_CHIP_SAVAGE_MX 0x8c11
34#define PCI_CHIP_SAVAGE_IX_MV 0x8c12
35#define PCI_CHIP_SAVAGE_IX 0x8c13
36#define PCI_CHIP_PROSAVAGE_PM 0x8a25
37#define PCI_CHIP_PROSAVAGE_KM 0x8a26
38 /* Twister is a code name; hope I get the real name soon. */
39#define PCI_CHIP_S3TWISTER_P 0x8d01
40#define PCI_CHIP_S3TWISTER_K 0x8d02
41#define PCI_CHIP_PROSAVAGE_DDR 0x8d03
42#define PCI_CHIP_PROSAVAGE_DDRK 0x8d04
43#define PCI_CHIP_SUPSAV_MX128 0x8c22
44#define PCI_CHIP_SUPSAV_MX64 0x8c24
45#define PCI_CHIP_SUPSAV_MX64C 0x8c26
46#define PCI_CHIP_SUPSAV_IX128SDR 0x8c2a
47#define PCI_CHIP_SUPSAV_IX128DDR 0x8c2b
48#define PCI_CHIP_SUPSAV_IX64SDR 0x8c2c
49#define PCI_CHIP_SUPSAV_IX64DDR 0x8c2d
50#define PCI_CHIP_SUPSAV_IXCSDR 0x8c2e
51#define PCI_CHIP_SUPSAV_IXCDDR 0x8c2f
52
53
54
55#define S3_SAVAGE3D_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
56
57#define S3_SAVAGE4_SERIES(chip) ((chip==S3_SAVAGE4) || (chip==S3_PROSAVAGE))
58
59#define S3_SAVAGE_MOBILE_SERIES(chip) ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
60
61#define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
62
Antonino A. Daplas13776712005-09-09 13:04:35 -070063#define S3_MOBILE_TWISTER_SERIES(chip) ((chip==S3_TWISTER) || (chip == S3_PROSAVAGEDDR))
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* Chip tags. These are used to group the adapters into
66 * related families.
67 */
68
69typedef enum {
70 S3_UNKNOWN = 0,
71 S3_SAVAGE3D,
72 S3_SAVAGE_MX,
73 S3_SAVAGE4,
74 S3_PROSAVAGE,
75 S3_SUPERSAVAGE,
76 S3_SAVAGE2000,
Antonino A. Daplas13776712005-09-09 13:04:35 -070077 S3_PROSAVAGEDDR,
78 S3_TWISTER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 S3_LAST
80} savage_chipset;
81
82#define BIOS_BSIZE 1024
83#define BIOS_BASE 0xc0000
84
85#define SAVAGE_NEWMMIO_REGBASE_S3 0x1000000 /* 16MB */
86#define SAVAGE_NEWMMIO_REGBASE_S4 0x0000000
87#define SAVAGE_NEWMMIO_REGSIZE 0x0080000 /* 512kb */
88#define SAVAGE_NEWMMIO_VGABASE 0x8000
89
90#define BASE_FREQ 14318
91#define HALF_BASE_FREQ 7159
92
93#define FIFO_CONTROL_REG 0x8200
94#define MIU_CONTROL_REG 0x8204
95#define STREAMS_TIMEOUT_REG 0x8208
96#define MISC_TIMEOUT_REG 0x820c
97
98#define MONO_PAT_0 0xa4e8
99#define MONO_PAT_1 0xa4ec
100
101#define MAXFIFO 0x7f00
102
103#define BCI_CMD_NOP 0x40000000
104#define BCI_CMD_SETREG 0x96000000
105#define BCI_CMD_RECT 0x48000000
106#define BCI_CMD_RECT_XP 0x01000000
107#define BCI_CMD_RECT_YP 0x02000000
108#define BCI_CMD_SEND_COLOR 0x00008000
109#define BCI_CMD_DEST_GBD 0x00000000
110#define BCI_CMD_SRC_GBD 0x00000020
111#define BCI_CMD_SRC_SOLID 0x00000000
112#define BCI_CMD_SRC_MONO 0x00000060
113#define BCI_CMD_CLIP_NEW 0x00006000
114#define BCI_CMD_CLIP_LR 0x00004000
115
116#define BCI_CLIP_LR(l, r) ((((r) << 16) | (l)) & 0x0FFF0FFF)
117#define BCI_CLIP_TL(t, l) ((((t) << 16) | (l)) & 0x0FFF0FFF)
118#define BCI_CLIP_BR(b, r) ((((b) << 16) | (r)) & 0x0FFF0FFF)
119#define BCI_W_H(w, h) (((h) << 16) | ((w) & 0xFFF))
120#define BCI_X_Y(x, y) (((y) << 16) | ((x) & 0xFFF))
121
122#define BCI_GBD1 0xE0
123#define BCI_GBD2 0xE1
124
125#define BCI_BUFFER_OFFSET 0x10000
126#define BCI_SIZE 0x4000
127
128#define BCI_SEND(dw) writel(dw, par->bci_base + par->bci_ptr++)
129
130#define BCI_CMD_GET_ROP(cmd) (((cmd) >> 16) & 0xFF)
131#define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
132#define BCI_CMD_SEND_COLOR 0x00008000
133
Antonino A. Daplas13776712005-09-09 13:04:35 -0700134#define DISP_CRT 1
135#define DISP_LCD 2
136#define DISP_DFP 3
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138struct xtimings {
139 unsigned int Clock;
140 unsigned int HDisplay;
141 unsigned int HSyncStart;
142 unsigned int HSyncEnd;
143 unsigned int HTotal;
144 unsigned int HAdjusted;
145 unsigned int VDisplay;
146 unsigned int VSyncStart;
147 unsigned int VSyncEnd;
148 unsigned int VTotal;
149 unsigned int sync;
150 int dblscan;
151 int interlaced;
152};
153
154
155/* --------------------------------------------------------------------- */
156
157#define NR_PALETTE 256
158
159
160struct savagefb_par;
161
162struct savagefb_i2c_chan {
163 struct savagefb_par *par;
164 struct i2c_adapter adapter;
165 struct i2c_algo_bit_data algo;
166 volatile u8 __iomem *ioaddr;
167 u32 reg;
168};
169
170struct savagefb_par {
171 struct pci_dev *pcidev;
172 savage_chipset chip;
173 struct savagefb_i2c_chan chan;
174 unsigned char *edid;
175 u32 pseudo_palette[16];
Antonino A. Daplas13776712005-09-09 13:04:35 -0700176 int pm_state;
177 int display_type;
178 int dvi;
179 int crtonly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int dacSpeedBpp;
181 int maxClock;
182 int minClock;
183 int numClocks;
184 int clock[4];
185 struct {
186 u8 __iomem *vbase;
187 u32 pbase;
188 u32 len;
189#ifdef CONFIG_MTRR
190 int mtrr;
191#endif
192 } video;
193
194 struct {
195 volatile u8 __iomem *vbase;
196 u32 pbase;
197 u32 len;
198 } mmio;
199
200 volatile u32 __iomem *bci_base;
201 unsigned int bci_ptr;
202
203 u32 cob_offset;
204 u32 cob_size;
205 int cob_index;
206
207 void (*SavageWaitIdle) (struct savagefb_par *par);
208 void (*SavageWaitFifo) (struct savagefb_par *par, int space);
209
210 int MCLK, REFCLK, LCDclk;
211 int HorizScaleFactor;
212
213 /* Panels size */
214 int SavagePanelWidth;
215 int SavagePanelHeight;
216
217 struct {
218 u16 red, green, blue, transp;
219 } palette[NR_PALETTE];
220
221 int depth;
222 int vwidth;
223
224 unsigned char MiscOutReg; /* Misc */
225 unsigned char CRTC[25]; /* Crtc Controller */
226 unsigned char Sequencer[5]; /* Video Sequencer */
227 unsigned char Graphics[9]; /* Video Graphics */
228 unsigned char Attribute[21]; /* Video Atribute */
229
230 unsigned int mode, refresh;
231 unsigned char SR08, SR0E, SR0F;
232 unsigned char SR10, SR11, SR12, SR13, SR15, SR18, SR29, SR30;
233 unsigned char SR54[8];
234 unsigned char Clock;
235 unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
236 unsigned char CR40, CR41, CR42, CR43, CR45;
237 unsigned char CR50, CR51, CR53, CR55, CR58, CR5B, CR5D, CR5E;
238 unsigned char CR60, CR63, CR65, CR66, CR67, CR68, CR69, CR6D, CR6F;
239 unsigned char CR86, CR88;
240 unsigned char CR90, CR91, CRB0;
241 unsigned int STREAMS[22]; /* yuck, streams regs */
242 unsigned int MMPR0, MMPR1, MMPR2, MMPR3;
243};
244
245#define BCI_BD_BW_DISABLE 0x10000000
246#define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
247#define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
248
249
250/* IO functions */
251
252#define vga_in8(addr) (inb (addr))
253#define vga_in16(addr) (inw (addr))
254#define vga_in32(addr) (inl (addr))
255
256#define vga_out8(addr,val) (outb ((val), (addr)))
257#define vga_out16(addr,val) (outw ((val), (addr)))
258#define vga_out32(addr,val) (outl ((val), (addr)))
259
260#define savage_in16(addr) readw(par->mmio.vbase + (addr))
261#define savage_in32(addr) readl(par->mmio.vbase + (addr))
262
263#define savage_out16(addr,val) writew((val), par->mmio.vbase + (addr))
264#define savage_out32(addr,val) writel((val), par->mmio.vbase + (addr))
265
266static inline u8 VGArCR (u8 index)
267{
268 outb (index, 0x3d4);
269 return inb (0x3d5);
270}
271
272static inline u8 VGArGR (u8 index)
273{
274 outb (index, 0x3ce);
275 return inb (0x3cf);
276}
277
278static inline u8 VGArSEQ (u8 index)
279{
280 outb (index, 0x3c4);
281 return inb (0x3c5);
282}
283
284#define VGAwCR(index, val) \
285do { \
286 vga_out8 (0x3d4, index); \
287 vga_out8 (0x3d5, val); \
288} while (0)
289
290#define VGAwGR(index, val) \
291do { \
292 vga_out8 (0x3ce, index); \
293 vga_out8 (0x3cf, val); \
294} while (0)
295
296#define VGAwSEQ(index, val) \
297do { \
298 vga_out8 (0x3c4, index); \
299 vga_out8 (0x3c5, val); \
300} while (0)
301
302#define VGAenablePalette() \
303do { \
304 u8 tmp; \
305 \
306 tmp = vga_in8 (0x3da); \
307 vga_out8 (0x3c0, 0x00); \
308 paletteEnabled = 1; \
309} while (0)
310
311#define VGAdisablePalette() \
312do { \
313 u8 tmp; \
314 \
315 tmp = vga_in8 (0x3da); \
316 vga_out8 (0x3c0, 0x20); \
317 paletteEnabled = 0; \
318} while (0)
319
320#define VGAwATTR(index, value) \
321do { \
322 u8 tmp; \
323 \
324 if (paletteEnabled) \
325 index &= ~0x20; \
326 else \
327 index |= 0x20; \
328 \
329 tmp = vga_in8 (0x3da); \
330 vga_out8 (0x3c0, index); \
331 vga_out8 (0x3c0, value); \
332} while (0)
333
334#define VGAwMISC(value) \
335do { \
336 vga_out8 (0x3c2, value); \
337} while (0)
338
339#ifndef CONFIG_FB_SAVAGE_ACCEL
340#define savagefb_set_clip(x)
341#endif
342
343#define VerticalRetraceWait() \
344{ \
345 vga_out8 (0x3d4, 0x17); \
346 if (vga_in8 (0x3d5) & 0x80) { \
347 while ((vga_in8(0x3da) & 0x08) == 0x08) ; \
348 while ((vga_in8(0x3da) & 0x08) == 0x00) ; \
349 } \
350}
351
Antonino A. Daplas13776712005-09-09 13:04:35 -0700352extern int savagefb_probe_i2c_connector(struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 u8 **out_edid);
354extern void savagefb_create_i2c_busses(struct fb_info *info);
355extern void savagefb_delete_i2c_busses(struct fb_info *info);
356extern int savagefb_sync(struct fb_info *info);
357extern void savagefb_copyarea(struct fb_info *info,
358 const struct fb_copyarea *region);
359extern void savagefb_fillrect(struct fb_info *info,
360 const struct fb_fillrect *rect);
361extern void savagefb_imageblit(struct fb_info *info,
362 const struct fb_image *image);
363
364
365#endif /* __SAVAGEFB_H__ */