atyfb.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * ATI Frame Buffer Device Driver Core Definitions
  3. */
  4. #include <linux/config.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/wait.h>
  7. /*
  8. * Elements of the hardware specific atyfb_par structure
  9. */
  10. struct crtc {
  11. u32 vxres;
  12. u32 vyres;
  13. u32 xoffset;
  14. u32 yoffset;
  15. u32 bpp;
  16. u32 h_tot_disp;
  17. u32 h_sync_strt_wid;
  18. u32 v_tot_disp;
  19. u32 v_sync_strt_wid;
  20. u32 vline_crnt_vline;
  21. u32 off_pitch;
  22. u32 gen_cntl;
  23. u32 dp_pix_width; /* acceleration */
  24. u32 dp_chain_mask; /* acceleration */
  25. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  26. u32 horz_stretching;
  27. u32 vert_stretching;
  28. u32 ext_vert_stretch;
  29. u32 shadow_h_tot_disp;
  30. u32 shadow_h_sync_strt_wid;
  31. u32 shadow_v_tot_disp;
  32. u32 shadow_v_sync_strt_wid;
  33. u32 lcd_gen_cntl;
  34. u32 lcd_config_panel;
  35. u32 lcd_index;
  36. #endif
  37. };
  38. struct aty_interrupt {
  39. wait_queue_head_t wait;
  40. unsigned int count;
  41. int pan_display;
  42. };
  43. struct pll_info {
  44. int pll_max;
  45. int pll_min;
  46. int sclk, mclk, mclk_pm, xclk;
  47. int ref_div;
  48. int ref_clk;
  49. };
  50. typedef struct {
  51. u16 unknown1;
  52. u16 PCLK_min_freq;
  53. u16 PCLK_max_freq;
  54. u16 unknown2;
  55. u16 ref_freq;
  56. u16 ref_divider;
  57. u16 unknown3;
  58. u16 MCLK_pwd;
  59. u16 MCLK_max_freq;
  60. u16 XCLK_max_freq;
  61. u16 SCLK_freq;
  62. } __attribute__ ((packed)) PLL_BLOCK_MACH64;
  63. struct pll_514 {
  64. u8 m;
  65. u8 n;
  66. };
  67. struct pll_18818 {
  68. u32 program_bits;
  69. u32 locationAddr;
  70. u32 period_in_ps;
  71. u32 post_divider;
  72. };
  73. struct pll_ct {
  74. u8 pll_ref_div;
  75. u8 pll_gen_cntl;
  76. u8 mclk_fb_div;
  77. u8 mclk_fb_mult; /* 2 ro 4 */
  78. u8 sclk_fb_div;
  79. u8 pll_vclk_cntl;
  80. u8 vclk_post_div;
  81. u8 vclk_fb_div;
  82. u8 pll_ext_cntl;
  83. u8 ext_vpll_cntl;
  84. u8 spll_cntl2;
  85. u32 dsp_config; /* Mach64 GTB DSP */
  86. u32 dsp_on_off; /* Mach64 GTB DSP */
  87. u32 dsp_loop_latency;
  88. u32 fifo_size;
  89. u32 xclkpagefaultdelay;
  90. u32 xclkmaxrasdelay;
  91. u8 xclk_ref_div;
  92. u8 xclk_post_div;
  93. u8 mclk_post_div_real;
  94. u8 xclk_post_div_real;
  95. u8 vclk_post_div_real;
  96. u8 features;
  97. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  98. u32 xres; /* use for LCD stretching/scaling */
  99. #endif
  100. };
  101. /*
  102. for pll_ct.features
  103. */
  104. #define DONT_USE_SPLL 0x1
  105. #define DONT_USE_XDLL 0x2
  106. #define USE_CPUCLK 0x4
  107. #define POWERDOWN_PLL 0x8
  108. union aty_pll {
  109. struct pll_ct ct;
  110. struct pll_514 ibm514;
  111. struct pll_18818 ics2595;
  112. };
  113. /*
  114. * The hardware parameters for each card
  115. */
  116. struct atyfb_par {
  117. struct aty_cmap_regs __iomem *aty_cmap_regs;
  118. struct { u8 red, green, blue; } palette[256];
  119. const struct aty_dac_ops *dac_ops;
  120. const struct aty_pll_ops *pll_ops;
  121. void __iomem *ati_regbase;
  122. unsigned long clk_wr_offset; /* meaning overloaded, clock id by CT */
  123. struct crtc crtc;
  124. union aty_pll pll;
  125. struct pll_info pll_limits;
  126. u32 features;
  127. u32 ref_clk_per;
  128. u32 pll_per;
  129. u32 mclk_per;
  130. u32 xclk_per;
  131. u8 bus_type;
  132. u8 ram_type;
  133. u8 mem_refresh_rate;
  134. u16 pci_id;
  135. u32 accel_flags;
  136. int blitter_may_be_busy;
  137. int asleep;
  138. int lock_blank;
  139. unsigned long res_start;
  140. unsigned long res_size;
  141. #ifdef __sparc__
  142. struct pci_mmap_map *mmap_map;
  143. u8 mmaped;
  144. #endif
  145. int open;
  146. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  147. unsigned long bios_base_phys;
  148. unsigned long bios_base;
  149. unsigned long lcd_table;
  150. u16 lcd_width;
  151. u16 lcd_height;
  152. u32 lcd_pixclock;
  153. u16 lcd_refreshrate;
  154. u16 lcd_htotal;
  155. u16 lcd_hdisp;
  156. u16 lcd_hsync_dly;
  157. u16 lcd_hsync_len;
  158. u16 lcd_vtotal;
  159. u16 lcd_vdisp;
  160. u16 lcd_vsync_len;
  161. u16 lcd_right_margin;
  162. u16 lcd_lower_margin;
  163. u16 lcd_hblank_len;
  164. u16 lcd_vblank_len;
  165. #endif
  166. unsigned long aux_start; /* auxiliary aperture */
  167. unsigned long aux_size;
  168. struct aty_interrupt vblank;
  169. unsigned long irq_flags;
  170. unsigned int irq;
  171. spinlock_t int_lock;
  172. #ifdef CONFIG_MTRR
  173. int mtrr_aper;
  174. int mtrr_reg;
  175. #endif
  176. };
  177. /*
  178. * ATI Mach64 features
  179. */
  180. #define M64_HAS(feature) ((par)->features & (M64F_##feature))
  181. #define M64F_RESET_3D 0x00000001
  182. #define M64F_MAGIC_FIFO 0x00000002
  183. #define M64F_GTB_DSP 0x00000004
  184. #define M64F_FIFO_32 0x00000008
  185. #define M64F_SDRAM_MAGIC_PLL 0x00000010
  186. #define M64F_MAGIC_POSTDIV 0x00000020
  187. #define M64F_INTEGRATED 0x00000040
  188. #define M64F_CT_BUS 0x00000080
  189. #define M64F_VT_BUS 0x00000100
  190. #define M64F_MOBIL_BUS 0x00000200
  191. #define M64F_GX 0x00000400
  192. #define M64F_CT 0x00000800
  193. #define M64F_VT 0x00001000
  194. #define M64F_GT 0x00002000
  195. #define M64F_MAGIC_VRAM_SIZE 0x00004000
  196. #define M64F_G3_PB_1_1 0x00008000
  197. #define M64F_G3_PB_1024x768 0x00010000
  198. #define M64F_EXTRA_BRIGHT 0x00020000
  199. #define M64F_LT_LCD_REGS 0x00040000
  200. #define M64F_XL_DLL 0x00080000
  201. #define M64F_MFB_FORCE_4 0x00100000
  202. #define M64F_HW_TRIPLE 0x00200000
  203. /*
  204. * Register access
  205. */
  206. static inline u32 aty_ld_le32(int regindex, const struct atyfb_par *par)
  207. {
  208. /* Hack for bloc 1, should be cleanly optimized by compiler */
  209. if (regindex >= 0x400)
  210. regindex -= 0x800;
  211. #ifdef CONFIG_ATARI
  212. return in_le32((volatile u32 *)(par->ati_regbase + regindex));
  213. #else
  214. return readl(par->ati_regbase + regindex);
  215. #endif
  216. }
  217. static inline void aty_st_le32(int regindex, u32 val, const struct atyfb_par *par)
  218. {
  219. /* Hack for bloc 1, should be cleanly optimized by compiler */
  220. if (regindex >= 0x400)
  221. regindex -= 0x800;
  222. #ifdef CONFIG_ATARI
  223. out_le32((volatile u32 *)(par->ati_regbase + regindex), val);
  224. #else
  225. writel(val, par->ati_regbase + regindex);
  226. #endif
  227. }
  228. static inline void aty_st_le16(int regindex, u16 val,
  229. const struct atyfb_par *par)
  230. {
  231. /* Hack for bloc 1, should be cleanly optimized by compiler */
  232. if (regindex >= 0x400)
  233. regindex -= 0x800;
  234. #ifdef CONFIG_ATARI
  235. out_le16((volatile u16 *)(par->ati_regbase + regindex), val);
  236. #else
  237. writel(val, par->ati_regbase + regindex);
  238. #endif
  239. }
  240. static inline u8 aty_ld_8(int regindex, const struct atyfb_par *par)
  241. {
  242. /* Hack for bloc 1, should be cleanly optimized by compiler */
  243. if (regindex >= 0x400)
  244. regindex -= 0x800;
  245. #ifdef CONFIG_ATARI
  246. return in_8(par->ati_regbase + regindex);
  247. #else
  248. return readb(par->ati_regbase + regindex);
  249. #endif
  250. }
  251. static inline void aty_st_8(int regindex, u8 val, const struct atyfb_par *par)
  252. {
  253. /* Hack for bloc 1, should be cleanly optimized by compiler */
  254. if (regindex >= 0x400)
  255. regindex -= 0x800;
  256. #ifdef CONFIG_ATARI
  257. out_8(par->ati_regbase + regindex, val);
  258. #else
  259. writeb(val, par->ati_regbase + regindex);
  260. #endif
  261. }
  262. #if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD)
  263. extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par);
  264. extern u32 aty_ld_lcd(int index, const struct atyfb_par *par);
  265. #endif
  266. /*
  267. * DAC operations
  268. */
  269. struct aty_dac_ops {
  270. int (*set_dac) (const struct fb_info * info,
  271. const union aty_pll * pll, u32 bpp, u32 accel);
  272. };
  273. extern const struct aty_dac_ops aty_dac_ibm514; /* IBM RGB514 */
  274. extern const struct aty_dac_ops aty_dac_ati68860b; /* ATI 68860-B */
  275. extern const struct aty_dac_ops aty_dac_att21c498; /* AT&T 21C498 */
  276. extern const struct aty_dac_ops aty_dac_unsupported; /* unsupported */
  277. extern const struct aty_dac_ops aty_dac_ct; /* Integrated */
  278. /*
  279. * Clock operations
  280. */
  281. struct aty_pll_ops {
  282. int (*var_to_pll) (const struct fb_info * info, u32 vclk_per, u32 bpp, union aty_pll * pll);
  283. u32 (*pll_to_var) (const struct fb_info * info, const union aty_pll * pll);
  284. void (*set_pll) (const struct fb_info * info, const union aty_pll * pll);
  285. void (*get_pll) (const struct fb_info *info, union aty_pll * pll);
  286. int (*init_pll) (const struct fb_info * info, union aty_pll * pll);
  287. };
  288. extern const struct aty_pll_ops aty_pll_ati18818_1; /* ATI 18818 */
  289. extern const struct aty_pll_ops aty_pll_stg1703; /* STG 1703 */
  290. extern const struct aty_pll_ops aty_pll_ch8398; /* Chrontel 8398 */
  291. extern const struct aty_pll_ops aty_pll_att20c408; /* AT&T 20C408 */
  292. extern const struct aty_pll_ops aty_pll_ibm514; /* IBM RGB514 */
  293. extern const struct aty_pll_ops aty_pll_unsupported; /* unsupported */
  294. extern const struct aty_pll_ops aty_pll_ct; /* Integrated */
  295. extern void aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll);
  296. extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);
  297. /*
  298. * Hardware cursor support
  299. */
  300. extern int aty_init_cursor(struct fb_info *info);
  301. /*
  302. * Hardware acceleration
  303. */
  304. static inline void wait_for_fifo(u16 entries, const struct atyfb_par *par)
  305. {
  306. while ((aty_ld_le32(FIFO_STAT, par) & 0xffff) >
  307. ((u32) (0x8000 >> entries)));
  308. }
  309. static inline void wait_for_idle(struct atyfb_par *par)
  310. {
  311. wait_for_fifo(16, par);
  312. while ((aty_ld_le32(GUI_STAT, par) & 1) != 0);
  313. par->blitter_may_be_busy = 0;
  314. }
  315. extern void aty_reset_engine(const struct atyfb_par *par);
  316. extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info);
  317. extern int atyfb_xl_init(struct fb_info *info);
  318. extern void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par);
  319. extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);