radeonfb.h 15 KB

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