1 /* SPDX-License-Identifier: GPL-2.0 */
5 #ifdef CONFIG_FB_RADEON_DEBUG
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/delay.h>
13 #include <linux/pci.h>
17 #ifdef CONFIG_FB_RADEON_I2C
18 #include <linux/i2c.h>
19 #include <linux/i2c-algo-bit.h>
24 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
28 #include <video/radeon.h>
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 */
62 #define IS_RV100_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_RV100) || \
63 ((rinfo)->family == CHIP_FAMILY_RV200) || \
64 ((rinfo)->family == CHIP_FAMILY_RS100) || \
65 ((rinfo)->family == CHIP_FAMILY_RS200) || \
66 ((rinfo)->family == CHIP_FAMILY_RV250) || \
67 ((rinfo)->family == CHIP_FAMILY_RV280) || \
68 ((rinfo)->family == CHIP_FAMILY_RS300))
71 #define IS_R300_VARIANT(rinfo) (((rinfo)->family == CHIP_FAMILY_R300) || \
72 ((rinfo)->family == CHIP_FAMILY_RV350) || \
73 ((rinfo)->family == CHIP_FAMILY_R350) || \
74 ((rinfo)->family == CHIP_FAMILY_RV380) || \
75 ((rinfo)->family == CHIP_FAMILY_R420) || \
76 ((rinfo)->family == CHIP_FAMILY_RC410) || \
77 ((rinfo)->family == CHIP_FAMILY_RS480))
82 enum radeon_chip_flags
{
83 CHIP_FAMILY_MASK
= 0x0000ffffUL
,
84 CHIP_FLAGS_MASK
= 0xffff0000UL
,
85 CHIP_IS_MOBILITY
= 0x00010000UL
,
86 CHIP_IS_IGP
= 0x00020000UL
,
87 CHIP_HAS_CRTC2
= 0x00040000UL
,
94 CHIP_ERRATA_R300_CG
= 0x00000001,
95 CHIP_ERRATA_PLL_DUMMYREADS
= 0x00000002,
96 CHIP_ERRATA_PLL_DELAY
= 0x00000004,
103 enum radeon_montype
{
108 MT_CTV
, /* composite TV */
109 MT_STV
/* S-Video out */
148 * This structure contains the various registers manipulated by this
149 * driver for setting or restoring a mode. It's mostly copied from
150 * XFree's RADEONSaveRec structure. A few chip settings might still be
151 * tweaked without beeing reflected or saved in these registers though
154 /* Common registers */
156 u32 ovr_wid_left_right
;
157 u32 ovr_wid_top_bottom
;
171 /* Other registers to save for VT switches or driver load/unload */
174 u32 clock_cntl_index
;
178 /* Surface/tiling registers */
179 u32 surf_lower_bound
[8];
180 u32 surf_upper_bound
[8];
187 u32 crtc_h_total_disp
;
188 u32 crtc_h_sync_strt_wid
;
189 u32 crtc_v_total_disp
;
190 u32 crtc_v_sync_strt_wid
;
192 u32 crtc_offset_cntl
;
195 u32 grph_buffer_cntl
;
198 /* CRTC2 registers */
201 u32 disp_output_cntl
;
203 u32 disp2_merge_cntl
;
204 u32 grph2_buffer_cntl
;
205 u32 crtc2_h_total_disp
;
206 u32 crtc2_h_sync_strt_wid
;
207 u32 crtc2_v_total_disp
;
208 u32 crtc2_v_sync_strt_wid
;
210 u32 crtc2_offset_cntl
;
213 /* Flat panel regs */
214 u32 fp_crtc_h_total_disp
;
215 u32 fp_crtc_v_total_disp
;
218 u32 fp_h_sync_strt_wid
;
219 u32 fp2_h_sync_strt_wid
;
222 u32 fp_v_sync_strt_wid
;
223 u32 fp2_v_sync_strt_wid
;
228 u32 tmds_transmitter_cntl
;
230 /* Computed values for PLL */
241 /* Computed values for PLL2 */
242 u32 dot_clock_freq_2
;
259 int hOver_plus
, hSync_width
, hblank
;
260 int vOver_plus
, vSync_width
, vblank
;
261 int hAct_high
, vAct_high
, interlaced
;
263 int use_bios_dividers
;
269 struct radeonfb_info
;
271 #ifdef CONFIG_FB_RADEON_I2C
272 struct radeon_i2c_chan
{
273 struct radeonfb_info
*rinfo
;
275 struct i2c_adapter adapter
;
276 struct i2c_algo_bit_data algo
;
280 enum radeon_pm_mode
{
281 radeon_pm_none
= 0, /* Nothing supported */
282 radeon_pm_d2
= 0x00000001, /* Can do D2 state */
283 radeon_pm_off
= 0x00000002, /* Can resume from D3 cold */
286 typedef void (*reinit_function_ptr
)(struct radeonfb_info
*rinfo
);
288 struct radeonfb_info
{
289 struct fb_info
*info
;
291 struct radeon_regs state
;
292 struct radeon_regs init_state
;
296 unsigned long mmio_base_phys
;
297 unsigned long fb_base_phys
;
299 void __iomem
*mmio_base
;
300 void __iomem
*fb_base
;
302 unsigned long fb_local_base
;
304 struct pci_dev
*pdev
;
305 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
306 struct device_node
*of_node
;
309 void __iomem
*bios_seg
;
312 u32 pseudo_palette
[16];
313 struct { u8 red
, green
, blue
, pad
; }
320 unsigned long video_ram
;
321 unsigned long mapped_vram
;
325 int pitch
, bpp
, depth
;
332 struct panel_info panel_info
;
335 struct fb_videomode
*mon1_modedb
;
340 u32 dp_gui_master_cntl
;
351 enum radeon_pm_mode pm_mode
;
352 reinit_function_ptr reinit_func
;
354 /* Lock on register access */
357 /* Timer used for delayed LVDS operations */
358 struct timer_list lvds_timer
;
359 u32 pending_lvds_gen_cntl
;
361 #ifdef CONFIG_FB_RADEON_I2C
362 struct radeon_i2c_chan i2c
[4];
367 #define PRIMARY_MONITOR(rinfo) (rinfo->mon1_type)
374 void _radeon_msleep(struct radeonfb_info
*rinfo
, unsigned long ms
);
376 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
377 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
378 #define INREG16(addr) readw((rinfo->mmio_base)+addr)
379 #define OUTREG16(addr,val) writew(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 void _OUTREGP(struct radeonfb_info
*rinfo
, u32 addr
, u32 val
, u32 mask
);
385 #define OUTREGP(addr,val,mask) _OUTREGP(rinfo, addr, val,mask)
388 * Note about PLL register accesses:
390 * I have removed the spinlock on them on purpose. The driver now
391 * expects that it will only manipulate the PLL registers in normal
392 * task environment, where radeon_msleep() will be called, protected
393 * by a semaphore (currently the console semaphore) so that no conflict
394 * will happen on the PLL register index.
396 * With the latest changes to the VT layer, this is guaranteed for all
397 * calls except the actual drawing/blits which aren't supposed to use
398 * the PLL registers anyway
400 * This is very important for the workarounds to work properly. The only
401 * possible exception to this rule is the call to unblank(), which may
402 * be done at irq time if an oops is in progress.
404 void radeon_pll_errata_after_index_slow(struct radeonfb_info
*rinfo
);
405 static inline void radeon_pll_errata_after_index(struct radeonfb_info
*rinfo
)
407 if (rinfo
->errata
& CHIP_ERRATA_PLL_DUMMYREADS
)
408 radeon_pll_errata_after_index_slow(rinfo
);
411 void radeon_pll_errata_after_data_slow(struct radeonfb_info
*rinfo
);
412 static inline void radeon_pll_errata_after_data(struct radeonfb_info
*rinfo
)
414 if (rinfo
->errata
& (CHIP_ERRATA_PLL_DELAY
|CHIP_ERRATA_R300_CG
))
415 radeon_pll_errata_after_data_slow(rinfo
);
418 u32
__INPLL(struct radeonfb_info
*rinfo
, u32 addr
);
419 void __OUTPLL(struct radeonfb_info
*rinfo
, unsigned int index
, u32 val
);
420 void __OUTPLLP(struct radeonfb_info
*rinfo
, unsigned int index
,
423 #define INPLL(addr) __INPLL(rinfo, addr)
424 #define OUTPLL(index, val) __OUTPLL(rinfo, index, val)
425 #define OUTPLLP(index, val, mask) __OUTPLLP(rinfo, index, val, mask)
428 #define BIOS_IN8(v) (readb(rinfo->bios_seg + (v)))
429 #define BIOS_IN16(v) (readb(rinfo->bios_seg + (v)) | \
430 (readb(rinfo->bios_seg + (v) + 1) << 8))
431 #define BIOS_IN32(v) (readb(rinfo->bios_seg + (v)) | \
432 (readb(rinfo->bios_seg + (v) + 1) << 8) | \
433 (readb(rinfo->bios_seg + (v) + 2) << 16) | \
434 (readb(rinfo->bios_seg + (v) + 3) << 24))
439 static inline int round_div(int num
, int den
)
441 return (num
+ (den
/ 2)) / den
;
444 static inline int var_to_depth(const struct fb_var_screeninfo
*var
)
446 if (var
->bits_per_pixel
!= 16)
447 return var
->bits_per_pixel
;
448 return (var
->green
.length
== 5) ? 15 : 16;
451 static inline u32
radeon_get_dstbpp(u16 depth
)
468 * 2D Engine helper routines
471 void _radeon_fifo_wait(struct radeonfb_info
*rinfo
, int entries
);
472 void radeon_engine_flush(struct radeonfb_info
*rinfo
);
473 void _radeon_engine_idle(struct radeonfb_info
*rinfo
);
475 #define radeon_engine_idle() _radeon_engine_idle(rinfo)
476 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
477 #define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
481 extern void radeon_create_i2c_busses(struct radeonfb_info
*rinfo
);
482 extern void radeon_delete_i2c_busses(struct radeonfb_info
*rinfo
);
483 extern int radeon_probe_i2c_connector(struct radeonfb_info
*rinfo
, int conn
, u8
**out_edid
);
486 extern int radeonfb_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
);
487 extern int radeonfb_pci_resume(struct pci_dev
*pdev
);
488 extern void radeonfb_pm_init(struct radeonfb_info
*rinfo
, int dynclk
, int ignore_devlist
, int force_sleep
);
489 extern void radeonfb_pm_exit(struct radeonfb_info
*rinfo
);
491 /* Monitor probe functions */
492 extern void radeon_probe_screens(struct radeonfb_info
*rinfo
,
493 const char *monitor_layout
, int ignore_edid
);
494 extern void radeon_check_modes(struct radeonfb_info
*rinfo
, const char *mode_option
);
495 extern int radeon_match_mode(struct radeonfb_info
*rinfo
,
496 struct fb_var_screeninfo
*dest
,
497 const struct fb_var_screeninfo
*src
);
499 /* Accel functions */
500 extern void radeonfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*region
);
501 extern void radeonfb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
);
502 extern void radeonfb_imageblit(struct fb_info
*p
, const struct fb_image
*image
);
503 extern int radeonfb_sync(struct fb_info
*info
);
504 extern void radeonfb_engine_init (struct radeonfb_info
*rinfo
);
505 extern void radeonfb_engine_reset(struct radeonfb_info
*rinfo
);
507 /* Other functions */
508 extern int radeon_screen_blank(struct radeonfb_info
*rinfo
, int blank
, int mode_switch
);
509 extern void radeon_write_mode (struct radeonfb_info
*rinfo
, struct radeon_regs
*mode
,
512 /* Backlight functions */
513 #ifdef CONFIG_FB_RADEON_BACKLIGHT
514 extern void radeonfb_bl_init(struct radeonfb_info
*rinfo
);
515 extern void radeonfb_bl_exit(struct radeonfb_info
*rinfo
);
517 static inline void radeonfb_bl_init(struct radeonfb_info
*rinfo
) {}
518 static inline void radeonfb_bl_exit(struct radeonfb_info
*rinfo
) {}
521 #endif /* __RADEONFB_H__ */