atyfb.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * ATI Frame Buffer Device Driver Core Definitions
  3. */
  4. #include <linux/spinlock.h>
  5. #include <linux/wait.h>
  6. /*
  7. * Elements of the hardware specific atyfb_par structure
  8. */
  9. struct crtc {
  10. u32 vxres;
  11. u32 vyres;
  12. u32 xoffset;
  13. u32 yoffset;
  14. u32 bpp;
  15. u32 h_tot_disp;
  16. u32 h_sync_strt_wid;
  17. u32 v_tot_disp;
  18. u32 v_sync_strt_wid;
  19. u32 vline_crnt_vline;
  20. u32 off_pitch;
  21. u32 gen_cntl;
  22. u32 dp_pix_width; /* acceleration */
  23. u32 dp_chain_mask; /* acceleration */
  24. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  25. u32 horz_stretching;
  26. u32 vert_stretching;
  27. u32 ext_vert_stretch;
  28. u32 shadow_h_tot_disp;
  29. u32 shadow_h_sync_strt_wid;
  30. u32 shadow_v_tot_disp;
  31. u32 shadow_v_sync_strt_wid;
  32. u32 lcd_gen_cntl;
  33. u32 lcd_config_panel;
  34. u32 lcd_index;
  35. #endif
  36. };
  37. struct aty_interrupt {
  38. wait_queue_head_t wait;
  39. unsigned int count;
  40. int pan_display;
  41. };
  42. struct pll_info {
  43. int pll_max;
  44. int pll_min;
  45. int sclk, mclk, mclk_pm, xclk;
  46. int ref_div;
  47. int ref_clk;
  48. int ecp_max;
  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. u32 pseudo_palette[16];
  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. struct pci_dev *pdev;
  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. u32 mem_cntl;
  178. struct crtc saved_crtc;
  179. union aty_pll saved_pll;
  180. };
  181. /*
  182. * ATI Mach64 features
  183. */
  184. #define M64_HAS(feature) ((par)->features & (M64F_##feature))
  185. #define M64F_RESET_3D 0x00000001
  186. #define M64F_MAGIC_FIFO 0x00000002
  187. #define M64F_GTB_DSP 0x00000004
  188. #define M64F_FIFO_32 0x00000008
  189. #define M64F_SDRAM_MAGIC_PLL 0x00000010
  190. #define M64F_MAGIC_POSTDIV 0x00000020
  191. #define M64F_INTEGRATED 0x00000040
  192. #define M64F_CT_BUS 0x00000080
  193. #define M64F_VT_BUS 0x00000100
  194. #define M64F_MOBIL_BUS 0x00000200
  195. #define M64F_GX 0x00000400
  196. #define M64F_CT 0x00000800
  197. #define M64F_VT 0x00001000
  198. #define M64F_GT 0x00002000
  199. #define M64F_MAGIC_VRAM_SIZE 0x00004000
  200. #define M64F_G3_PB_1_1 0x00008000
  201. #define M64F_G3_PB_1024x768 0x00010000
  202. #define M64F_EXTRA_BRIGHT 0x00020000
  203. #define M64F_LT_LCD_REGS 0x00040000
  204. #define M64F_XL_DLL 0x00080000
  205. #define M64F_MFB_FORCE_4 0x00100000
  206. #define M64F_HW_TRIPLE 0x00200000
  207. #define M64F_XL_MEM 0x00400000
  208. /*
  209. * Register access
  210. */
  211. static inline u32 aty_ld_le32(int regindex, const struct atyfb_par *par)
  212. {
  213. /* Hack for bloc 1, should be cleanly optimized by compiler */
  214. if (regindex >= 0x400)
  215. regindex -= 0x800;
  216. #ifdef CONFIG_ATARI
  217. return in_le32(par->ati_regbase + regindex);
  218. #else
  219. return readl(par->ati_regbase + regindex);
  220. #endif
  221. }
  222. static inline void aty_st_le32(int regindex, u32 val, const struct atyfb_par *par)
  223. {
  224. /* Hack for bloc 1, should be cleanly optimized by compiler */
  225. if (regindex >= 0x400)
  226. regindex -= 0x800;
  227. #ifdef CONFIG_ATARI
  228. out_le32(par->ati_regbase + regindex, val);
  229. #else
  230. writel(val, par->ati_regbase + regindex);
  231. #endif
  232. }
  233. static inline void aty_st_le16(int regindex, u16 val,
  234. const struct atyfb_par *par)
  235. {
  236. /* Hack for bloc 1, should be cleanly optimized by compiler */
  237. if (regindex >= 0x400)
  238. regindex -= 0x800;
  239. #ifdef CONFIG_ATARI
  240. out_le16(par->ati_regbase + regindex, val);
  241. #else
  242. writel(val, par->ati_regbase + regindex);
  243. #endif
  244. }
  245. static inline u8 aty_ld_8(int regindex, const struct atyfb_par *par)
  246. {
  247. /* Hack for bloc 1, should be cleanly optimized by compiler */
  248. if (regindex >= 0x400)
  249. regindex -= 0x800;
  250. #ifdef CONFIG_ATARI
  251. return in_8(par->ati_regbase + regindex);
  252. #else
  253. return readb(par->ati_regbase + regindex);
  254. #endif
  255. }
  256. static inline void aty_st_8(int regindex, u8 val, const struct atyfb_par *par)
  257. {
  258. /* Hack for bloc 1, should be cleanly optimized by compiler */
  259. if (regindex >= 0x400)
  260. regindex -= 0x800;
  261. #ifdef CONFIG_ATARI
  262. out_8(par->ati_regbase + regindex, val);
  263. #else
  264. writeb(val, par->ati_regbase + regindex);
  265. #endif
  266. }
  267. #if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
  268. defined (CONFIG_FB_ATY_GENERIC_LCD) || defined (CONFIG_FB_ATY_BACKLIGHT)
  269. extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par);
  270. extern u32 aty_ld_lcd(int index, const struct atyfb_par *par);
  271. #endif
  272. /*
  273. * DAC operations
  274. */
  275. struct aty_dac_ops {
  276. int (*set_dac) (const struct fb_info * info,
  277. const union aty_pll * pll, u32 bpp, u32 accel);
  278. };
  279. extern const struct aty_dac_ops aty_dac_ibm514; /* IBM RGB514 */
  280. extern const struct aty_dac_ops aty_dac_ati68860b; /* ATI 68860-B */
  281. extern const struct aty_dac_ops aty_dac_att21c498; /* AT&T 21C498 */
  282. extern const struct aty_dac_ops aty_dac_unsupported; /* unsupported */
  283. extern const struct aty_dac_ops aty_dac_ct; /* Integrated */
  284. /*
  285. * Clock operations
  286. */
  287. struct aty_pll_ops {
  288. int (*var_to_pll) (const struct fb_info * info, u32 vclk_per, u32 bpp, union aty_pll * pll);
  289. u32 (*pll_to_var) (const struct fb_info * info, const union aty_pll * pll);
  290. void (*set_pll) (const struct fb_info * info, const union aty_pll * pll);
  291. void (*get_pll) (const struct fb_info *info, union aty_pll * pll);
  292. int (*init_pll) (const struct fb_info * info, union aty_pll * pll);
  293. void (*resume_pll)(const struct fb_info *info, union aty_pll *pll);
  294. };
  295. extern const struct aty_pll_ops aty_pll_ati18818_1; /* ATI 18818 */
  296. extern const struct aty_pll_ops aty_pll_stg1703; /* STG 1703 */
  297. extern const struct aty_pll_ops aty_pll_ch8398; /* Chrontel 8398 */
  298. extern const struct aty_pll_ops aty_pll_att20c408; /* AT&T 20C408 */
  299. extern const struct aty_pll_ops aty_pll_ibm514; /* IBM RGB514 */
  300. extern const struct aty_pll_ops aty_pll_unsupported; /* unsupported */
  301. extern const struct aty_pll_ops aty_pll_ct; /* Integrated */
  302. extern void aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll);
  303. extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);
  304. /*
  305. * Hardware cursor support
  306. */
  307. extern int aty_init_cursor(struct fb_info *info);
  308. /*
  309. * Hardware acceleration
  310. */
  311. static inline void wait_for_fifo(u16 entries, const struct atyfb_par *par)
  312. {
  313. while ((aty_ld_le32(FIFO_STAT, par) & 0xffff) >
  314. ((u32) (0x8000 >> entries)));
  315. }
  316. static inline void wait_for_idle(struct atyfb_par *par)
  317. {
  318. wait_for_fifo(16, par);
  319. while ((aty_ld_le32(GUI_STAT, par) & 1) != 0);
  320. par->blitter_may_be_busy = 0;
  321. }
  322. extern void aty_reset_engine(const struct atyfb_par *par);
  323. extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info);
  324. extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);
  325. void atyfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  326. void atyfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
  327. void atyfb_imageblit(struct fb_info *info, const struct fb_image *image);