4 #include <linux/module.h>
5 #include <linux/kernel.h>
6 #include <linux/sched.h>
7 #include <linux/delay.h>
12 #ifdef CONFIG_FB_RADEON_I2C
13 #include <linux/i2c.h>
14 #include <linux/i2c-algo-bit.h>
19 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
23 #include <video/radeon.h>
25 /***************************************************************
26 * Most of the definitions here are adapted right from XFree86 *
27 ***************************************************************/
31 * Chip families. Must fit in the low 16 bits of a long word
38 CHIP_FAMILY_RS100
, /* U1 (IGP320M) or A3 (IGP320)*/
40 CHIP_FAMILY_RS200
, /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350),
44 CHIP_FAMILY_RS300
, /* Radeon 9000 IGP */
49 CHIP_FAMILY_RV380
, /* RV370/RV380/M22/M24 */
50 CHIP_FAMILY_R420
, /* R420/R423/M18 */
56 #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
57 ((rinfo)->family == CHIP_FAMILY_RV200) || \
58 ((rinfo)->family == CHIP_FAMILY_RS100) || \
59 ((rinfo)->family == CHIP_FAMILY_RS200) || \
60 ((rinfo)->family == CHIP_FAMILY_RV250) || \
61 ((rinfo)->family == CHIP_FAMILY_RV280) || \
62 ((rinfo)->family == CHIP_FAMILY_RS300))
65 #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
66 ((rinfo)->family == CHIP_FAMILY_RV350) || \
67 ((rinfo)->family == CHIP_FAMILY_R350) || \
68 ((rinfo)->family == CHIP_FAMILY_RV380) || \
69 ((rinfo)->family == CHIP_FAMILY_R420) || \
70 ((rinfo)->family == CHIP_FAMILY_RC410) || \
71 ((rinfo)->family == CHIP_FAMILY_RS480))
76 enum radeon_chip_flags
{
77 CHIP_FAMILY_MASK
= 0x0000ffffUL
,
78 CHIP_FLAGS_MASK
= 0xffff0000UL
,
79 CHIP_IS_MOBILITY
= 0x00010000UL
,
80 CHIP_IS_IGP
= 0x00020000UL
,
81 CHIP_HAS_CRTC2
= 0x00040000UL
,
88 CHIP_ERRATA_R300_CG
= 0x00000001,
89 CHIP_ERRATA_PLL_DUMMYREADS
= 0x00000002,
90 CHIP_ERRATA_PLL_DELAY
= 0x00000004,
102 MT_CTV
, /* composite TV */
103 MT_STV
/* S-Video out */
142 * This structure contains the various registers manipulated by this
143 * driver for setting or restoring a mode. It's mostly copied from
144 * XFree's RADEONSaveRec structure. A few chip settings might still be
145 * tweaked without beeing reflected or saved in these registers though
148 /* Common registers */
150 u32 ovr_wid_left_right
;
151 u32 ovr_wid_top_bottom
;
165 /* Other registers to save for VT switches or driver load/unload */
168 u32 clock_cntl_index
;
172 /* Surface/tiling registers */
173 u32 surf_lower_bound
[8];
174 u32 surf_upper_bound
[8];
181 u32 crtc_h_total_disp
;
182 u32 crtc_h_sync_strt_wid
;
183 u32 crtc_v_total_disp
;
184 u32 crtc_v_sync_strt_wid
;
186 u32 crtc_offset_cntl
;
189 u32 grph_buffer_cntl
;
192 /* CRTC2 registers */
195 u32 disp_output_cntl
;
197 u32 disp2_merge_cntl
;
198 u32 grph2_buffer_cntl
;
199 u32 crtc2_h_total_disp
;
200 u32 crtc2_h_sync_strt_wid
;
201 u32 crtc2_v_total_disp
;
202 u32 crtc2_v_sync_strt_wid
;
204 u32 crtc2_offset_cntl
;
207 /* Flat panel regs */
208 u32 fp_crtc_h_total_disp
;
209 u32 fp_crtc_v_total_disp
;
212 u32 fp_h_sync_strt_wid
;
213 u32 fp2_h_sync_strt_wid
;
216 u32 fp_v_sync_strt_wid
;
217 u32 fp2_v_sync_strt_wid
;
222 u32 tmds_transmitter_cntl
;
224 /* Computed values for PLL */
235 /* Computed values for PLL2 */
236 u32 dot_clock_freq_2
;
253 int hOver_plus
, hSync_width
, hblank
;
254 int vOver_plus
, vSync_width
, vblank
;
255 int hAct_high
, vAct_high
, interlaced
;
257 int use_bios_dividers
;
263 struct radeonfb_info
;
265 #ifdef CONFIG_FB_RADEON_I2C
266 struct radeon_i2c_chan
{
267 struct radeonfb_info
*rinfo
;
269 struct i2c_adapter adapter
;
270 struct i2c_algo_bit_data algo
;
274 enum radeon_pm_mode
{
275 radeon_pm_none
= 0, /* Nothing supported */
276 radeon_pm_d2
= 0x00000001, /* Can do D2 state */
277 radeon_pm_off
= 0x00000002, /* Can resume from D3 cold */
280 typedef void (*reinit_function_ptr
)(struct radeonfb_info
*rinfo
);
282 struct radeonfb_info
{
283 struct fb_info
*info
;
285 struct radeon_regs state
;
286 struct radeon_regs init_state
;
288 char name
[DEVICE_NAME_SIZE
];
290 unsigned long mmio_base_phys
;
291 unsigned long fb_base_phys
;
293 void __iomem
*mmio_base
;
294 void __iomem
*fb_base
;
296 unsigned long fb_local_base
;
298 struct pci_dev
*pdev
;
299 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
300 struct device_node
*of_node
;
303 void __iomem
*bios_seg
;
306 u32 pseudo_palette
[16];
307 struct { u8 red
, green
, blue
, pad
; }
314 unsigned long video_ram
;
315 unsigned long mapped_vram
;
319 int pitch
, bpp
, depth
;
326 struct panel_info panel_info
;
329 struct fb_videomode
*mon1_modedb
;
334 u32 dp_gui_master_cntl
;
346 enum radeon_pm_mode pm_mode
;
347 reinit_function_ptr reinit_func
;
349 /* Lock on register access */
352 /* Timer used for delayed LVDS operations */
353 struct timer_list lvds_timer
;
354 u32 pending_lvds_gen_cntl
;
356 #ifdef CONFIG_FB_RADEON_I2C
357 struct radeon_i2c_chan i2c
[4];
364 #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
370 #ifdef CONFIG_FB_RADEON_DEBUG
377 #define RTRACE printk
379 #define RTRACE if(0) printk
387 /* Note about this function: we have some rare cases where we must not schedule,
388 * this typically happen with our special "wake up early" hook which allows us to
389 * wake up the graphic chip (and thus get the console back) before everything else
390 * on some machines that support that mechanism. At this point, interrupts are off
391 * and scheduling is not permitted
393 static inline void _radeon_msleep(struct radeonfb_info
*rinfo
, unsigned long ms
)
395 if (rinfo
->no_schedule
|| oops_in_progress
)
402 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
403 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
404 #define INREG16(addr) readw((rinfo->mmio_base)+addr)
405 #define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr)
406 #define INREG(addr) readl((rinfo->mmio_base)+addr)
407 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
409 static inline void _OUTREGP(struct radeonfb_info
*rinfo
, u32 addr
,
415 spin_lock_irqsave(&rinfo
->reg_lock
, flags
);
420 spin_unlock_irqrestore(&rinfo
->reg_lock
, flags
);
423 #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
426 * Note about PLL register accesses:
428 * I have removed the spinlock on them on purpose. The driver now
429 * expects that it will only manipulate the PLL registers in normal
430 * task environment, where radeon_msleep() will be called, protected
431 * by a semaphore (currently the console semaphore) so that no conflict
432 * will happen on the PLL register index.
434 * With the latest changes to the VT layer, this is guaranteed for all
435 * calls except the actual drawing/blits which aren't supposed to use
436 * the PLL registers anyway
438 * This is very important for the workarounds to work properly. The only
439 * possible exception to this rule is the call to unblank(), which may
440 * be done at irq time if an oops is in progress.
442 static inline void radeon_pll_errata_after_index(struct radeonfb_info
*rinfo
)
444 if (!(rinfo
->errata
& CHIP_ERRATA_PLL_DUMMYREADS
))
447 (void)INREG(CLOCK_CNTL_DATA
);
448 (void)INREG(CRTC_GEN_CNTL
);
451 static inline void radeon_pll_errata_after_data(struct radeonfb_info
*rinfo
)
453 if (rinfo
->errata
& CHIP_ERRATA_PLL_DELAY
) {
454 /* we can't deal with posted writes here ... */
455 _radeon_msleep(rinfo
, 5);
457 if (rinfo
->errata
& CHIP_ERRATA_R300_CG
) {
459 save
= INREG(CLOCK_CNTL_INDEX
);
460 tmp
= save
& ~(0x3f | PLL_WR_EN
);
461 OUTREG(CLOCK_CNTL_INDEX
, tmp
);
462 tmp
= INREG(CLOCK_CNTL_DATA
);
463 OUTREG(CLOCK_CNTL_INDEX
, save
);
467 static inline u32
__INPLL(struct radeonfb_info
*rinfo
, u32 addr
)
471 OUTREG8(CLOCK_CNTL_INDEX
, addr
& 0x0000003f);
472 radeon_pll_errata_after_index(rinfo
);
473 data
= INREG(CLOCK_CNTL_DATA
);
474 radeon_pll_errata_after_data(rinfo
);
478 static inline void __OUTPLL(struct radeonfb_info
*rinfo
, unsigned int index
,
482 OUTREG8(CLOCK_CNTL_INDEX
, (index
& 0x0000003f) | 0x00000080);
483 radeon_pll_errata_after_index(rinfo
);
484 OUTREG(CLOCK_CNTL_DATA
, val
);
485 radeon_pll_errata_after_data(rinfo
);
489 static inline void __OUTPLLP(struct radeonfb_info
*rinfo
, unsigned int index
,
494 tmp
= __INPLL(rinfo
, index
);
497 __OUTPLL(rinfo
, index
, tmp
);
501 #define INPLL(addr) __INPLL(rinfo, addr)
502 #define OUTPLL(index, val) __OUTPLL(rinfo, index, val)
503 #define OUTPLLP(index, val, mask) __OUTPLLP(rinfo, index, val, mask)
506 #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
507 #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
508 (readb(rinfo->bios_seg + (v) + 1) << 8))
509 #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
510 (readb(rinfo->bios_seg + (v) + 1) << 8) | \
511 (readb(rinfo->bios_seg + (v) + 2) << 16) | \
512 (readb(rinfo->bios_seg + (v) + 3) << 24))
517 static inline int round_div(int num
, int den
)
519 return (num
+ (den
/ 2)) / den
;
522 static inline int var_to_depth(const struct fb_var_screeninfo
*var
)
524 if (var
->bits_per_pixel
!= 16)
525 return var
->bits_per_pixel
;
526 return (var
->green
.length
== 5) ? 15 : 16;
529 static inline u32
radeon_get_dstbpp(u16 depth
)
546 * 2D Engine helper routines
548 static inline void radeon_engine_flush (struct radeonfb_info
*rinfo
)
553 OUTREGP(RB2D_DSTCACHE_CTLSTAT
, RB2D_DC_FLUSH_ALL
,
556 for (i
=0; i
< 2000000; i
++) {
557 if (!(INREG(RB2D_DSTCACHE_CTLSTAT
) & RB2D_DC_BUSY
))
561 printk(KERN_ERR
"radeonfb: Flush Timeout !\n");
565 static inline void _radeon_fifo_wait(struct radeonfb_info
*rinfo
, int entries
)
569 for (i
=0; i
<2000000; i
++) {
570 if ((INREG(RBBM_STATUS
) & 0x7f) >= entries
)
574 printk(KERN_ERR
"radeonfb: FIFO 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_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_engine_idle() _radeon_engine_idle(rinfo)
597 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
598 #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
602 extern void radeon_create_i2c_busses(struct radeonfb_info
*rinfo
);
603 extern void radeon_delete_i2c_busses(struct radeonfb_info
*rinfo
);
604 extern int radeon_probe_i2c_connector(struct radeonfb_info
*rinfo
, int conn
, u8
**out_edid
);
607 extern int radeonfb_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
);
608 extern int radeonfb_pci_resume(struct pci_dev
*pdev
);
609 extern void radeonfb_pm_init(struct radeonfb_info
*rinfo
, int dynclk
, int ignore_devlist
, int force_sleep
);
610 extern void radeonfb_pm_exit(struct radeonfb_info
*rinfo
);
612 /* Monitor probe functions */
613 extern void radeon_probe_screens(struct radeonfb_info
*rinfo
,
614 const char *monitor_layout
, int ignore_edid
);
615 extern void radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
);
616 extern int radeon_match_mode(struct radeonfb_info
*rinfo
,
617 struct fb_var_screeninfo
*dest
,
618 const struct fb_var_screeninfo
*src
);
620 /* Accel functions */
621 extern void radeonfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*region
);
622 extern void radeonfb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
);
623 extern void radeonfb_imageblit(struct fb_info
*p
, const struct fb_image
*image
);
624 extern int radeonfb_sync(struct fb_info
*info
);
625 extern void radeonfb_engine_init (struct radeonfb_info
*rinfo
);
626 extern void radeonfb_engine_reset(struct radeonfb_info
*rinfo
);
628 /* Other functions */
629 extern int radeon_screen_blank(struct radeonfb_info
*rinfo
, int blank
, int mode_switch
);
630 extern void radeon_write_mode (struct radeonfb_info
*rinfo
, struct radeon_regs
*mode
,
633 /* Backlight functions */
634 #ifdef CONFIG_FB_RADEON_BACKLIGHT
635 extern void radeonfb_bl_init(struct radeonfb_info
*rinfo
);
636 extern void radeonfb_bl_exit(struct radeonfb_info
*rinfo
);
638 static inline void radeonfb_bl_init(struct radeonfb_info
*rinfo
) {}
639 static inline void radeonfb_bl_exit(struct radeonfb_info
*rinfo
) {}
642 #endif /* __RADEONFB_H__ */