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