ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / aty / atyfb.h
1 /*
2  *  ATI Frame Buffer Device Driver Core Definitions
3  */
4
5 #include <linux/config.h>
6     /*
7      *  Elements of the hardware specific atyfb_par structure
8      */
9
10 struct crtc {
11         u32 vxres;
12         u32 vyres;
13         u32 h_tot_disp;
14         u32 h_sync_strt_wid;
15         u32 v_tot_disp;
16         u32 v_sync_strt_wid;
17         u32 off_pitch;
18         u32 gen_cntl;
19         u32 dp_pix_width;       /* acceleration */
20         u32 dp_chain_mask;      /* acceleration */
21 };
22
23 struct pll_514 {
24         u8 m;
25         u8 n;
26 };
27
28 struct pll_18818 {
29         u32 program_bits;
30         u32 locationAddr;
31         u32 period_in_ps;
32         u32 post_divider;
33 };
34
35 struct pll_ct {
36         u8 pll_ref_div;
37         u8 pll_gen_cntl;
38         u8 mclk_fb_div;
39         u8 pll_vclk_cntl;
40         u8 vclk_post_div;
41         u8 vclk_fb_div;
42         u8 pll_ext_cntl;
43         u32 dsp_config;         /* Mach64 GTB DSP */
44         u32 dsp_on_off;         /* Mach64 GTB DSP */
45         u8 mclk_post_div_real;
46         u8 vclk_post_div_real;
47 };
48
49 union aty_pll {
50         struct pll_ct ct;
51         struct pll_514 ibm514;
52         struct pll_18818 ics2595;
53 };
54
55     /*
56      *  The hardware parameters for each card
57      */
58
59 struct aty_cursor {
60         u8 bits[8][64];
61         u8 mask[8][64];
62         u8 *ram;
63 };
64
65 struct atyfb_par {
66         struct aty_cmap_regs *aty_cmap_regs;
67         const struct aty_dac_ops *dac_ops;
68         const struct aty_pll_ops *pll_ops;
69         struct aty_cursor *cursor;
70         unsigned long ati_regbase;
71         unsigned long clk_wr_offset;
72         struct crtc crtc;
73         union aty_pll pll;
74         u32 features;
75         u32 ref_clk_per;
76         u32 pll_per;
77         u32 mclk_per;
78         u8 bus_type;
79         u8 ram_type;
80         u8 mem_refresh_rate;
81         u8 blitter_may_be_busy;
82         u32 accel_flags;
83 #ifdef __sparc__
84         struct pci_mmap_map *mmap_map;
85         u8 mmaped;
86         int open;
87 #endif
88 #ifdef CONFIG_PMAC_PBOOK
89         struct fb_info *next;
90         unsigned char *save_framebuffer;
91         unsigned long save_pll[64];
92 #endif
93 };
94     
95     /*
96      *  ATI Mach64 features
97      */
98
99 #define M64_HAS(feature)        ((par)->features & (M64F_##feature))
100
101 #define M64F_RESET_3D           0x00000001
102 #define M64F_MAGIC_FIFO         0x00000002
103 #define M64F_GTB_DSP            0x00000004
104 #define M64F_FIFO_24            0x00000008
105 #define M64F_SDRAM_MAGIC_PLL    0x00000010
106 #define M64F_MAGIC_POSTDIV      0x00000020
107 #define M64F_INTEGRATED         0x00000040
108 #define M64F_CT_BUS             0x00000080
109 #define M64F_VT_BUS             0x00000100
110 #define M64F_MOBIL_BUS          0x00000200
111 #define M64F_GX                 0x00000400
112 #define M64F_CT                 0x00000800
113 #define M64F_VT                 0x00001000
114 #define M64F_GT                 0x00002000
115 #define M64F_MAGIC_VRAM_SIZE    0x00004000
116 #define M64F_G3_PB_1_1          0x00008000
117 #define M64F_G3_PB_1024x768     0x00010000
118 #define M64F_EXTRA_BRIGHT       0x00020000
119 #define M64F_LT_SLEEP           0x00040000
120 #define M64F_XL_DLL             0x00080000
121
122
123     /*
124      *  Register access
125      */
126
127 static inline u32 aty_ld_le32(int regindex, const struct atyfb_par *par)
128 {
129         /* Hack for bloc 1, should be cleanly optimized by compiler */
130         if (regindex >= 0x400)
131                 regindex -= 0x800;
132
133 #ifdef CONFIG_ATARI
134         return in_le32((volatile u32 *)(par->ati_regbase + regindex));
135 #else
136         return readl(par->ati_regbase + regindex);
137 #endif
138 }
139
140 static inline void aty_st_le32(int regindex, u32 val,
141                                const struct atyfb_par *par)
142 {
143         /* Hack for bloc 1, should be cleanly optimized by compiler */
144         if (regindex >= 0x400)
145                 regindex -= 0x800;
146
147 #ifdef CONFIG_ATARI
148         out_le32((volatile u32 *)(par->ati_regbase + regindex), val);
149 #else
150         writel(val, par->ati_regbase + regindex);
151 #endif
152 }
153
154 static inline u8 aty_ld_8(int regindex, const struct atyfb_par *par)
155 {
156         /* Hack for bloc 1, should be cleanly optimized by compiler */
157         if (regindex >= 0x400)
158                 regindex -= 0x800;
159 #ifdef CONFIG_ATARI
160         return in_8(par->ati_regbase + regindex);
161 #else
162         return readb(par->ati_regbase + regindex);
163 #endif
164 }
165
166 static inline void aty_st_8(int regindex, u8 val,
167                             const struct atyfb_par *par)
168 {
169         /* Hack for bloc 1, should be cleanly optimized by compiler */
170         if (regindex >= 0x400)
171                 regindex -= 0x800;
172
173 #ifdef CONFIG_ATARI
174         out_8(par->ati_regbase + regindex, val);
175 #else
176         writeb(val, par->ati_regbase + regindex);
177 #endif
178 }
179
180 static inline u8 aty_ld_pll(int offset, const struct atyfb_par *par)
181 {
182         u8 res;
183
184         /* write addr byte */
185         aty_st_8(CLOCK_CNTL + 1, (offset << 2), par);
186         /* read the register value */
187         res = aty_ld_8(CLOCK_CNTL + 2, par);
188         return res;
189 }
190
191
192     /*
193      *  DAC operations
194      */
195
196 struct aty_dac_ops {
197         int (*set_dac) (const struct fb_info * info,
198                         const union aty_pll * pll, u32 bpp, u32 accel);
199 };
200
201 extern const struct aty_dac_ops aty_dac_ibm514; /* IBM RGB514 */
202 extern const struct aty_dac_ops aty_dac_ati68860b;      /* ATI 68860-B */
203 extern const struct aty_dac_ops aty_dac_att21c498;      /* AT&T 21C498 */
204 extern const struct aty_dac_ops aty_dac_unsupported;    /* unsupported */
205 extern const struct aty_dac_ops aty_dac_ct;     /* Integrated */
206
207
208     /*
209      *  Clock operations
210      */
211
212 struct aty_pll_ops {
213         int (*var_to_pll) (const struct fb_info * info, u32 vclk_per,
214                            u8 bpp, union aty_pll * pll);
215          u32(*pll_to_var) (const struct fb_info * info,
216                            const union aty_pll * pll);
217         void (*set_pll) (const struct fb_info * info,
218                          const union aty_pll * pll);
219 };
220
221 extern const struct aty_pll_ops aty_pll_ati18818_1;     /* ATI 18818 */
222 extern const struct aty_pll_ops aty_pll_stg1703;        /* STG 1703 */
223 extern const struct aty_pll_ops aty_pll_ch8398; /* Chrontel 8398 */
224 extern const struct aty_pll_ops aty_pll_att20c408;      /* AT&T 20C408 */
225 extern const struct aty_pll_ops aty_pll_ibm514; /* IBM RGB514 */
226 extern const struct aty_pll_ops aty_pll_unsupported;    /* unsupported */
227 extern const struct aty_pll_ops aty_pll_ct;     /* Integrated */
228
229
230 extern void aty_set_pll_ct(const struct fb_info *info,
231                            const union aty_pll *pll);
232 extern void aty_calc_pll_ct(const struct fb_info *info,
233                             struct pll_ct *pll);
234
235
236     /*
237      *  Hardware cursor support
238      */
239
240 extern struct aty_cursor *aty_init_cursor(struct fb_info *info);
241 extern int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor);
242 extern void aty_set_cursor_color(struct fb_info *info);
243 extern void aty_set_cursor_shape(struct fb_info *info);
244
245     /*
246      *  Hardware acceleration
247      */
248
249 static inline void wait_for_fifo(u16 entries, const struct atyfb_par *par)
250 {
251         while ((aty_ld_le32(FIFO_STAT, par) & 0xffff) >
252                ((u32) (0x8000 >> entries)));
253 }
254
255 static inline void wait_for_idle(struct atyfb_par *par)
256 {
257         wait_for_fifo(16, par);
258         while ((aty_ld_le32(GUI_STAT, par) & 1) != 0);
259         par->blitter_may_be_busy = 0;
260 }
261
262 extern void aty_reset_engine(const struct atyfb_par *par);
263 extern void aty_init_engine(struct atyfb_par *par,
264                             struct fb_info *info);
265