radeonfb.h 14 KB

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