4 #include <linux/config.h>
5 #include <linux/module.h>
6 #include <linux/kernel.h>
7 #include <linux/sched.h>
8 #include <linux/delay.h>
13 #include <linux/i2c.h>
14 #include <linux/i2c-id.h>
15 #include <linux/i2c-algo-bit.h>
23 #include <video/radeon.h>
25 /* Some weird black magic use by Apple driver that we don't use for
28 #undef HAS_PLL_M9_GPIO_MAGIC
30 /***************************************************************
31 * Most of the definitions here are adapted right from XFree86 *
32 ***************************************************************/
36 * Chip families. Must fit in the low 16 bits of a long word
43 CHIP_FAMILY_RS100, /* U1 (IGP320M) or A3 (IGP320)*/
45 CHIP_FAMILY_RS200, /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350),
49 CHIP_FAMILY_RS300, /* Radeon 9000 IGP */
54 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */
55 CHIP_FAMILY_R420, /* R420/R423/M18 */
59 #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
60 ((rinfo)->family == CHIP_FAMILY_RV200) || \
61 ((rinfo)->family == CHIP_FAMILY_RS100) || \
62 ((rinfo)->family == CHIP_FAMILY_RS200) || \
63 ((rinfo)->family == CHIP_FAMILY_RV250) || \
64 ((rinfo)->family == CHIP_FAMILY_RV280) || \
65 ((rinfo)->family == CHIP_FAMILY_RS300))
68 #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
69 ((rinfo)->family == CHIP_FAMILY_RV350) || \
70 ((rinfo)->family == CHIP_FAMILY_R350) || \
71 ((rinfo)->family == CHIP_FAMILY_RV380) || \
72 ((rinfo)->family == CHIP_FAMILY_R420))
77 enum radeon_chip_flags {
78 CHIP_FAMILY_MASK = 0x0000ffffUL,
79 CHIP_FLAGS_MASK = 0xffff0000UL,
80 CHIP_IS_MOBILITY = 0x00010000UL,
81 CHIP_IS_IGP = 0x00020000UL,
82 CHIP_HAS_CRTC2 = 0x00040000UL,
94 MT_CTV, /* composite TV */
95 MT_STV /* S-Video out */
134 * This structure contains the various registers manipulated by this
135 * driver for setting or restoring a mode. It's mostly copied from
136 * XFree's RADEONSaveRec structure. A few chip settings might still be
137 * tweaked without beeing reflected or saved in these registers though
140 /* Common registers */
142 u32 ovr_wid_left_right;
143 u32 ovr_wid_top_bottom;
157 /* Other registers to save for VT switches or driver load/unload */
160 u32 clock_cntl_index;
164 /* Surface/tiling registers */
165 u32 surf_lower_bound[8];
166 u32 surf_upper_bound[8];
173 u32 crtc_h_total_disp;
174 u32 crtc_h_sync_strt_wid;
175 u32 crtc_v_total_disp;
176 u32 crtc_v_sync_strt_wid;
178 u32 crtc_offset_cntl;
181 u32 grph_buffer_cntl;
184 /* CRTC2 registers */
187 u32 disp_output_cntl;
189 u32 disp2_merge_cntl;
190 u32 grph2_buffer_cntl;
191 u32 crtc2_h_total_disp;
192 u32 crtc2_h_sync_strt_wid;
193 u32 crtc2_v_total_disp;
194 u32 crtc2_v_sync_strt_wid;
196 u32 crtc2_offset_cntl;
199 /* Flat panel regs */
200 u32 fp_crtc_h_total_disp;
201 u32 fp_crtc_v_total_disp;
204 u32 fp_h_sync_strt_wid;
205 u32 fp2_h_sync_strt_wid;
208 u32 fp_v_sync_strt_wid;
209 u32 fp2_v_sync_strt_wid;
214 u32 tmds_transmitter_cntl;
216 /* Computed values for PLL */
227 /* Computed values for PLL2 */
228 u32 dot_clock_freq_2;
245 int hOver_plus, hSync_width, hblank;
246 int vOver_plus, vSync_width, vblank;
247 int hAct_high, vAct_high, interlaced;
249 int use_bios_dividers;
255 struct radeonfb_info;
257 #ifdef CONFIG_FB_RADEON_I2C
258 struct radeon_i2c_chan {
259 struct radeonfb_info *rinfo;
261 struct i2c_adapter adapter;
262 struct i2c_algo_bit_data algo;
266 enum radeon_pm_mode {
267 radeon_pm_none = 0, /* Nothing supported */
268 radeon_pm_d2 = 0x00000001, /* Can do D2 state */
269 radeon_pm_off = 0x00000002, /* Can resume from D3 cold */
272 struct radeonfb_info {
273 struct fb_info *info;
275 struct radeon_regs state;
276 struct radeon_regs init_state;
278 char name[DEVICE_NAME_SIZE];
280 unsigned long mmio_base_phys;
281 unsigned long fb_base_phys;
283 void __iomem *mmio_base;
284 void __iomem *fb_base;
286 unsigned long fb_local_base;
288 struct pci_dev *pdev;
290 struct device_node *of_node;
293 void __iomem *bios_seg;
296 u32 pseudo_palette[17];
297 struct { u8 red, green, blue, pad; }
303 unsigned long video_ram;
304 unsigned long mapped_vram;
308 int pitch, bpp, depth;
313 int R300_cg_workaround;
317 struct panel_info panel_info;
320 struct fb_videomode *mon1_modedb;
325 u32 dp_gui_master_cntl;
337 enum radeon_pm_mode pm_mode;
338 void (*reinit_func)(struct radeonfb_info *rinfo);
340 /* Lock on register access */
343 /* Timer used for delayed LVDS operations */
344 struct timer_list lvds_timer;
345 u32 pending_lvds_gen_cntl;
347 #ifdef CONFIG_FB_RADEON_I2C
348 struct radeon_i2c_chan i2c[4];
355 #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
361 #ifdef CONFIG_FB_RADEON_DEBUG
368 #define RTRACE printk
370 #define RTRACE if(0) printk
378 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
379 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
380 #define INREG(addr) readl((rinfo->mmio_base)+addr)
381 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
383 static inline void _OUTREGP(struct radeonfb_info *rinfo, u32 addr,
389 spin_lock_irqsave(&rinfo->reg_lock, flags);
394 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
397 #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
399 static inline void R300_cg_workardound(struct radeonfb_info *rinfo)
402 save = INREG(CLOCK_CNTL_INDEX);
403 tmp = save & ~(0x3f | PLL_WR_EN);
404 OUTREG(CLOCK_CNTL_INDEX, tmp);
405 tmp = INREG(CLOCK_CNTL_DATA);
406 OUTREG(CLOCK_CNTL_INDEX, save);
410 static inline u32 __INPLL(struct radeonfb_info *rinfo, u32 addr)
413 #ifdef HAS_PLL_M9_GPIO_MAGIC
416 if (rinfo->m9p_workaround) {
417 sv[0] = INREG(0x19c);
418 sv[1] = INREG(0x1a0);
419 sv[2] = INREG(0x198);
424 #endif /* HAS_PLL_M9_GPIO_MAGIC */
426 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
427 data = (INREG(CLOCK_CNTL_DATA));
429 #ifdef HAS_PLL_M9_GPIO_MAGIC
430 if (rinfo->m9p_workaround) {
431 (void)INREG(CRTC_GEN_CNTL);
432 data = INREG(CLOCK_CNTL_DATA);
433 OUTREG(0x19c, sv[0]);
434 OUTREG(0x1a0, sv[1]);
435 OUTREG(0x198, sv[2]);
437 #endif /* HAS_PLL_M9_GPIO_MAGIC */
438 if (rinfo->R300_cg_workaround)
439 R300_cg_workardound(rinfo);
443 static inline u32 _INPLL(struct radeonfb_info *rinfo, u32 addr)
448 spin_lock_irqsave(&rinfo->reg_lock, flags);
449 data = __INPLL(rinfo, addr);
450 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
454 #define INPLL(addr) _INPLL(rinfo, addr)
457 static inline void __OUTPLL(struct radeonfb_info *rinfo, unsigned int index, u32 val)
459 #ifdef HAS_PLL_M9_GPIO_MAGIC
462 if (rinfo->m9p_workaround) {
463 sv[0] = INREG(0x19c);
464 sv[1] = INREG(0x1a0);
465 sv[2] = INREG(0x198);
471 #endif /* HAS_PLL_M9_GPIO_MAGIC */
473 OUTREG8(CLOCK_CNTL_INDEX, (index & 0x0000003f) | 0x00000080);
474 OUTREG(CLOCK_CNTL_DATA, val);
476 #ifdef HAS_PLL_M9_GPIO_MAGIC
477 if (rinfo->m9p_workaround) {
478 OUTREG(0x19c, sv[0]);
479 OUTREG(0x1a0, sv[1]);
480 OUTREG(0x198, sv[2]);
482 #endif /* HAS_PLL_M9_GPIO_MAGIC */
485 static inline void _OUTPLL(struct radeonfb_info *rinfo, unsigned int index, u32 val)
488 spin_lock_irqsave(&rinfo->reg_lock, flags);
489 __OUTPLL(rinfo, index, val);
490 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
493 static inline void _OUTPLLP(struct radeonfb_info *rinfo, unsigned int index,
499 spin_lock_irqsave(&rinfo->reg_lock, flags);
500 tmp = __INPLL(rinfo, index);
503 __OUTPLL(rinfo, index, tmp);
504 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
508 #define OUTPLL(index, val) _OUTPLL(rinfo, index, val)
509 #define OUTPLLP(index, val, mask) _OUTPLLP(rinfo, index, val, mask)
512 #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
513 #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
514 (readb(rinfo->bios_seg + (v) + 1) << 8))
515 #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
516 (readb(rinfo->bios_seg + (v) + 1) << 8) | \
517 (readb(rinfo->bios_seg + (v) + 2) << 16) | \
518 (readb(rinfo->bios_seg + (v) + 3) << 24))
523 static inline int round_div(int num, int den)
525 return (num + (den / 2)) / den;
528 static inline int var_to_depth(const struct fb_var_screeninfo *var)
530 if (var->bits_per_pixel != 16)
531 return var->bits_per_pixel;
532 return (var->green.length == 5) ? 15 : 16;
535 static inline u32 radeon_get_dstbpp(u16 depth)
552 * 2D Engine helper routines
554 static inline void radeon_engine_flush (struct radeonfb_info *rinfo)
559 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
562 for (i=0; i < 2000000; i++) {
563 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
567 printk(KERN_ERR "radeonfb: Flush Timeout !\n");
571 static inline void _radeon_fifo_wait(struct radeonfb_info *rinfo, int entries)
575 for (i=0; i<2000000; i++) {
576 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
580 printk(KERN_ERR "radeonfb: FIFO Timeout !\n");
584 static inline void _radeon_engine_idle(struct radeonfb_info *rinfo)
588 /* ensure FIFO is empty before waiting for idle */
589 _radeon_fifo_wait (rinfo, 64);
591 for (i=0; i<2000000; i++) {
592 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
593 radeon_engine_flush (rinfo);
598 printk(KERN_ERR "radeonfb: Idle Timeout !\n");
601 /* Note about this function: we have some rare cases where we must not schedule,
602 * this typically happen with our special "wake up early" hook which allows us to
603 * wake up the graphic chip (and thus get the console back) before everything else
604 * on some machines that support that mecanism. At this point, interrupts are off
605 * and scheduling is not permitted
607 static inline void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms)
609 if (rinfo->no_schedule)
616 #define radeon_engine_idle() _radeon_engine_idle(rinfo)
617 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
618 #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
622 extern void radeon_create_i2c_busses(struct radeonfb_info *rinfo);
623 extern void radeon_delete_i2c_busses(struct radeonfb_info *rinfo);
624 extern int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid);
627 extern int radeonfb_pci_suspend(struct pci_dev *pdev, u32 state);
628 extern int radeonfb_pci_resume(struct pci_dev *pdev);
629 extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk);
630 extern void radeonfb_pm_exit(struct radeonfb_info *rinfo);
632 /* Monitor probe functions */
633 extern void radeon_probe_screens(struct radeonfb_info *rinfo,
634 const char *monitor_layout, int ignore_edid);
635 extern void radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option);
636 extern int radeon_match_mode(struct radeonfb_info *rinfo,
637 struct fb_var_screeninfo *dest,
638 const struct fb_var_screeninfo *src);
640 /* Accel functions */
641 extern void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region);
642 extern void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
643 extern void radeonfb_imageblit(struct fb_info *p, const struct fb_image *image);
644 extern int radeonfb_sync(struct fb_info *info);
645 extern void radeonfb_engine_init (struct radeonfb_info *rinfo);
646 extern void radeonfb_engine_reset(struct radeonfb_info *rinfo);
648 /* Other functions */
649 extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch);
650 extern void radeon_save_state (struct radeonfb_info *rinfo, struct radeon_regs *save);
651 extern void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
654 #endif /* __RADEONFB_H__ */