atyfb.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ATI Frame Buffer Device Driver Core Definitions
  4. */
  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. u32 pseudo_palette[16];
  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. struct pci_dev *pdev;
  143. #ifdef __sparc__
  144. struct pci_mmap_map *mmap_map;
  145. u8 mmaped;
  146. #endif
  147. int open;
  148. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  149. unsigned long bios_base_phys;
  150. unsigned long bios_base;
  151. unsigned long lcd_table;
  152. u16 lcd_width;
  153. u16 lcd_height;
  154. u32 lcd_pixclock;
  155. u16 lcd_refreshrate;
  156. u16 lcd_htotal;
  157. u16 lcd_hdisp;
  158. u16 lcd_hsync_dly;
  159. u16 lcd_hsync_len;
  160. u16 lcd_vtotal;
  161. u16 lcd_vdisp;
  162. u16 lcd_vsync_len;
  163. u16 lcd_right_margin;
  164. u16 lcd_lower_margin;
  165. u16 lcd_hblank_len;
  166. u16 lcd_vblank_len;
  167. #endif
  168. unsigned long aux_start; /* auxiliary aperture */
  169. unsigned long aux_size;
  170. struct aty_interrupt vblank;
  171. unsigned long irq_flags;
  172. unsigned int irq;
  173. spinlock_t int_lock;
  174. int wc_cookie;
  175. u32 mem_cntl;
  176. struct crtc saved_crtc;
  177. union aty_pll saved_pll;
  178. };
  179. /*
  180. * ATI Mach64 features
  181. */
  182. #define M64_HAS(feature) ((par)->features & (M64F_##feature))
  183. #define M64F_RESET_3D 0x00000001
  184. #define M64F_MAGIC_FIFO 0x00000002
  185. #define M64F_GTB_DSP 0x00000004
  186. #define M64F_FIFO_32 0x00000008
  187. #define M64F_SDRAM_MAGIC_PLL 0x00000010
  188. #define M64F_MAGIC_POSTDIV 0x00000020
  189. #define M64F_INTEGRATED 0x00000040
  190. #define M64F_CT_BUS 0x00000080
  191. #define M64F_VT_BUS 0x00000100
  192. #define M64F_MOBIL_BUS 0x00000200
  193. #define M64F_GX 0x00000400
  194. #define M64F_CT 0x00000800
  195. #define M64F_VT 0x00001000
  196. #define M64F_GT 0x00002000
  197. #define M64F_MAGIC_VRAM_SIZE 0x00004000
  198. #define M64F_G3_PB_1_1 0x00008000
  199. #define M64F_G3_PB_1024x768 0x00010000
  200. #define M64F_EXTRA_BRIGHT 0x00020000
  201. #define M64F_LT_LCD_REGS 0x00040000
  202. #define M64F_XL_DLL 0x00080000
  203. #define M64F_MFB_FORCE_4 0x00100000
  204. #define M64F_HW_TRIPLE 0x00200000
  205. #define M64F_XL_MEM 0x00400000
  206. /*
  207. * Register access
  208. */
  209. static inline u32 aty_ld_le32(int regindex, const struct atyfb_par *par)
  210. {
  211. /* Hack for bloc 1, should be cleanly optimized by compiler */
  212. if (regindex >= 0x400)
  213. regindex -= 0x800;
  214. #ifdef CONFIG_ATARI
  215. return in_le32(par->ati_regbase + regindex);
  216. #else
  217. return readl(par->ati_regbase + regindex);
  218. #endif
  219. }
  220. static inline void aty_st_le32(int regindex, u32 val, const struct atyfb_par *par)
  221. {
  222. /* Hack for bloc 1, should be cleanly optimized by compiler */
  223. if (regindex >= 0x400)
  224. regindex -= 0x800;
  225. #ifdef CONFIG_ATARI
  226. out_le32(par->ati_regbase + regindex, val);
  227. #else
  228. writel(val, par->ati_regbase + regindex);
  229. #endif
  230. }
  231. static inline void aty_st_le16(int regindex, u16 val,
  232. const struct atyfb_par *par)
  233. {
  234. /* Hack for bloc 1, should be cleanly optimized by compiler */
  235. if (regindex >= 0x400)
  236. regindex -= 0x800;
  237. #ifdef CONFIG_ATARI
  238. out_le16(par->ati_regbase + regindex, val);
  239. #else
  240. writel(val, par->ati_regbase + regindex);
  241. #endif
  242. }
  243. static inline u8 aty_ld_8(int regindex, const struct atyfb_par *par)
  244. {
  245. /* Hack for bloc 1, should be cleanly optimized by compiler */
  246. if (regindex >= 0x400)
  247. regindex -= 0x800;
  248. #ifdef CONFIG_ATARI
  249. return in_8(par->ati_regbase + regindex);
  250. #else
  251. return readb(par->ati_regbase + regindex);
  252. #endif
  253. }
  254. static inline void aty_st_8(int regindex, u8 val, const struct atyfb_par *par)
  255. {
  256. /* Hack for bloc 1, should be cleanly optimized by compiler */
  257. if (regindex >= 0x400)
  258. regindex -= 0x800;
  259. #ifdef CONFIG_ATARI
  260. out_8(par->ati_regbase + regindex, val);
  261. #else
  262. writeb(val, par->ati_regbase + regindex);
  263. #endif
  264. }
  265. #if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
  266. defined (CONFIG_FB_ATY_GENERIC_LCD) || defined (CONFIG_FB_ATY_BACKLIGHT)
  267. extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par);
  268. extern u32 aty_ld_lcd(int index, const struct atyfb_par *par);
  269. #endif
  270. /*
  271. * DAC operations
  272. */
  273. struct aty_dac_ops {
  274. int (*set_dac) (const struct fb_info * info,
  275. const union aty_pll * pll, u32 bpp, u32 accel);
  276. };
  277. extern const struct aty_dac_ops aty_dac_ibm514; /* IBM RGB514 */
  278. extern const struct aty_dac_ops aty_dac_ati68860b; /* ATI 68860-B */
  279. extern const struct aty_dac_ops aty_dac_att21c498; /* AT&T 21C498 */
  280. extern const struct aty_dac_ops aty_dac_unsupported; /* unsupported */
  281. extern const struct aty_dac_ops aty_dac_ct; /* Integrated */
  282. /*
  283. * Clock operations
  284. */
  285. struct aty_pll_ops {
  286. int (*var_to_pll) (const struct fb_info * info, u32 vclk_per, u32 bpp, union aty_pll * pll);
  287. u32 (*pll_to_var) (const struct fb_info * info, const union aty_pll * pll);
  288. void (*set_pll) (const struct fb_info * info, const union aty_pll * pll);
  289. void (*get_pll) (const struct fb_info *info, union aty_pll * pll);
  290. int (*init_pll) (const struct fb_info * info, union aty_pll * pll);
  291. void (*resume_pll)(const struct fb_info *info, union aty_pll *pll);
  292. };
  293. extern const struct aty_pll_ops aty_pll_ati18818_1; /* ATI 18818 */
  294. extern const struct aty_pll_ops aty_pll_stg1703; /* STG 1703 */
  295. extern const struct aty_pll_ops aty_pll_ch8398; /* Chrontel 8398 */
  296. extern const struct aty_pll_ops aty_pll_att20c408; /* AT&T 20C408 */
  297. extern const struct aty_pll_ops aty_pll_ibm514; /* IBM RGB514 */
  298. extern const struct aty_pll_ops aty_pll_unsupported; /* unsupported */
  299. extern const struct aty_pll_ops aty_pll_ct; /* Integrated */
  300. extern void aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll);
  301. extern u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par);
  302. extern const u8 aty_postdividers[8];
  303. /*
  304. * Hardware cursor support
  305. */
  306. extern int aty_init_cursor(struct fb_info *info);
  307. /*
  308. * Hardware acceleration
  309. */
  310. static inline void wait_for_fifo(u16 entries, const struct atyfb_par *par)
  311. {
  312. while ((aty_ld_le32(FIFO_STAT, par) & 0xffff) >
  313. ((u32) (0x8000 >> entries)));
  314. }
  315. static inline void wait_for_idle(struct atyfb_par *par)
  316. {
  317. wait_for_fifo(16, par);
  318. while ((aty_ld_le32(GUI_STAT, par) & 1) != 0);
  319. par->blitter_may_be_busy = 0;
  320. }
  321. extern void aty_reset_engine(const struct atyfb_par *par);
  322. extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info);
  323. void atyfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  324. void atyfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
  325. void atyfb_imageblit(struct fb_info *info, const struct fb_image *image);