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