3d9a8c5aa1cef822935ad9a1a0ca2faf8643ba88
[coreboot.git] / src / drivers / ati / ragexl / atyfb.h
1 /*
2  *  ATI Frame Buffer Device Driver Core Definitions
3  */
4         
5 #define PLL_CRTC_DECODE 0
6
7 #define EINVAL -1
8
9 #define max(x,y) (x>=y)?x:y
10
11 #if CONFIG_CONSOLE_BTEXT==1
12     /*
13      *  Elements of the hardware specific atyfb_par structure
14      */
15 struct crtc {
16     u32 vxres;
17     u32 vyres;
18     u32 xoffset;
19     u32 yoffset;
20     u32 bpp;
21     u32 h_tot_disp;
22     u32 h_sync_strt_wid;
23     u32 v_tot_disp;
24     u32 v_sync_strt_wid;
25     u32 off_pitch;
26     u32 gen_cntl;
27     u32 dp_pix_width;   /* acceleration */
28     u32 dp_chain_mask;  /* acceleration */
29 };
30 #endif /* CONFIG_CONSOLE_BTEXT */
31 #if 0
32 struct pll_514 {
33     u8 m;
34     u8 n;
35 };
36
37 struct pll_18818
38 {
39     u32 program_bits;
40     u32 locationAddr;
41     u32 period_in_ps;
42     u32 post_divider;
43 };
44 #endif
45 struct pll_ct {
46     u8 pll_ref_div;
47     u8 pll_gen_cntl;
48     u8 mclk_fb_div;
49     u8 mclk_fb_mult;    /* 2 or 4 */
50     u8 sclk_fb_div;
51     u8 pll_vclk_cntl;
52     u8 vclk_post_div;
53     u8 vclk_fb_div;
54     u8 pll_ext_cntl;
55     u8 spll_cntl2;
56     u32 dsp_config;     /* Mach64 GTB DSP */
57     u32 dsp_on_off;     /* Mach64 GTB DSP */
58     u8 mclk_post_div_real;
59     u8 xclk_post_div_real;
60     u8 vclk_post_div_real;
61 };
62
63 union aty_pll {
64     struct pll_ct ct;
65 #if 0
66     struct pll_514 ibm514;
67     struct pll_18818 ics2595;
68 #endif
69 };
70
71
72     /*
73      *  The hardware parameters for each card
74      */
75 struct atyfb_par {
76 #if CONFIG_CONSOLE_BTEXT==1
77     struct crtc crtc;
78 #endif
79     union aty_pll pll;
80     u32 accel_flags;
81 };
82 #if 0
83 struct aty_cursor {
84     int enable;
85     int on;
86     int vbl_cnt;
87     int blink_rate;
88     u32 offset;
89     struct {
90         u16 x, y;
91     } pos, hot, size;
92     u32 color[2];
93     u8 bits[8][64];
94     u8 mask[8][64];
95     u8 *ram;
96     struct timer_list *timer;
97 };
98 #endif
99 struct fb_info_aty {
100 #if CONFIG_CONSOLE_BTEXT==1
101 #if PLL_CRTC_DECODE==1
102     struct fb_info fb_info;
103 #endif
104 #endif
105 #if 0
106     struct fb_info_aty *next;
107     unsigned long ati_regbase_phys;
108 #endif
109     unsigned long ati_regbase;
110 #if 0
111     unsigned long frame_buffer_phys;
112 #endif
113     unsigned long frame_buffer;
114     unsigned long clk_wr_offset;
115 #if 0
116     struct pci_mmap_map *mmap_map;
117     struct aty_cursor *cursor;
118 #endif
119     struct aty_cmap_regs *aty_cmap_regs;
120 #if 0
121     struct { u8 red, green, blue, pad; } palette[256];
122 #endif
123     struct atyfb_par default_par;
124 #if PLL_CRTC_DECODE==1
125     struct atyfb_par current_par;
126 #endif
127
128     u32 features;
129     u32 total_vram;
130     u32 ref_clk_per;
131     u32 pll_per;
132     u32 mclk_per;
133     u32 xclk_per;
134     u8 bus_type;
135     u8 ram_type;
136     u8 mem_refresh_rate;
137 #if 0
138     struct aty_dac_ops *dac_ops;
139     struct aty_pll_ops *pll_ops;
140     struct display disp;
141     struct display_switch dispsw;
142 #endif
143
144 #if 0
145     union {
146 #ifdef FBCON_HAS_CFB16
147         u16 cfb16[16];
148 #endif
149 #ifdef FBCON_HAS_CFB24
150         u32 cfb24[16];
151 #endif
152 #ifdef FBCON_HAS_CFB32
153         u32 cfb32[16];
154 #endif
155     } fbcon_cmap;
156 #endif
157     u8 blitter_may_be_busy;
158 #if 0
159 #ifdef __sparc__
160     u8 mmaped;
161     int open;
162     int vtconsole;
163     int consolecnt;
164 #endif
165 #ifdef CONFIG_PMAC_PBOOK
166     unsigned char *save_framebuffer;
167     unsigned long save_pll[64];
168 #endif
169 #endif
170 };
171
172
173     /*
174      *  ATI Mach64 features
175      */
176
177 #define M64_HAS(feature)        ((info)->features & (M64F_##feature))
178
179 #define M64F_RESET_3D           0x00000001
180 #define M64F_MAGIC_FIFO         0x00000002
181 #define M64F_GTB_DSP            0x00000004
182 #define M64F_FIFO_24            0x00000008
183 #define M64F_SDRAM_MAGIC_PLL    0x00000010
184 #define M64F_MAGIC_POSTDIV      0x00000020
185 #define M64F_INTEGRATED         0x00000040
186 #define M64F_CT_BUS             0x00000080
187 #define M64F_VT_BUS             0x00000100
188 #define M64F_MOBIL_BUS          0x00000200
189 #define M64F_GX                 0x00000400
190 #define M64F_CT                 0x00000800
191 #define M64F_VT                 0x00001000
192 #define M64F_GT                 0x00002000
193 #define M64F_MAGIC_VRAM_SIZE    0x00004000
194 #define M64F_G3_PB_1_1          0x00008000
195 #define M64F_G3_PB_1024x768     0x00010000
196 #define M64F_EXTRA_BRIGHT       0x00020000
197 #define M64F_LT_SLEEP           0x00040000
198 #define M64F_XL_DLL             0x00080000
199 #define M64F_MFB_TIMES_4        0x00100000
200
201
202     /*
203      *  Register access
204      */
205
206 static inline u32 aty_ld_le32(int regindex,
207                               const struct fb_info_aty *info)
208 {
209     /* Hack for bloc 1, should be cleanly optimized by compiler */
210     if (regindex >= 0x400)
211         regindex -= 0x800;
212
213 #ifdef ATARI
214     return in_le32((volatile u32 *)(info->ati_regbase+regindex));
215 #else
216     return read32 (info->ati_regbase + regindex);
217 #endif
218 }
219
220 static inline void aty_st_le32(int regindex, u32 val,
221                                const struct fb_info_aty *info)
222 {
223     /* Hack for bloc 1, should be cleanly optimized by compiler */
224     if (regindex >= 0x400)
225         regindex -= 0x800;
226
227 #ifdef ATARI
228     out_le32 (info->ati_regbase+regindex, val);
229 #else
230     write32 (info->ati_regbase + regindex, val);
231 #endif
232 }
233
234 static inline u16 aty_ld_le16(int regindex,
235                               const struct fb_info_aty *info)
236 {
237     /* Hack for bloc 1, should be cleanly optimized by compiler */
238     if (regindex >= 0x400)
239         regindex -= 0x800;
240
241 #if defined(__mc68000__)
242     return le16_to_cpu(*((volatile u16 *)(info->ati_regbase+regindex)));
243 #else
244     return read16 (info->ati_regbase + regindex);
245 #endif
246 }
247
248 static inline void aty_st_le16(int regindex, u16 val,
249                                const struct fb_info_aty *info)
250 {
251     /* Hack for bloc 1, should be cleanly optimized by compiler */
252     if (regindex >= 0x400)
253         regindex -= 0x800;
254
255 #if defined(__mc68000__)
256     *((volatile u16 *)(info->ati_regbase+regindex)) = cpu_to_le16(val);
257 #else
258     write16 (info->ati_regbase + regindex, val);
259 #endif
260 }
261
262 static inline u8 aty_ld_8(int regindex,
263                           const struct fb_info_aty *info)
264 {
265     /* Hack for bloc 1, should be cleanly optimized by compiler */
266     if (regindex >= 0x400)
267         regindex -= 0x800;
268
269 #ifdef ATARI
270     return in_8 (info->ati_regbase + regindex);
271 #else
272     return read8 (info->ati_regbase + regindex);
273 #endif
274 }
275
276 static inline void aty_st_8(int regindex, u8 val,
277                             const struct fb_info_aty *info)
278 {
279     /* Hack for bloc 1, should be cleanly optimized by compiler */
280     if (regindex >= 0x400)
281         regindex -= 0x800;
282
283 #ifdef ATARI
284     out_8 (info->ati_regbase + regindex, val);
285 #else
286     write8 (info->ati_regbase + regindex, val);
287 #endif
288 }
289
290 static inline u8 aty_ld_pll(int offset, const struct fb_info_aty *info)
291 {
292     u8 res;
293
294     /* write addr byte */
295     aty_st_8(CLOCK_CNTL + 1, (offset << 2), info);
296     /* read the register value */
297     res = aty_ld_8(CLOCK_CNTL + 2, info);
298     return res;
299 }
300
301 /*
302  * CT family only.
303  */
304 static inline void aty_st_pll(int offset, u8 val,
305                               const struct fb_info_aty *info)
306 {
307     /* write addr byte */
308     aty_st_8(CLOCK_CNTL + 1, (offset << 2) | PLL_WR_EN, info);
309     /* write the register value */
310     aty_st_8(CLOCK_CNTL + 2, val, info);
311     aty_st_8(CLOCK_CNTL + 1, (offset << 2) & ~PLL_WR_EN, info);
312 }
313
314
315     /*
316      *  DAC operations
317      */
318
319 #if 0
320
321 struct aty_dac_ops {
322     int (*set_dac)(const struct fb_info_aty *info, const union aty_pll *pll,
323                    u32 bpp, u32 accel);
324 };
325 extern const struct aty_dac_ops aty_dac_ibm514;         /* IBM RGB514 */
326 extern const struct aty_dac_ops aty_dac_ati68860b;      /* ATI 68860-B */
327 extern const struct aty_dac_ops aty_dac_att21c498;      /* AT&T 21C498 */
328 extern const struct aty_dac_ops aty_dac_unsupported;    /* unsupported */
329 static  struct aty_dac_ops aty_dac_ct;          /* Integrated */
330
331 #endif
332
333     /*
334      *  Clock operations
335      */
336
337 #if 0
338 struct aty_pll_ops {
339     int (*var_to_pll)(const struct fb_info_aty *info, u32 vclk_per, u8 bpp,
340                       union aty_pll *pll);
341 #if 0
342     u32 (*pll_to_var)(const struct fb_info_aty *info,
343                       const union aty_pll *pll);
344     void (*set_pll)(const struct fb_info_aty *info, const union aty_pll *pll);
345 #endif
346 };
347
348 #endif
349
350 #if 0
351 extern const struct aty_pll_ops aty_pll_ati18818_1;     /* ATI 18818 */
352 extern const struct aty_pll_ops aty_pll_stg1703;        /* STG 1703 */
353 extern const struct aty_pll_ops aty_pll_ch8398;         /* Chrontel 8398 */
354 extern const struct aty_pll_ops aty_pll_att20c408;      /* AT&T 20C408 */
355 extern const struct aty_pll_ops aty_pll_ibm514;         /* IBM RGB514 */
356 extern const struct aty_pll_ops aty_pll_unsupported;    /* unsupported */
357 #endif
358 #if 0
359 static struct aty_pll_ops aty_pll_ct;           /* Integrated */
360
361 static void aty_set_pll_ct(const struct fb_info_aty *info,
362                            const union aty_pll *pll);
363
364 static void aty_calc_pll_ct(const struct fb_info_aty *info,
365                             struct pll_ct *pll);
366 #endif
367 #if 0
368     /*
369      *  Hardware cursor support
370      */
371 extern struct aty_cursor *aty_init_cursor(struct fb_info_aty *fb);
372 extern void atyfb_cursor(struct display *p, int mode, int x, int y);
373 extern void aty_set_cursor_color(struct fb_info_aty *fb);
374 extern void aty_set_cursor_shape(struct fb_info_aty *fb);
375 extern int atyfb_set_font(struct display *d, int width, int height);
376 #endif
377     /*
378      *  Hardware acceleration
379      */
380
381 static inline void wait_for_fifo(u16 entries, const struct fb_info_aty *info)
382 {
383     while ((aty_ld_le32(FIFO_STAT, info) & 0xffff) >
384            ((u32)(0x8000 >> entries)));
385 }
386
387 static inline void wait_for_idle(struct fb_info_aty *info)
388 {
389     wait_for_fifo(16, info);
390     while ((aty_ld_le32(GUI_STAT, info) & 1)!= 0);
391     info->blitter_may_be_busy = 0;
392 }
393 #if 0
394 extern void aty_reset_engine(const struct fb_info_aty *info);
395 extern void aty_init_engine(const struct atyfb_par *par,
396                             struct fb_info_aty *info);
397 extern void aty_rectfill(int dstx, int dsty, u32 width, u32 height,
398                          u32 color, struct fb_info_aty *info);
399
400
401     /*
402      *  Text console acceleration
403      */
404
405 extern const struct display_switch fbcon_aty8;
406 extern const struct display_switch fbcon_aty16;
407 extern const struct display_switch fbcon_aty24;
408 extern const struct display_switch fbcon_aty32;
409 #endif