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 /***************************************************************
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 */
54 #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
55 ((rinfo)->family == CHIP_FAMILY_RV200) || \
56 ((rinfo)->family == CHIP_FAMILY_RS100) || \
57 ((rinfo)->family == CHIP_FAMILY_RS200) || \
58 ((rinfo)->family == CHIP_FAMILY_RV250) || \
59 ((rinfo)->family == CHIP_FAMILY_RV280) || \
60 ((rinfo)->family == CHIP_FAMILY_RS300))
63 #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
64 ((rinfo)->family == CHIP_FAMILY_RV350) || \
65 ((rinfo)->family == CHIP_FAMILY_R350) || \
66 ((rinfo)->family == CHIP_FAMILY_RV380) || \
67 ((rinfo)->family == CHIP_FAMILY_R420))
72 enum radeon_chip_flags {
73 CHIP_FAMILY_MASK = 0x0000ffffUL,
74 CHIP_FLAGS_MASK = 0xffff0000UL,
75 CHIP_IS_MOBILITY = 0x00010000UL,
76 CHIP_IS_IGP = 0x00020000UL,
77 CHIP_HAS_CRTC2 = 0x00040000UL,
84 CHIP_ERRATA_R300_CG = 0x00000001,
85 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
86 CHIP_ERRATA_PLL_DELAY = 0x00000004,
98 MT_CTV, /* composite TV */
99 MT_STV /* S-Video out */
138 * This structure contains the various registers manipulated by this
139 * driver for setting or restoring a mode. It's mostly copied from
140 * XFree's RADEONSaveRec structure. A few chip settings might still be
141 * tweaked without beeing reflected or saved in these registers though
144 /* Common registers */
146 u32 ovr_wid_left_right;
147 u32 ovr_wid_top_bottom;
161 /* Other registers to save for VT switches or driver load/unload */
164 u32 clock_cntl_index;
168 /* Surface/tiling registers */
169 u32 surf_lower_bound[8];
170 u32 surf_upper_bound[8];
177 u32 crtc_h_total_disp;
178 u32 crtc_h_sync_strt_wid;
179 u32 crtc_v_total_disp;
180 u32 crtc_v_sync_strt_wid;
182 u32 crtc_offset_cntl;
185 u32 grph_buffer_cntl;
188 /* CRTC2 registers */
191 u32 disp_output_cntl;
193 u32 disp2_merge_cntl;
194 u32 grph2_buffer_cntl;
195 u32 crtc2_h_total_disp;
196 u32 crtc2_h_sync_strt_wid;
197 u32 crtc2_v_total_disp;
198 u32 crtc2_v_sync_strt_wid;
200 u32 crtc2_offset_cntl;
203 /* Flat panel regs */
204 u32 fp_crtc_h_total_disp;
205 u32 fp_crtc_v_total_disp;
208 u32 fp_h_sync_strt_wid;
209 u32 fp2_h_sync_strt_wid;
212 u32 fp_v_sync_strt_wid;
213 u32 fp2_v_sync_strt_wid;
218 u32 tmds_transmitter_cntl;
220 /* Computed values for PLL */
231 /* Computed values for PLL2 */
232 u32 dot_clock_freq_2;
249 int hOver_plus, hSync_width, hblank;
250 int vOver_plus, vSync_width, vblank;
251 int hAct_high, vAct_high, interlaced;
253 int use_bios_dividers;
259 struct radeonfb_info;
261 #ifdef CONFIG_FB_RADEON_I2C
262 struct radeon_i2c_chan {
263 struct radeonfb_info *rinfo;
265 struct i2c_adapter adapter;
266 struct i2c_algo_bit_data algo;
270 enum radeon_pm_mode {
271 radeon_pm_none = 0, /* Nothing supported */
272 radeon_pm_d2 = 0x00000001, /* Can do D2 state */
273 radeon_pm_off = 0x00000002, /* Can resume from D3 cold */
276 struct radeonfb_info {
277 struct fb_info *info;
279 struct radeon_regs state;
280 struct radeon_regs init_state;
282 char name[DEVICE_NAME_SIZE];
284 unsigned long mmio_base_phys;
285 unsigned long fb_base_phys;
287 void __iomem *mmio_base;
288 void __iomem *fb_base;
290 unsigned long fb_local_base;
292 struct pci_dev *pdev;
294 struct device_node *of_node;
297 void __iomem *bios_seg;
300 u32 pseudo_palette[17];
301 struct { u8 red, green, blue, pad; }
308 unsigned long video_ram;
309 unsigned long mapped_vram;
313 int pitch, bpp, depth;
320 struct panel_info panel_info;
323 struct fb_videomode *mon1_modedb;
328 u32 dp_gui_master_cntl;
340 enum radeon_pm_mode pm_mode;
341 void (*reinit_func)(struct radeonfb_info *rinfo);
343 /* Lock on register access */
346 /* Timer used for delayed LVDS operations */
347 struct timer_list lvds_timer;
348 u32 pending_lvds_gen_cntl;
350 #ifdef CONFIG_FB_RADEON_I2C
351 struct radeon_i2c_chan i2c[4];
358 #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
364 #ifdef CONFIG_FB_RADEON_DEBUG
371 #define RTRACE printk
373 #define RTRACE if(0) printk
381 /* Note about this function: we have some rare cases where we must not schedule,
382 * this typically happen with our special "wake up early" hook which allows us to
383 * wake up the graphic chip (and thus get the console back) before everything else
384 * on some machines that support that mecanism. At this point, interrupts are off
385 * and scheduling is not permitted
387 static inline void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms)
389 if (rinfo->no_schedule || oops_in_progress)
396 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
397 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
398 #define INREG16(addr) readw((rinfo->mmio_base)+addr)
399 #define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr)
400 #define INREG(addr) readl((rinfo->mmio_base)+addr)
401 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
403 static inline void _OUTREGP(struct radeonfb_info *rinfo, u32 addr,
409 spin_lock_irqsave(&rinfo->reg_lock, flags);
414 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
417 #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
420 * Note about PLL register accesses:
422 * I have removed the spinlock on them on purpose. The driver now
423 * expects that it will only manipulate the PLL registers in normal
424 * task environment, where radeon_msleep() will be called, protected
425 * by a semaphore (currently the console semaphore) so that no conflict
426 * will happen on the PLL register index.
428 * With the latest changes to the VT layer, this is guaranteed for all
429 * calls except the actual drawing/blits which aren't supposed to use
430 * the PLL registers anyway
432 * This is very important for the workarounds to work properly. The only
433 * possible exception to this rule is the call to unblank(), which may
434 * be done at irq time if an oops is in progress.
436 static inline void radeon_pll_errata_after_index(struct radeonfb_info *rinfo)
438 if (!(rinfo->errata & CHIP_ERRATA_PLL_DUMMYREADS))
441 (void)INREG(CLOCK_CNTL_DATA);
442 (void)INREG(CRTC_GEN_CNTL);
445 static inline void radeon_pll_errata_after_data(struct radeonfb_info *rinfo)
447 if (rinfo->errata & CHIP_ERRATA_PLL_DELAY) {
448 /* we can't deal with posted writes here ... */
449 _radeon_msleep(rinfo, 5);
451 if (rinfo->errata & CHIP_ERRATA_R300_CG) {
453 save = INREG(CLOCK_CNTL_INDEX);
454 tmp = save & ~(0x3f | PLL_WR_EN);
455 OUTREG(CLOCK_CNTL_INDEX, tmp);
456 tmp = INREG(CLOCK_CNTL_DATA);
457 OUTREG(CLOCK_CNTL_INDEX, save);
461 static inline u32 __INPLL(struct radeonfb_info *rinfo, u32 addr)
465 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
466 radeon_pll_errata_after_index(rinfo);
467 data = INREG(CLOCK_CNTL_DATA);
468 radeon_pll_errata_after_data(rinfo);
472 static inline void __OUTPLL(struct radeonfb_info *rinfo, unsigned int index,
476 OUTREG8(CLOCK_CNTL_INDEX, (index & 0x0000003f) | 0x00000080);
477 radeon_pll_errata_after_index(rinfo);
478 OUTREG(CLOCK_CNTL_DATA, val);
479 radeon_pll_errata_after_data(rinfo);
483 static inline void __OUTPLLP(struct radeonfb_info *rinfo, unsigned int index,
488 tmp = __INPLL(rinfo, index);
491 __OUTPLL(rinfo, index, tmp);
495 #define INPLL(addr) __INPLL(rinfo, addr)
496 #define OUTPLL(index, val) __OUTPLL(rinfo, index, val)
497 #define OUTPLLP(index, val, mask) __OUTPLLP(rinfo, index, val, mask)
500 #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
501 #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
502 (readb(rinfo->bios_seg + (v) + 1) << 8))
503 #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
504 (readb(rinfo->bios_seg + (v) + 1) << 8) | \
505 (readb(rinfo->bios_seg + (v) + 2) << 16) | \
506 (readb(rinfo->bios_seg + (v) + 3) << 24))
511 static inline int round_div(int num, int den)
513 return (num + (den / 2)) / den;
516 static inline int var_to_depth(const struct fb_var_screeninfo *var)
518 if (var->bits_per_pixel != 16)
519 return var->bits_per_pixel;
520 return (var->green.length == 5) ? 15 : 16;
523 static inline u32 radeon_get_dstbpp(u16 depth)
540 * 2D Engine helper routines
542 static inline void radeon_engine_flush (struct radeonfb_info *rinfo)
547 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
550 for (i=0; i < 2000000; i++) {
551 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
555 printk(KERN_ERR "radeonfb: Flush Timeout !\n");
559 static inline void _radeon_fifo_wait(struct radeonfb_info *rinfo, int entries)
563 for (i=0; i<2000000; i++) {
564 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
568 printk(KERN_ERR "radeonfb: FIFO Timeout !\n");
572 static inline void _radeon_engine_idle(struct radeonfb_info *rinfo)
576 /* ensure FIFO is empty before waiting for idle */
577 _radeon_fifo_wait (rinfo, 64);
579 for (i=0; i<2000000; i++) {
580 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
581 radeon_engine_flush (rinfo);
586 printk(KERN_ERR "radeonfb: Idle Timeout !\n");
590 #define radeon_engine_idle() _radeon_engine_idle(rinfo)
591 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
592 #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
596 extern void radeon_create_i2c_busses(struct radeonfb_info *rinfo);
597 extern void radeon_delete_i2c_busses(struct radeonfb_info *rinfo);
598 extern int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid);
601 extern int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state);
602 extern int radeonfb_pci_resume(struct pci_dev *pdev);
603 extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk);
604 extern void radeonfb_pm_exit(struct radeonfb_info *rinfo);
606 /* Monitor probe functions */
607 extern void radeon_probe_screens(struct radeonfb_info *rinfo,
608 const char *monitor_layout, int ignore_edid);
609 extern void radeon_check_modes(struct radeonfb_info *rinfo, const char *mode_option);
610 extern int radeon_match_mode(struct radeonfb_info *rinfo,
611 struct fb_var_screeninfo *dest,
612 const struct fb_var_screeninfo *src);
614 /* Accel functions */
615 extern void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region);
616 extern void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
617 extern void radeonfb_imageblit(struct fb_info *p, const struct fb_image *image);
618 extern int radeonfb_sync(struct fb_info *info);
619 extern void radeonfb_engine_init (struct radeonfb_info *rinfo);
620 extern void radeonfb_engine_reset(struct radeonfb_info *rinfo);
622 /* Other functions */
623 extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch);
624 extern void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
627 #endif /* __RADEONFB_H__ */