4 #ifdef CONFIG_FB_RADEON_DEBUG
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/delay.h>
12 #include <linux/pci.h>
16 #ifdef CONFIG_FB_RADEON_I2C
17 #include <linux/i2c.h>
18 #include <linux/i2c-algo-bit.h>
23 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
27 #include <video/radeon.h>
29 /***************************************************************
30 * Most of the definitions here are adapted right from XFree86 *
31 ***************************************************************/
35 * Chip families. Must fit in the low 16 bits of a long word
42 CHIP_FAMILY_RS100, /* U1 (IGP320M) or A3 (IGP320)*/
44 CHIP_FAMILY_RS200, /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350),
48 CHIP_FAMILY_RS300, /* Radeon 9000 IGP */
53 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */
54 CHIP_FAMILY_R420, /* R420/R423/M18 */
61 #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
62 ((rinfo)->family == CHIP_FAMILY_RV200) || \
63 ((rinfo)->family == CHIP_FAMILY_RS100) || \
64 ((rinfo)->family == CHIP_FAMILY_RS200) || \
65 ((rinfo)->family == CHIP_FAMILY_RV250) || \
66 ((rinfo)->family == CHIP_FAMILY_RV280) || \
67 ((rinfo)->family == CHIP_FAMILY_RS300))
70 #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
71 ((rinfo)->family == CHIP_FAMILY_RV350) || \
72 ((rinfo)->family == CHIP_FAMILY_R350) || \
73 ((rinfo)->family == CHIP_FAMILY_RV380) || \
74 ((rinfo)->family == CHIP_FAMILY_R420) || \
75 ((rinfo)->family == CHIP_FAMILY_RC410) || \
76 ((rinfo)->family == CHIP_FAMILY_RS480))
81 enum radeon_chip_flags {
82 CHIP_FAMILY_MASK = 0x0000ffffUL,
83 CHIP_FLAGS_MASK = 0xffff0000UL,
84 CHIP_IS_MOBILITY = 0x00010000UL,
85 CHIP_IS_IGP = 0x00020000UL,
86 CHIP_HAS_CRTC2 = 0x00040000UL,
93 CHIP_ERRATA_R300_CG = 0x00000001,
94 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
95 CHIP_ERRATA_PLL_DELAY = 0x00000004,
102 enum radeon_montype {
107 MT_CTV, /* composite TV */
108 MT_STV /* S-Video out */
147 * This structure contains the various registers manipulated by this
148 * driver for setting or restoring a mode. It's mostly copied from
149 * XFree's RADEONSaveRec structure. A few chip settings might still be
150 * tweaked without beeing reflected or saved in these registers though
153 /* Common registers */
155 u32 ovr_wid_left_right;
156 u32 ovr_wid_top_bottom;
170 /* Other registers to save for VT switches or driver load/unload */
173 u32 clock_cntl_index;
177 /* Surface/tiling registers */
178 u32 surf_lower_bound[8];
179 u32 surf_upper_bound[8];
186 u32 crtc_h_total_disp;
187 u32 crtc_h_sync_strt_wid;
188 u32 crtc_v_total_disp;
189 u32 crtc_v_sync_strt_wid;
191 u32 crtc_offset_cntl;
194 u32 grph_buffer_cntl;
197 /* CRTC2 registers */
200 u32 disp_output_cntl;
202 u32 disp2_merge_cntl;
203 u32 grph2_buffer_cntl;
204 u32 crtc2_h_total_disp;
205 u32 crtc2_h_sync_strt_wid;
206 u32 crtc2_v_total_disp;
207 u32 crtc2_v_sync_strt_wid;
209 u32 crtc2_offset_cntl;
212 /* Flat panel regs */
213 u32 fp_crtc_h_total_disp;
214 u32 fp_crtc_v_total_disp;
217 u32 fp_h_sync_strt_wid;
218 u32 fp2_h_sync_strt_wid;
221 u32 fp_v_sync_strt_wid;
222 u32 fp2_v_sync_strt_wid;
227 u32 tmds_transmitter_cntl;
229 /* Computed values for PLL */
240 /* Computed values for PLL2 */
241 u32 dot_clock_freq_2;
258 int hOver_plus, hSync_width, hblank;
259 int vOver_plus, vSync_width, vblank;
260 int hAct_high, vAct_high, interlaced;
262 int use_bios_dividers;
268 struct radeonfb_info;
270 #ifdef CONFIG_FB_RADEON_I2C
271 struct radeon_i2c_chan {
272 struct radeonfb_info *rinfo;
274 struct i2c_adapter adapter;
275 struct i2c_algo_bit_data algo;
279 enum radeon_pm_mode {
280 radeon_pm_none = 0, /* Nothing supported */
281 radeon_pm_d2 = 0x00000001, /* Can do D2 state */
282 radeon_pm_off = 0x00000002, /* Can resume from D3 cold */
285 typedef void (*reinit_function_ptr)(struct radeonfb_info *rinfo);
287 struct radeonfb_info {
288 struct fb_info *info;
290 struct radeon_regs state;
291 struct radeon_regs init_state;
295 unsigned long mmio_base_phys;
296 unsigned long fb_base_phys;
298 void __iomem *mmio_base;
299 void __iomem *fb_base;
301 unsigned long fb_local_base;
303 struct pci_dev *pdev;
304 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
305 struct device_node *of_node;
308 void __iomem *bios_seg;
311 u32 pseudo_palette[16];
312 struct { u8 red, green, blue, pad; }
319 unsigned long video_ram;
320 unsigned long mapped_vram;
324 int pitch, bpp, depth;
331 struct panel_info panel_info;
334 struct fb_videomode *mon1_modedb;
343 u32 dp_brush_fg_cache;
344 u32 dp_brush_bg_cache;
360 enum radeon_pm_mode pm_mode;
361 reinit_function_ptr reinit_func;
363 /* Lock on register access */
366 /* Timer used for delayed LVDS operations */
367 struct timer_list lvds_timer;
368 u32 pending_lvds_gen_cntl;
370 #ifdef CONFIG_FB_RADEON_I2C
371 struct radeon_i2c_chan i2c[4];
378 #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
385 /* Note about this function: we have some rare cases where we must not schedule,
386 * this typically happen with our special "wake up early" hook which allows us to
387 * wake up the graphic chip (and thus get the console back) before everything else
388 * on some machines that support that mechanism. At this point, interrupts are off
389 * and scheduling is not permitted
391 static inline void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms)
393 if (rinfo->no_schedule || oops_in_progress)
400 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
401 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
402 #define INREG16(addr) readw((rinfo->mmio_base)+addr)
403 #define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr)
406 #define INREG(addr) ({ eieio(); ld_le32(rinfo->mmio_base+(addr)); })
407 #define OUTREG(addr,val) do { eieio(); st_le32(rinfo->mmio_base+(addr),(val)); } while(0)
409 #define INREG(addr) readl((rinfo->mmio_base)+addr)
410 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
413 static inline void _OUTREGP(struct radeonfb_info *rinfo, u32 addr,
419 spin_lock_irqsave(&rinfo->reg_lock, flags);
424 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
427 #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
430 * Note about PLL register accesses:
432 * I have removed the spinlock on them on purpose. The driver now
433 * expects that it will only manipulate the PLL registers in normal
434 * task environment, where radeon_msleep() will be called, protected
435 * by a semaphore (currently the console semaphore) so that no conflict
436 * will happen on the PLL register index.
438 * With the latest changes to the VT layer, this is guaranteed for all
439 * calls except the actual drawing/blits which aren't supposed to use
440 * the PLL registers anyway
442 * This is very important for the workarounds to work properly. The only
443 * possible exception to this rule is the call to unblank(), which may
444 * be done at irq time if an oops is in progress.
446 static inline void radeon_pll_errata_after_index(struct radeonfb_info *rinfo)
448 if (!(rinfo->errata & CHIP_ERRATA_PLL_DUMMYREADS))
451 (void)INREG(CLOCK_CNTL_DATA);
452 (void)INREG(CRTC_GEN_CNTL);
455 static inline void radeon_pll_errata_after_data(struct radeonfb_info *rinfo)
457 if (rinfo->errata & CHIP_ERRATA_PLL_DELAY) {
458 /* we can't deal with posted writes here ... */
459 _radeon_msleep(rinfo, 5);
461 if (rinfo->errata & CHIP_ERRATA_R300_CG) {
463 save = INREG(CLOCK_CNTL_INDEX);
464 tmp = save & ~(0x3f | PLL_WR_EN);
465 OUTREG(CLOCK_CNTL_INDEX, tmp);
466 tmp = INREG(CLOCK_CNTL_DATA);
467 OUTREG(CLOCK_CNTL_INDEX, save);
471 static inline u32 __INPLL(struct radeonfb_info *rinfo, u32 addr)
475 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
476 radeon_pll_errata_after_index(rinfo);
477 data = INREG(CLOCK_CNTL_DATA);
478 radeon_pll_errata_after_data(rinfo);
482 static inline void __OUTPLL(struct radeonfb_info *rinfo, unsigned int index,
486 OUTREG8(CLOCK_CNTL_INDEX, (index & 0x0000003f) | 0x00000080);
487 radeon_pll_errata_after_index(rinfo);
488 OUTREG(CLOCK_CNTL_DATA, val);
489 radeon_pll_errata_after_data(rinfo);
493 static inline void __OUTPLLP(struct radeonfb_info *rinfo, unsigned int index,
498 tmp = __INPLL(rinfo, index);
501 __OUTPLL(rinfo, index, tmp);
505 #define INPLL(addr) __INPLL(rinfo, addr)
506 #define OUTPLL(index, val) __OUTPLL(rinfo, index, val)
507 #define OUTPLLP(index, val, mask) __OUTPLLP(rinfo, index, val, mask)
510 #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
511 #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
512 (readb(rinfo->bios_seg + (v) + 1) << 8))
513 #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
514 (readb(rinfo->bios_seg + (v) + 1) << 8) | \
515 (readb(rinfo->bios_seg + (v) + 2) << 16) | \
516 (readb(rinfo->bios_seg + (v) + 3) << 24))
521 static inline int round_div(int num, int den)
523 return (num + (den / 2)) / den;
526 static inline int var_to_depth(const struct fb_var_screeninfo *var)
528 if (var->bits_per_pixel != 16)
529 return var->bits_per_pixel;
530 return (var->green.length == 5) ? 15 : 16;
533 static inline u32 radeon_get_dstbpp(u16 depth)
550 * 2D Engine helper routines
553 extern void radeon_fifo_update_and_wait(struct radeonfb_info *rinfo, int entries);
555 static inline void radeon_engine_flush (struct radeonfb_info *rinfo)
560 OUTREGP(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
563 /* Ensure FIFO is empty, ie, make sure the flush commands
564 * has reached the cache
566 radeon_fifo_update_and_wait(rinfo, 64);
568 /* Wait for the flush to complete */
569 for (i=0; i < 2000000; i++) {
570 if (!(INREG(DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
574 printk(KERN_ERR "radeonfb: Flush Timeout !\n");
578 static inline void radeon_engine_idle(struct radeonfb_info *rinfo)
582 /* ensure FIFO is empty before waiting for idle */
583 radeon_fifo_update_and_wait (rinfo, 64);
585 for (i=0; i<2000000; i++) {
586 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
587 radeon_engine_flush (rinfo);
592 printk(KERN_ERR "radeonfb: Idle Timeout !\n");
596 #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
600 extern void radeon_create_i2c_busses(struct radeonfb_info *rinfo);
601 extern void radeon_delete_i2c_busses(struct radeonfb_info *rinfo);
602 extern int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid);
605 extern int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state);
606 extern int radeonfb_pci_resume(struct pci_dev *pdev);
607 extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlist, int force_sleep);
608 extern void radeonfb_pm_exit(struct radeonfb_info *rinfo);
610 /* Monitor probe functions */
611 extern void radeon_probe_screens(struct radeonfb_info *rinfo,
612 const char *monitor_layout, int ignore_edid);
613 extern void radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option);
614 extern int radeon_match_mode(struct radeonfb_info *rinfo,
615 struct fb_var_screeninfo *dest,
616 const struct fb_var_screeninfo *src);
618 /* Accel functions */
619 extern void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region);
620 extern void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
621 extern void radeonfb_imageblit(struct fb_info *p, const struct fb_image *image);
622 extern int radeonfb_sync(struct fb_info *info);
623 extern void radeonfb_engine_init (struct radeonfb_info *rinfo);
624 extern void radeonfb_engine_reset(struct radeonfb_info *rinfo);
625 extern void radeon_fixup_mem_offset(struct radeonfb_info *rinfo);
627 /* Other functions */
628 extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch);
629 extern void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
632 /* Backlight functions */
633 #ifdef CONFIG_FB_RADEON_BACKLIGHT
634 extern void radeonfb_bl_init(struct radeonfb_info *rinfo);
635 extern void radeonfb_bl_exit(struct radeonfb_info *rinfo);
637 static inline void radeonfb_bl_init(struct radeonfb_info *rinfo) {}
638 static inline void radeonfb_bl_exit(struct radeonfb_info *rinfo) {}
641 #endif /* __RADEONFB_H__ */