radeonfb.h 14 KB

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