3325fbd68ab3b235a9ec370e59cd96314b414359
[safe/jmp/linux-2.6] / drivers / video / intelfb / intelfb.h
1 #ifndef _INTELFB_H
2 #define _INTELFB_H
3
4 /* $DHD: intelfb/intelfb.h,v 1.40 2003/06/27 15:06:25 dawes Exp $ */
5
6 #include <linux/agp_backend.h>
7 #include <linux/fb.h>
8
9 #ifdef CONFIG_FB_INTEL_I2C
10 #include <linux/i2c.h>
11 #include <linux/i2c-algo-bit.h>
12 #endif
13
14 /*** Version/name ***/
15 #define INTELFB_VERSION                 "0.9.5"
16 #define INTELFB_MODULE_NAME             "intelfb"
17 #define SUPPORTED_CHIPSETS              "830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM/965G/965GM"
18
19
20 /*** Debug/feature defines ***/
21
22 #ifndef DEBUG
23 #define DEBUG                           0
24 #endif
25
26 #ifndef VERBOSE
27 #define VERBOSE                         0
28 #endif
29
30 #ifndef REGDUMP
31 #define REGDUMP                         0
32 #endif
33
34 #ifndef DETECT_VGA_CLASS_ONLY
35 #define DETECT_VGA_CLASS_ONLY           1
36 #endif
37
38 #ifndef ALLOCATE_FOR_PANNING
39 #define ALLOCATE_FOR_PANNING            1
40 #endif
41
42 #ifndef PREFERRED_MODE
43 #define PREFERRED_MODE                  "1024x768-32@70"
44 #endif
45
46 /*** hw-related values ***/
47
48 /* Resource Allocation */
49 #define INTELFB_FB_ACQUIRED                 1
50 #define INTELFB_MMIO_ACQUIRED               2
51
52 /* PCI ids for supported devices */
53 #define PCI_DEVICE_ID_INTEL_830M        0x3577
54 #define PCI_DEVICE_ID_INTEL_845G        0x2562
55 #define PCI_DEVICE_ID_INTEL_85XGM       0x3582
56 #define PCI_DEVICE_ID_INTEL_865G        0x2572
57 #define PCI_DEVICE_ID_INTEL_915G        0x2582
58 #define PCI_DEVICE_ID_INTEL_915GM       0x2592
59 #define PCI_DEVICE_ID_INTEL_945G        0x2772
60 #define PCI_DEVICE_ID_INTEL_945GM       0x27A2
61 #define PCI_DEVICE_ID_INTEL_965G        0x29A2
62 #define PCI_DEVICE_ID_INTEL_965GM       0x2A02
63
64 /* Size of MMIO region */
65 #define INTEL_REG_SIZE                  0x80000
66
67 #define STRIDE_ALIGNMENT                16
68 #define STRIDE_ALIGNMENT_I9XX           64
69
70 #define PALETTE_8_ENTRIES               256
71
72
73 /*** Macros ***/
74
75 /* basic arithmetic */
76 #define KB(x)                   ((x) * 1024)
77 #define MB(x)                   ((x) * 1024 * 1024)
78 #define BtoKB(x)                ((x) / 1024)
79 #define BtoMB(x)                ((x) / 1024 / 1024)
80
81 #define GTT_PAGE_SIZE           KB(4)
82
83 #define ROUND_UP_TO(x, y)       (((x) + (y) - 1) / (y) * (y))
84 #define ROUND_DOWN_TO(x, y)     ((x) / (y) * (y))
85 #define ROUND_UP_TO_PAGE(x)     ROUND_UP_TO((x), GTT_PAGE_SIZE)
86 #define ROUND_DOWN_TO_PAGE(x)   ROUND_DOWN_TO((x), GTT_PAGE_SIZE)
87
88 /* messages */
89 #define PFX                     INTELFB_MODULE_NAME ": "
90
91 #define ERR_MSG(fmt, args...)   printk(KERN_ERR PFX fmt, ## args)
92 #define WRN_MSG(fmt, args...)   printk(KERN_WARNING PFX fmt, ## args)
93 #define NOT_MSG(fmt, args...)   printk(KERN_NOTICE PFX fmt, ## args)
94 #define INF_MSG(fmt, args...)   printk(KERN_INFO PFX fmt, ## args)
95 #if DEBUG
96 #define DBG_MSG(fmt, args...)   printk(KERN_DEBUG PFX fmt, ## args)
97 #else
98 #define DBG_MSG(fmt, args...)   while (0) printk(fmt, ## args)
99 #endif
100
101 /* get commonly used pointers */
102 #define GET_DINFO(info)         (info)->par
103
104 /* misc macros */
105 #define ACCEL(d, i)                                                     \
106         ((d)->accel && !(d)->ring_lockup &&                             \
107          ((i)->var.accel_flags & FB_ACCELF_TEXT))
108
109 /*#define NOACCEL_CHIPSET(d)                                            \
110         ((d)->chipset != INTEL_865G)*/
111 #define NOACCEL_CHIPSET(d)                                              \
112         (0)
113
114 #define FIXED_MODE(d) ((d)->fixed_mode)
115
116 /*** Driver parameters ***/
117
118 #define RINGBUFFER_SIZE         KB(64)
119 #define HW_CURSOR_SIZE          KB(4)
120
121 /* Intel agpgart driver */
122 #define AGP_PHYSICAL_MEMORY     2
123
124 /* store information about an Ixxx DVO */
125 /* The i830->i865 use multiple DVOs with multiple i2cs */
126 /* the i915, i945 have a single sDVO i2c bus - which is different */
127 #define MAX_OUTPUTS 6
128
129 /* these are outputs from the chip - integrated only
130    external chips are via DVO or SDVO output */
131 #define INTELFB_OUTPUT_UNUSED 0
132 #define INTELFB_OUTPUT_ANALOG 1
133 #define INTELFB_OUTPUT_DVO 2
134 #define INTELFB_OUTPUT_SDVO 3
135 #define INTELFB_OUTPUT_LVDS 4
136 #define INTELFB_OUTPUT_TVOUT 5
137
138 #define INTELFB_DVO_CHIP_NONE 0
139 #define INTELFB_DVO_CHIP_LVDS 1
140 #define INTELFB_DVO_CHIP_TMDS 2
141 #define INTELFB_DVO_CHIP_TVOUT 4
142
143 #define INTELFB_OUTPUT_PIPE_NC  0
144 #define INTELFB_OUTPUT_PIPE_A   1
145 #define INTELFB_OUTPUT_PIPE_B   2
146
147 /*** Data Types ***/
148
149 /* supported chipsets */
150 enum intel_chips {
151         INTEL_830M,
152         INTEL_845G,
153         INTEL_85XGM,
154         INTEL_852GM,
155         INTEL_852GME,
156         INTEL_855GM,
157         INTEL_855GME,
158         INTEL_865G,
159         INTEL_915G,
160         INTEL_915GM,
161         INTEL_945G,
162         INTEL_945GM,
163         INTEL_965G,
164         INTEL_965GM,
165 };
166
167 struct intelfb_hwstate {
168         u32 vga0_divisor;
169         u32 vga1_divisor;
170         u32 vga_pd;
171         u32 dpll_a;
172         u32 dpll_b;
173         u32 fpa0;
174         u32 fpa1;
175         u32 fpb0;
176         u32 fpb1;
177         u32 palette_a[PALETTE_8_ENTRIES];
178         u32 palette_b[PALETTE_8_ENTRIES];
179         u32 htotal_a;
180         u32 hblank_a;
181         u32 hsync_a;
182         u32 vtotal_a;
183         u32 vblank_a;
184         u32 vsync_a;
185         u32 src_size_a;
186         u32 bclrpat_a;
187         u32 htotal_b;
188         u32 hblank_b;
189         u32 hsync_b;
190         u32 vtotal_b;
191         u32 vblank_b;
192         u32 vsync_b;
193         u32 src_size_b;
194         u32 bclrpat_b;
195         u32 adpa;
196         u32 dvoa;
197         u32 dvob;
198         u32 dvoc;
199         u32 dvoa_srcdim;
200         u32 dvob_srcdim;
201         u32 dvoc_srcdim;
202         u32 lvds;
203         u32 pipe_a_conf;
204         u32 pipe_b_conf;
205         u32 disp_arb;
206         u32 cursor_a_control;
207         u32 cursor_b_control;
208         u32 cursor_a_base;
209         u32 cursor_b_base;
210         u32 cursor_size;
211         u32 disp_a_ctrl;
212         u32 disp_b_ctrl;
213         u32 disp_a_base;
214         u32 disp_b_base;
215         u32 cursor_a_palette[4];
216         u32 cursor_b_palette[4];
217         u32 disp_a_stride;
218         u32 disp_b_stride;
219         u32 vgacntrl;
220         u32 add_id;
221         u32 swf0x[7];
222         u32 swf1x[7];
223         u32 swf3x[3];
224         u32 fence[8];
225         u32 instpm;
226         u32 mem_mode;
227         u32 fw_blc_0;
228         u32 fw_blc_1;
229         u16 hwstam;
230         u16 ier;
231         u16 iir;
232         u16 imr;
233 };
234
235 struct intelfb_heap_data {
236         u32 physical;
237         u8 __iomem *virtual;
238         u32 offset;             /* in GATT pages */
239         u32 size;               /* in bytes */
240 };
241
242 #ifdef CONFIG_FB_INTEL_I2C
243 struct intelfb_i2c_chan {
244     struct intelfb_info *dinfo;
245     u32 reg;
246     struct i2c_adapter adapter;
247     struct i2c_algo_bit_data algo;
248 };
249 #endif
250
251 struct intelfb_output_rec {
252     int type;
253     int pipe;
254     int flags;
255
256 #ifdef CONFIG_FB_INTEL_I2C
257     struct intelfb_i2c_chan i2c_bus;
258     struct intelfb_i2c_chan ddc_bus;
259 #endif
260 };
261
262 struct intelfb_vsync {
263         wait_queue_head_t wait;
264         unsigned int count;
265         int pan_display;
266         u32 pan_offset;
267 };
268
269 struct intelfb_info {
270         struct fb_info *info;
271         struct fb_ops  *fbops;
272         struct pci_dev *pdev;
273
274         struct intelfb_hwstate save_state;
275
276         /* agpgart structs */
277         struct agp_memory *gtt_fb_mem;     /* use all stolen memory or vram */
278         struct agp_memory *gtt_ring_mem;   /* ring buffer */
279         struct agp_memory *gtt_cursor_mem; /* hw cursor */
280
281         /* use a gart reserved fb mem */
282         u8 fbmem_gart;
283
284         /* mtrr support */
285         int mtrr_reg;
286         u32 has_mtrr;
287
288         /* heap data */
289         struct intelfb_heap_data aperture;
290         struct intelfb_heap_data fb;
291         struct intelfb_heap_data ring;
292         struct intelfb_heap_data cursor;
293
294         /* mmio regs */
295         u32 mmio_base_phys;
296         u8 __iomem *mmio_base;
297
298         /* fb start offset (in bytes) */
299         u32 fb_start;
300
301         /* ring buffer */
302         u32 ring_head;
303         u32 ring_tail;
304         u32 ring_tail_mask;
305         u32 ring_space;
306         u32 ring_lockup;
307
308         /* palette */
309         u32 pseudo_palette[16];
310
311         /* chip info */
312         int pci_chipset;
313         int chipset;
314         const char *name;
315         int mobile;
316
317         /* current mode */
318         int bpp, depth;
319         u32 visual;
320         int xres, yres, pitch;
321         int pixclock;
322
323         /* current pipe */
324         int pipe;
325
326         /* some flags */
327         int accel;
328         int hwcursor;
329         int fixed_mode;
330         int ring_active;
331         int flag;
332         unsigned long irq_flags;
333         int open;
334
335         /* vsync */
336         struct intelfb_vsync vsync;
337         spinlock_t int_lock;
338
339         /* hw cursor */
340         int cursor_on;
341         int cursor_blanked;
342         u8  cursor_src[64];
343
344         /* initial parameters */
345         int initial_vga;
346         struct fb_var_screeninfo initial_var;
347         u32 initial_fb_base;
348         u32 initial_video_ram;
349         u32 initial_pitch;
350
351         /* driver registered */
352         int registered;
353
354         /* index into plls */
355         int pll_index;
356
357         /* outputs */
358         int num_outputs;
359         struct intelfb_output_rec output[MAX_OUTPUTS];
360 };
361
362 #define IS_I9XX(dinfo) (((dinfo)->chipset == INTEL_915G) ||     \
363                         ((dinfo)->chipset == INTEL_915GM) ||    \
364                         ((dinfo)->chipset == INTEL_945G) ||     \
365                         ((dinfo)->chipset == INTEL_945GM) ||    \
366                         ((dinfo)->chipset == INTEL_965G) ||     \
367                         ((dinfo)->chipset == INTEL_965GM))
368
369 #ifndef FBIO_WAITFORVSYNC
370 #define FBIO_WAITFORVSYNC       _IOW('F', 0x20, __u32)
371 #endif
372
373 /*** function prototypes ***/
374
375 extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var);
376
377 #ifdef CONFIG_FB_INTEL_I2C
378 extern void intelfb_create_i2c_busses(struct intelfb_info *dinfo);
379 extern void intelfb_delete_i2c_busses(struct intelfb_info *dinfo);
380 #endif
381
382 #endif /* _INTELFB_H */