radeonfb.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __RADEONFB_H__
  3. #define __RADEONFB_H__
  4. #ifdef CONFIG_FB_RADEON_DEBUG
  5. #define DEBUG 1
  6. #endif
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/delay.h>
  11. #include <linux/pci.h>
  12. #include <linux/fb.h>
  13. #ifdef CONFIG_FB_RADEON_I2C
  14. #include <linux/i2c.h>
  15. #include <linux/i2c-algo-bit.h>
  16. #endif
  17. #include <asm/io.h>
  18. #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
  19. #include <asm/prom.h>
  20. #endif
  21. #include <video/radeon.h>
  22. /***************************************************************
  23. * Most of the definitions here are adapted right from XFree86 *
  24. ***************************************************************/
  25. /*
  26. * Chip families. Must fit in the low 16 bits of a long word
  27. */
  28. enum radeon_family {
  29. CHIP_FAMILY_UNKNOW,
  30. CHIP_FAMILY_LEGACY,
  31. CHIP_FAMILY_RADEON,
  32. CHIP_FAMILY_RV100,
  33. CHIP_FAMILY_RS100, /* U1 (IGP320M) or A3 (IGP320)*/
  34. CHIP_FAMILY_RV200,
  35. CHIP_FAMILY_RS200, /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350),
  36. RS250 (IGP 7000) */
  37. CHIP_FAMILY_R200,
  38. CHIP_FAMILY_RV250,
  39. CHIP_FAMILY_RS300, /* Radeon 9000 IGP */
  40. CHIP_FAMILY_RV280,
  41. CHIP_FAMILY_R300,
  42. CHIP_FAMILY_R350,
  43. CHIP_FAMILY_RV350,
  44. CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */
  45. CHIP_FAMILY_R420, /* R420/R423/M18 */
  46. CHIP_FAMILY_RC410,
  47. CHIP_FAMILY_RS400,
  48. CHIP_FAMILY_RS480,
  49. CHIP_FAMILY_LAST,
  50. };
  51. #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
  52. ((rinfo)->family == CHIP_FAMILY_RV200) || \
  53. ((rinfo)->family == CHIP_FAMILY_RS100) || \
  54. ((rinfo)->family == CHIP_FAMILY_RS200) || \
  55. ((rinfo)->family == CHIP_FAMILY_RV250) || \
  56. ((rinfo)->family == CHIP_FAMILY_RV280) || \
  57. ((rinfo)->family == CHIP_FAMILY_RS300))
  58. #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
  59. ((rinfo)->family == CHIP_FAMILY_RV350) || \
  60. ((rinfo)->family == CHIP_FAMILY_R350) || \
  61. ((rinfo)->family == CHIP_FAMILY_RV380) || \
  62. ((rinfo)->family == CHIP_FAMILY_R420) || \
  63. ((rinfo)->family == CHIP_FAMILY_RC410) || \
  64. ((rinfo)->family == CHIP_FAMILY_RS480))
  65. /*
  66. * Chip flags
  67. */
  68. enum radeon_chip_flags {
  69. CHIP_FAMILY_MASK = 0x0000ffffUL,
  70. CHIP_FLAGS_MASK = 0xffff0000UL,
  71. CHIP_IS_MOBILITY = 0x00010000UL,
  72. CHIP_IS_IGP = 0x00020000UL,
  73. CHIP_HAS_CRTC2 = 0x00040000UL,
  74. };
  75. /*
  76. * Errata workarounds
  77. */
  78. enum radeon_errata {
  79. CHIP_ERRATA_R300_CG = 0x00000001,
  80. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  81. CHIP_ERRATA_PLL_DELAY = 0x00000004,
  82. };
  83. /*
  84. * Monitor types
  85. */
  86. enum radeon_montype {
  87. MT_NONE = 0,
  88. MT_CRT, /* CRT */
  89. MT_LCD, /* LCD */
  90. MT_DFP, /* DVI */
  91. MT_CTV, /* composite TV */
  92. MT_STV /* S-Video out */
  93. };
  94. /*
  95. * DDC i2c ports
  96. */
  97. enum ddc_type {
  98. ddc_none,
  99. ddc_monid,
  100. ddc_dvi,
  101. ddc_vga,
  102. ddc_crt2,
  103. };
  104. /*
  105. * Connector types
  106. */
  107. enum conn_type {
  108. conn_none,
  109. conn_proprietary,
  110. conn_crt,
  111. conn_DVI_I,
  112. conn_DVI_D,
  113. };
  114. /*
  115. * PLL infos
  116. */
  117. struct pll_info {
  118. int ppll_max;
  119. int ppll_min;
  120. int sclk, mclk;
  121. int ref_div;
  122. int ref_clk;
  123. };
  124. /*
  125. * This structure contains the various registers manipulated by this
  126. * driver for setting or restoring a mode. It's mostly copied from
  127. * XFree's RADEONSaveRec structure. A few chip settings might still be
  128. * tweaked without beeing reflected or saved in these registers though
  129. */
  130. struct radeon_regs {
  131. /* Common registers */
  132. u32 ovr_clr;
  133. u32 ovr_wid_left_right;
  134. u32 ovr_wid_top_bottom;
  135. u32 ov0_scale_cntl;
  136. u32 mpp_tb_config;
  137. u32 mpp_gp_config;
  138. u32 subpic_cntl;
  139. u32 viph_control;
  140. u32 i2c_cntl_1;
  141. u32 gen_int_cntl;
  142. u32 cap0_trig_cntl;
  143. u32 cap1_trig_cntl;
  144. u32 bus_cntl;
  145. u32 surface_cntl;
  146. u32 bios_5_scratch;
  147. /* Other registers to save for VT switches or driver load/unload */
  148. u32 dp_datatype;
  149. u32 rbbm_soft_reset;
  150. u32 clock_cntl_index;
  151. u32 amcgpio_en_reg;
  152. u32 amcgpio_mask;
  153. /* Surface/tiling registers */
  154. u32 surf_lower_bound[8];
  155. u32 surf_upper_bound[8];
  156. u32 surf_info[8];
  157. /* CRTC registers */
  158. u32 crtc_gen_cntl;
  159. u32 crtc_ext_cntl;
  160. u32 dac_cntl;
  161. u32 crtc_h_total_disp;
  162. u32 crtc_h_sync_strt_wid;
  163. u32 crtc_v_total_disp;
  164. u32 crtc_v_sync_strt_wid;
  165. u32 crtc_offset;
  166. u32 crtc_offset_cntl;
  167. u32 crtc_pitch;
  168. u32 disp_merge_cntl;
  169. u32 grph_buffer_cntl;
  170. u32 crtc_more_cntl;
  171. /* CRTC2 registers */
  172. u32 crtc2_gen_cntl;
  173. u32 dac2_cntl;
  174. u32 disp_output_cntl;
  175. u32 disp_hw_debug;
  176. u32 disp2_merge_cntl;
  177. u32 grph2_buffer_cntl;
  178. u32 crtc2_h_total_disp;
  179. u32 crtc2_h_sync_strt_wid;
  180. u32 crtc2_v_total_disp;
  181. u32 crtc2_v_sync_strt_wid;
  182. u32 crtc2_offset;
  183. u32 crtc2_offset_cntl;
  184. u32 crtc2_pitch;
  185. /* Flat panel regs */
  186. u32 fp_crtc_h_total_disp;
  187. u32 fp_crtc_v_total_disp;
  188. u32 fp_gen_cntl;
  189. u32 fp2_gen_cntl;
  190. u32 fp_h_sync_strt_wid;
  191. u32 fp2_h_sync_strt_wid;
  192. u32 fp_horz_stretch;
  193. u32 fp_panel_cntl;
  194. u32 fp_v_sync_strt_wid;
  195. u32 fp2_v_sync_strt_wid;
  196. u32 fp_vert_stretch;
  197. u32 lvds_gen_cntl;
  198. u32 lvds_pll_cntl;
  199. u32 tmds_crc;
  200. u32 tmds_transmitter_cntl;
  201. /* Computed values for PLL */
  202. u32 dot_clock_freq;
  203. int feedback_div;
  204. int post_div;
  205. /* PLL registers */
  206. u32 ppll_div_3;
  207. u32 ppll_ref_div;
  208. u32 vclk_ecp_cntl;
  209. u32 clk_cntl_index;
  210. /* Computed values for PLL2 */
  211. u32 dot_clock_freq_2;
  212. int feedback_div_2;
  213. int post_div_2;
  214. /* PLL2 registers */
  215. u32 p2pll_ref_div;
  216. u32 p2pll_div_0;
  217. u32 htotal_cntl2;
  218. /* Palette */
  219. int palette_valid;
  220. };
  221. struct panel_info {
  222. int xres, yres;
  223. int valid;
  224. int clock;
  225. int hOver_plus, hSync_width, hblank;
  226. int vOver_plus, vSync_width, vblank;
  227. int hAct_high, vAct_high, interlaced;
  228. int pwr_delay;
  229. int use_bios_dividers;
  230. int ref_divider;
  231. int post_divider;
  232. int fbk_divider;
  233. };
  234. struct radeonfb_info;
  235. #ifdef CONFIG_FB_RADEON_I2C
  236. struct radeon_i2c_chan {
  237. struct radeonfb_info *rinfo;
  238. u32 ddc_reg;
  239. struct i2c_adapter adapter;
  240. struct i2c_algo_bit_data algo;
  241. };
  242. #endif
  243. enum radeon_pm_mode {
  244. radeon_pm_none = 0, /* Nothing supported */
  245. radeon_pm_d2 = 0x00000001, /* Can do D2 state */
  246. radeon_pm_off = 0x00000002, /* Can resume from D3 cold */
  247. };
  248. typedef void (*reinit_function_ptr)(struct radeonfb_info *rinfo);
  249. struct radeonfb_info {
  250. struct fb_info *info;
  251. struct radeon_regs state;
  252. struct radeon_regs init_state;
  253. char name[50];
  254. unsigned long mmio_base_phys;
  255. unsigned long fb_base_phys;
  256. void __iomem *mmio_base;
  257. void __iomem *fb_base;
  258. unsigned long fb_local_base;
  259. struct pci_dev *pdev;
  260. #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
  261. struct device_node *of_node;
  262. #endif
  263. void __iomem *bios_seg;
  264. int fp_bios_start;
  265. u32 pseudo_palette[16];
  266. struct { u8 red, green, blue, pad; }
  267. palette[256];
  268. int chipset;
  269. u8 family;
  270. u8 rev;
  271. unsigned int errata;
  272. unsigned long video_ram;
  273. unsigned long mapped_vram;
  274. int vram_width;
  275. int vram_ddr;
  276. int pitch, bpp, depth;
  277. int has_CRTC2;
  278. int is_mobility;
  279. int is_IGP;
  280. int reversed_DAC;
  281. int reversed_TMDS;
  282. struct panel_info panel_info;
  283. int mon1_type;
  284. u8 *mon1_EDID;
  285. struct fb_videomode *mon1_modedb;
  286. int mon1_dbsize;
  287. int mon2_type;
  288. u8 *mon2_EDID;
  289. u32 dp_gui_master_cntl;
  290. struct pll_info pll;
  291. int wc_cookie;
  292. u32 save_regs[100];
  293. int asleep;
  294. int lock_blank;
  295. int dynclk;
  296. int no_schedule;
  297. enum radeon_pm_mode pm_mode;
  298. reinit_function_ptr reinit_func;
  299. /* Lock on register access */
  300. spinlock_t reg_lock;
  301. /* Timer used for delayed LVDS operations */
  302. struct timer_list lvds_timer;
  303. u32 pending_lvds_gen_cntl;
  304. #ifdef CONFIG_FB_RADEON_I2C
  305. struct radeon_i2c_chan i2c[4];
  306. #endif
  307. };
  308. #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
  309. /*
  310. * IO macros
  311. */
  312. void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms);
  313. #define INREG8(addr) readb((rinfo->mmio_base)+addr)
  314. #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
  315. #define INREG16(addr) readw((rinfo->mmio_base)+addr)
  316. #define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr)
  317. #define INREG(addr) readl((rinfo->mmio_base)+addr)
  318. #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
  319. void _OUTREGP(struct radeonfb_info *rinfo, u32 addr, u32 val, u32 mask);
  320. #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
  321. /*
  322. * Note about PLL register accesses:
  323. *
  324. * I have removed the spinlock on them on purpose. The driver now
  325. * expects that it will only manipulate the PLL registers in normal
  326. * task environment, where radeon_msleep() will be called, protected
  327. * by a semaphore (currently the console semaphore) so that no conflict
  328. * will happen on the PLL register index.
  329. *
  330. * With the latest changes to the VT layer, this is guaranteed for all
  331. * calls except the actual drawing/blits which aren't supposed to use
  332. * the PLL registers anyway
  333. *
  334. * This is very important for the workarounds to work properly. The only
  335. * possible exception to this rule is the call to unblank(), which may
  336. * be done at irq time if an oops is in progress.
  337. */
  338. void radeon_pll_errata_after_index_slow(struct radeonfb_info *rinfo);
  339. static inline void radeon_pll_errata_after_index(struct radeonfb_info *rinfo)
  340. {
  341. if (rinfo->errata & CHIP_ERRATA_PLL_DUMMYREADS)
  342. radeon_pll_errata_after_index_slow(rinfo);
  343. }
  344. void radeon_pll_errata_after_data_slow(struct radeonfb_info *rinfo);
  345. static inline void radeon_pll_errata_after_data(struct radeonfb_info *rinfo)
  346. {
  347. if (rinfo->errata & (CHIP_ERRATA_PLL_DELAY|CHIP_ERRATA_R300_CG))
  348. radeon_pll_errata_after_data_slow(rinfo);
  349. }
  350. u32 __INPLL(struct radeonfb_info *rinfo, u32 addr);
  351. void __OUTPLL(struct radeonfb_info *rinfo, unsigned int index, u32 val);
  352. void __OUTPLLP(struct radeonfb_info *rinfo, unsigned int index,
  353. u32 val, u32 mask);
  354. #define INPLL(addr) __INPLL(rinfo, addr)
  355. #define OUTPLL(index, val) __OUTPLL(rinfo, index, val)
  356. #define OUTPLLP(index, val, mask) __OUTPLLP(rinfo, index, val, mask)
  357. #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
  358. #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
  359. (readb(rinfo->bios_seg + (v) + 1) << 8))
  360. #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
  361. (readb(rinfo->bios_seg + (v) + 1) << 8) | \
  362. (readb(rinfo->bios_seg + (v) + 2) << 16) | \
  363. (readb(rinfo->bios_seg + (v) + 3) << 24))
  364. /*
  365. * Inline utilities
  366. */
  367. static inline int round_div(int num, int den)
  368. {
  369. return (num + (den / 2)) / den;
  370. }
  371. static inline int var_to_depth(const struct fb_var_screeninfo *var)
  372. {
  373. if (var->bits_per_pixel != 16)
  374. return var->bits_per_pixel;
  375. return (var->green.length == 5) ? 15 : 16;
  376. }
  377. static inline u32 radeon_get_dstbpp(u16 depth)
  378. {
  379. switch (depth) {
  380. case 8:
  381. return DST_8BPP;
  382. case 15:
  383. return DST_15BPP;
  384. case 16:
  385. return DST_16BPP;
  386. case 32:
  387. return DST_32BPP;
  388. default:
  389. return 0;
  390. }
  391. }
  392. /*
  393. * 2D Engine helper routines
  394. */
  395. void _radeon_fifo_wait(struct radeonfb_info *rinfo, int entries);
  396. void radeon_engine_flush(struct radeonfb_info *rinfo);
  397. void _radeon_engine_idle(struct radeonfb_info *rinfo);
  398. #define radeon_engine_idle() _radeon_engine_idle(rinfo)
  399. #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
  400. #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
  401. /* I2C Functions */
  402. extern void radeon_create_i2c_busses(struct radeonfb_info *rinfo);
  403. extern void radeon_delete_i2c_busses(struct radeonfb_info *rinfo);
  404. extern int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid);
  405. /* PM Functions */
  406. extern int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state);
  407. extern int radeonfb_pci_resume(struct pci_dev *pdev);
  408. extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlist, int force_sleep);
  409. extern void radeonfb_pm_exit(struct radeonfb_info *rinfo);
  410. /* Monitor probe functions */
  411. extern void radeon_probe_screens(struct radeonfb_info *rinfo,
  412. const char *monitor_layout, int ignore_edid);
  413. extern void radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option);
  414. extern int radeon_match_mode(struct radeonfb_info *rinfo,
  415. struct fb_var_screeninfo *dest,
  416. const struct fb_var_screeninfo *src);
  417. /* Accel functions */
  418. extern void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region);
  419. extern void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  420. extern void radeonfb_imageblit(struct fb_info *p, const struct fb_image *image);
  421. extern int radeonfb_sync(struct fb_info *info);
  422. extern void radeonfb_engine_init (struct radeonfb_info *rinfo);
  423. extern void radeonfb_engine_reset(struct radeonfb_info *rinfo);
  424. /* Other functions */
  425. extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch);
  426. extern void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
  427. int reg_only);
  428. /* Backlight functions */
  429. #ifdef CONFIG_FB_RADEON_BACKLIGHT
  430. extern void radeonfb_bl_init(struct radeonfb_info *rinfo);
  431. extern void radeonfb_bl_exit(struct radeonfb_info *rinfo);
  432. #else
  433. static inline void radeonfb_bl_init(struct radeonfb_info *rinfo) {}
  434. static inline void radeonfb_bl_exit(struct radeonfb_info *rinfo) {}
  435. #endif
  436. #endif /* __RADEONFB_H__ */