2 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3 * VA Linux Systems Inc., Fremont, California.
4 * Copyright 2008 Red Hat Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 * Kevin E. Martin, Rickard E. Faith, Alan Hourihane
27 * Kernel port Author: Dave Airlie
36 #include <drm_dp_helper.h>
37 #include <linux/i2c.h>
38 #include <linux/i2c-id.h>
39 #include <linux/i2c-algo-bit.h>
40 #include "radeon_fixed.h"
44 #define to_radeon_crtc(x) container_of(x, struct radeon_crtc, base)
45 #define to_radeon_connector(x) container_of(x, struct radeon_connector, base)
46 #define to_radeon_encoder(x) container_of(x, struct radeon_encoder, base)
47 #define to_radeon_framebuffer(x) container_of(x, struct radeon_framebuffer, base)
49 enum radeon_connector_type {
60 CONNECTOR_HDMI_TYPE_A,
61 CONNECTOR_HDMI_TYPE_B,
65 CONNECTOR_DISPLAY_PORT,
69 enum radeon_dvi_type {
75 enum radeon_rmx_type {
93 /* radeon gpio-based i2c
94 * 1. "mask" reg and bits
95 * grabs the gpio pins for software use
100 * 3. "en" reg and bits
101 * sets the pin direction
103 * 4. "y" reg and bits
107 struct radeon_i2c_bus_rec {
109 /* id used by atom */
111 /* can be used with hw i2c engine */
113 /* uses multi-media i2c engine */
116 uint32_t mask_clk_reg;
117 uint32_t mask_data_reg;
121 uint32_t en_data_reg;
124 uint32_t mask_clk_mask;
125 uint32_t mask_data_mask;
127 uint32_t a_data_mask;
128 uint32_t en_clk_mask;
129 uint32_t en_data_mask;
131 uint32_t y_data_mask;
134 struct radeon_tmds_pll {
139 #define RADEON_MAX_BIOS_CONNECTOR 16
141 #define RADEON_PLL_USE_BIOS_DIVS (1 << 0)
142 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
143 #define RADEON_PLL_USE_REF_DIV (1 << 2)
144 #define RADEON_PLL_LEGACY (1 << 3)
145 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
146 #define RADEON_PLL_PREFER_HIGH_REF_DIV (1 << 5)
147 #define RADEON_PLL_PREFER_LOW_FB_DIV (1 << 6)
148 #define RADEON_PLL_PREFER_HIGH_FB_DIV (1 << 7)
149 #define RADEON_PLL_PREFER_LOW_POST_DIV (1 << 8)
150 #define RADEON_PLL_PREFER_HIGH_POST_DIV (1 << 9)
151 #define RADEON_PLL_USE_FRAC_FB_DIV (1 << 10)
152 #define RADEON_PLL_PREFER_CLOSEST_LOWER (1 << 11)
155 uint16_t reference_freq;
156 uint16_t reference_div;
159 uint32_t pll_out_min;
160 uint32_t pll_out_max;
163 uint32_t min_ref_div;
164 uint32_t max_ref_div;
165 uint32_t min_post_div;
166 uint32_t max_post_div;
167 uint32_t min_feedback_div;
168 uint32_t max_feedback_div;
169 uint32_t min_frac_feedback_div;
170 uint32_t max_frac_feedback_div;
174 struct radeon_i2c_chan {
175 struct i2c_adapter adapter;
176 struct drm_device *dev;
178 struct i2c_algo_dp_aux_data dp;
179 struct i2c_algo_bit_data bit;
181 struct radeon_i2c_bus_rec rec;
184 /* mostly for macs, but really any system without connector tables */
185 enum radeon_connector_table {
189 CT_POWERBOOK_EXTERNAL,
190 CT_POWERBOOK_INTERNAL,
198 enum radeon_dvo_chip {
203 struct radeon_mode_info {
204 struct atom_context *atom_context;
205 struct card_info *atom_card_info;
206 enum radeon_connector_table connector_table;
207 bool mode_config_initialized;
208 struct radeon_crtc *crtcs[2];
209 /* DVI-I properties */
210 struct drm_property *coherent_mode_property;
211 /* DAC enable load detect */
212 struct drm_property *load_detect_property;
213 /* TV standard load detect */
214 struct drm_property *tv_std_property;
215 /* legacy TMDS PLL detect */
216 struct drm_property *tmds_pll_property;
220 #define MAX_H_CODE_TIMING_LEN 32
221 #define MAX_V_CODE_TIMING_LEN 32
223 /* need to store these as reading
224 back code tables is excessive */
225 struct radeon_tv_regs {
227 uint32_t timing_cntl;
231 uint16_t h_code_timing[MAX_H_CODE_TIMING_LEN];
232 uint16_t v_code_timing[MAX_V_CODE_TIMING_LEN];
236 struct drm_crtc base;
238 u16 lut_r[256], lut_g[256], lut_b[256];
241 uint32_t crtc_offset;
242 struct drm_gem_object *cursor_bo;
243 uint64_t cursor_addr;
246 uint32_t legacy_display_base_addr;
247 uint32_t legacy_cursor_offset;
248 enum radeon_rmx_type rmx_type;
251 struct drm_display_mode native_mode;
254 struct radeon_encoder_primary_dac {
255 /* legacy primary dac */
256 uint32_t ps2_pdac_adj;
259 struct radeon_encoder_lvds {
261 uint16_t panel_vcc_delay;
262 uint8_t panel_pwr_delay;
263 uint8_t panel_digon_delay;
264 uint8_t panel_blon_delay;
265 uint16_t panel_ref_divider;
266 uint8_t panel_post_divider;
267 uint16_t panel_fb_divider;
268 bool use_bios_dividers;
269 uint32_t lvds_gen_cntl;
271 struct drm_display_mode native_mode;
274 struct radeon_encoder_tv_dac {
276 uint32_t ps2_tvdac_adj;
277 uint32_t ntsc_tvdac_adj;
278 uint32_t pal_tvdac_adj;
283 int supported_tv_stds;
285 enum radeon_tv_std tv_std;
286 struct radeon_tv_regs tv;
289 struct radeon_encoder_int_tmds {
290 /* legacy int tmds */
291 struct radeon_tmds_pll tmds_pll[4];
294 struct radeon_encoder_ext_tmds {
296 struct radeon_i2c_chan *i2c_bus;
298 enum radeon_dvo_chip dvo_chip;
301 /* spread spectrum */
302 struct radeon_atom_ss {
311 struct radeon_encoder_atom_dig {
317 uint16_t panel_pwr_delay;
318 struct radeon_atom_ss *ss;
320 struct drm_display_mode native_mode;
323 struct radeon_encoder_atom_dac {
324 enum radeon_tv_std tv_std;
327 struct radeon_encoder {
328 struct drm_encoder base;
331 uint32_t active_device;
333 uint32_t pixel_clock;
334 enum radeon_rmx_type rmx_type;
335 struct drm_display_mode native_mode;
339 struct radeon_connector_atom_dig {
340 uint32_t igp_lane_info;
343 struct radeon_i2c_chan *dp_i2c_bus;
350 struct radeon_gpio_rec {
368 enum radeon_hpd_id hpd;
370 struct radeon_gpio_rec gpio;
373 struct radeon_connector {
374 struct drm_connector base;
375 uint32_t connector_id;
377 struct radeon_i2c_chan *ddc_bus;
378 /* some systems have a an hdmi and vga port with a shared ddc line */
381 /* we need to mind the EDID between detect
382 and get modes due to analog/digital/tvencoder */
385 bool dac_load_detect;
386 uint16_t connector_object_id;
387 struct radeon_hpd hpd;
390 struct radeon_framebuffer {
391 struct drm_framebuffer base;
392 struct drm_gem_object *obj;
395 extern void radeon_connector_hotplug(struct drm_connector *connector);
396 extern bool radeon_dp_needs_link_train(struct radeon_connector *radeon_connector);
397 extern int radeon_dp_mode_valid_helper(struct radeon_connector *radeon_connector,
398 struct drm_display_mode *mode);
399 extern void radeon_dp_set_link_config(struct drm_connector *connector,
400 struct drm_display_mode *mode);
401 extern void dp_link_train(struct drm_encoder *encoder,
402 struct drm_connector *connector);
403 extern u8 radeon_dp_getsinktype(struct radeon_connector *radeon_connector);
404 extern bool radeon_dp_getdpcd(struct radeon_connector *radeon_connector);
405 extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
406 int action, uint8_t lane_num,
408 extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
409 uint8_t write_byte, uint8_t *read_byte);
411 extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
412 struct radeon_i2c_bus_rec *rec,
414 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
415 struct radeon_i2c_bus_rec *rec,
417 extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
418 extern void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus,
422 extern void radeon_i2c_sw_put_byte(struct radeon_i2c_chan *i2c,
426 extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
427 extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
429 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
431 extern void radeon_compute_pll(struct radeon_pll *pll,
433 uint32_t *dot_clock_p,
435 uint32_t *frac_fb_div_p,
437 uint32_t *post_div_p,
440 extern void radeon_setup_encoder_clones(struct drm_device *dev);
442 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index);
443 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int with_tv);
444 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
445 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
446 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
447 extern void atombios_external_tmds_setup(struct drm_encoder *encoder, int action);
448 extern void atombios_digital_setup(struct drm_encoder *encoder, int action);
449 extern int atombios_get_encoder_mode(struct drm_encoder *encoder);
450 extern void radeon_encoder_set_active_device(struct drm_encoder *encoder);
452 extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
453 extern int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y,
454 struct drm_framebuffer *old_fb);
455 extern int atombios_crtc_mode_set(struct drm_crtc *crtc,
456 struct drm_display_mode *mode,
457 struct drm_display_mode *adjusted_mode,
459 struct drm_framebuffer *old_fb);
460 extern void atombios_crtc_dpms(struct drm_crtc *crtc, int mode);
462 extern int radeon_crtc_set_base(struct drm_crtc *crtc, int x, int y,
463 struct drm_framebuffer *old_fb);
464 extern void radeon_legacy_atom_set_surface(struct drm_crtc *crtc);
466 extern int radeon_crtc_cursor_set(struct drm_crtc *crtc,
467 struct drm_file *file_priv,
471 extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
474 extern bool radeon_atom_get_clock_info(struct drm_device *dev);
475 extern bool radeon_combios_get_clock_info(struct drm_device *dev);
476 extern struct radeon_encoder_atom_dig *
477 radeon_atombios_get_lvds_info(struct radeon_encoder *encoder);
478 extern bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
479 struct radeon_encoder_int_tmds *tmds);
480 extern bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
481 struct radeon_encoder_int_tmds *tmds);
482 extern bool radeon_legacy_get_tmds_info_from_table(struct radeon_encoder *encoder,
483 struct radeon_encoder_int_tmds *tmds);
484 extern bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder,
485 struct radeon_encoder_ext_tmds *tmds);
486 extern bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
487 struct radeon_encoder_ext_tmds *tmds);
488 extern struct radeon_encoder_primary_dac *
489 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder);
490 extern struct radeon_encoder_tv_dac *
491 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder);
492 extern struct radeon_encoder_lvds *
493 radeon_combios_get_lvds_info(struct radeon_encoder *encoder);
494 extern void radeon_combios_get_ext_tmds_info(struct radeon_encoder *encoder);
495 extern struct radeon_encoder_tv_dac *
496 radeon_combios_get_tv_dac_info(struct radeon_encoder *encoder);
497 extern struct radeon_encoder_primary_dac *
498 radeon_combios_get_primary_dac_info(struct radeon_encoder *encoder);
499 extern bool radeon_combios_external_tmds_setup(struct drm_encoder *encoder);
500 extern void radeon_external_tmds_setup(struct drm_encoder *encoder);
501 extern void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock);
502 extern void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev);
503 extern void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock);
504 extern void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev);
505 extern void radeon_save_bios_scratch_regs(struct radeon_device *rdev);
506 extern void radeon_restore_bios_scratch_regs(struct radeon_device *rdev);
508 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
510 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
512 radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
514 radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
515 extern void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
516 u16 blue, int regno);
517 extern void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
518 u16 *blue, int regno);
519 struct drm_framebuffer *radeon_framebuffer_create(struct drm_device *dev,
520 struct drm_mode_fb_cmd *mode_cmd,
521 struct drm_gem_object *obj);
523 int radeonfb_probe(struct drm_device *dev);
525 int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
526 bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev);
527 bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev);
528 void radeon_atombios_init_crtc(struct drm_device *dev,
529 struct radeon_crtc *radeon_crtc);
530 void radeon_legacy_init_crtc(struct drm_device *dev,
531 struct radeon_crtc *radeon_crtc);
532 extern void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state);
534 void radeon_get_clock_info(struct drm_device *dev);
536 extern bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev);
537 extern bool radeon_get_atom_connector_info_from_supported_devices_table(struct drm_device *dev);
539 void radeon_enc_destroy(struct drm_encoder *encoder);
540 void radeon_copy_fb(struct drm_device *dev, struct drm_gem_object *dst_obj);
541 void radeon_combios_asic_init(struct drm_device *dev);
542 extern int radeon_static_clocks_init(struct drm_device *dev);
543 bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
544 struct drm_display_mode *mode,
545 struct drm_display_mode *adjusted_mode);
546 void atom_rv515_force_tv_scaler(struct radeon_device *rdev, struct radeon_crtc *radeon_crtc);
549 void radeon_legacy_tv_adjust_crtc_reg(struct drm_encoder *encoder,
550 uint32_t *h_total_disp, uint32_t *h_sync_strt_wid,
551 uint32_t *v_total_disp, uint32_t *v_sync_strt_wid);
552 void radeon_legacy_tv_adjust_pll1(struct drm_encoder *encoder,
553 uint32_t *htotal_cntl, uint32_t *ppll_ref_div,
554 uint32_t *ppll_div_3, uint32_t *pixclks_cntl);
555 void radeon_legacy_tv_adjust_pll2(struct drm_encoder *encoder,
556 uint32_t *htotal2_cntl, uint32_t *p2pll_ref_div,
557 uint32_t *p2pll_div_0, uint32_t *pixclks_cntl);
558 void radeon_legacy_tv_mode_set(struct drm_encoder *encoder,
559 struct drm_display_mode *mode,
560 struct drm_display_mode *adjusted_mode);