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 <linux/i2c.h>
37 #include <linux/i2c-id.h>
38 #include <linux/i2c-algo-bit.h>
40 #define to_radeon_crtc(x) container_of(x, struct radeon_crtc, base)
41 #define to_radeon_connector(x) container_of(x, struct radeon_connector, base)
42 #define to_radeon_encoder(x) container_of(x, struct radeon_encoder, base)
43 #define to_radeon_framebuffer(x) container_of(x, struct radeon_framebuffer, base)
45 enum radeon_connector_type {
56 CONNECTOR_HDMI_TYPE_A,
57 CONNECTOR_HDMI_TYPE_B,
61 CONNECTOR_DISPLAY_PORT,
65 enum radeon_dvi_type {
71 enum radeon_rmx_type {
89 struct radeon_i2c_bus_rec {
91 uint32_t mask_clk_reg;
92 uint32_t mask_data_reg;
96 uint32_t put_data_reg;
98 uint32_t get_data_reg;
99 uint32_t mask_clk_mask;
100 uint32_t mask_data_mask;
101 uint32_t put_clk_mask;
102 uint32_t put_data_mask;
103 uint32_t get_clk_mask;
104 uint32_t get_data_mask;
106 uint32_t a_data_mask;
109 struct radeon_tmds_pll {
114 #define RADEON_MAX_BIOS_CONNECTOR 16
116 #define RADEON_PLL_USE_BIOS_DIVS (1 << 0)
117 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
118 #define RADEON_PLL_USE_REF_DIV (1 << 2)
119 #define RADEON_PLL_LEGACY (1 << 3)
120 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
121 #define RADEON_PLL_PREFER_HIGH_REF_DIV (1 << 5)
122 #define RADEON_PLL_PREFER_LOW_FB_DIV (1 << 6)
123 #define RADEON_PLL_PREFER_HIGH_FB_DIV (1 << 7)
124 #define RADEON_PLL_PREFER_LOW_POST_DIV (1 << 8)
125 #define RADEON_PLL_PREFER_HIGH_POST_DIV (1 << 9)
126 #define RADEON_PLL_USE_FRAC_FB_DIV (1 << 10)
129 uint16_t reference_freq;
130 uint16_t reference_div;
133 uint32_t pll_out_min;
134 uint32_t pll_out_max;
137 uint32_t min_ref_div;
138 uint32_t max_ref_div;
139 uint32_t min_post_div;
140 uint32_t max_post_div;
141 uint32_t min_feedback_div;
142 uint32_t max_feedback_div;
143 uint32_t min_frac_feedback_div;
144 uint32_t max_frac_feedback_div;
148 struct radeon_i2c_chan {
149 struct drm_device *dev;
150 struct i2c_adapter adapter;
151 struct i2c_algo_bit_data algo;
152 struct radeon_i2c_bus_rec rec;
155 /* mostly for macs, but really any system without connector tables */
156 enum radeon_connector_table {
160 CT_POWERBOOK_EXTERNAL,
161 CT_POWERBOOK_INTERNAL,
169 struct radeon_mode_info {
170 struct atom_context *atom_context;
171 enum radeon_connector_table connector_table;
172 bool mode_config_initialized;
176 struct drm_crtc base;
178 u16 lut_r[256], lut_g[256], lut_b[256];
181 uint32_t crtc_offset;
182 struct radeon_framebuffer *fbdev_fb;
183 struct drm_mode_set mode_set;
184 struct drm_gem_object *cursor_bo;
185 uint64_t cursor_addr;
190 #define RADEON_USE_RMX 1
192 struct radeon_native_mode {
194 uint32_t panel_xres, panel_yres;
195 uint32_t hoverplus, hsync_width;
197 uint32_t voverplus, vsync_width;
203 struct radeon_encoder_primary_dac {
204 /* legacy primary dac */
205 uint32_t ps2_pdac_adj;
208 struct radeon_encoder_lvds {
210 uint16_t panel_vcc_delay;
211 uint8_t panel_pwr_delay;
212 uint8_t panel_digon_delay;
213 uint8_t panel_blon_delay;
214 uint16_t panel_ref_divider;
215 uint8_t panel_post_divider;
216 uint16_t panel_fb_divider;
217 bool use_bios_dividers;
218 uint32_t lvds_gen_cntl;
220 struct radeon_native_mode native_mode;
223 struct radeon_encoder_tv_dac {
225 uint32_t ps2_tvdac_adj;
226 uint32_t ntsc_tvdac_adj;
227 uint32_t pal_tvdac_adj;
229 enum radeon_tv_std tv_std;
232 struct radeon_encoder_int_tmds {
233 /* legacy int tmds */
234 struct radeon_tmds_pll tmds_pll[4];
237 struct radeon_encoder_atom_dig {
243 uint16_t panel_pwr_delay;
245 struct radeon_native_mode native_mode;
248 struct radeon_encoder {
249 struct drm_encoder base;
253 uint32_t pixel_clock;
254 enum radeon_rmx_type rmx_type;
255 struct radeon_native_mode native_mode;
259 struct radeon_connector_atom_dig {
260 uint32_t igp_lane_info;
264 struct radeon_connector {
265 struct drm_connector base;
266 uint32_t connector_id;
268 struct radeon_i2c_chan *ddc_bus;
273 struct radeon_framebuffer {
274 struct drm_framebuffer base;
275 struct drm_gem_object *obj;
278 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
279 struct radeon_i2c_bus_rec *rec,
281 extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
282 extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
283 extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
285 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
287 extern void radeon_compute_pll(struct radeon_pll *pll,
289 uint32_t *dot_clock_p,
291 uint32_t *frac_fb_div_p,
293 uint32_t *post_div_p,
296 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index);
297 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int with_tv);
298 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
299 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
300 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
301 extern void atombios_external_tmds_setup(struct drm_encoder *encoder, int action);
302 extern int atombios_get_encoder_mode(struct drm_encoder *encoder);
304 extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
305 extern int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y,
306 struct drm_framebuffer *old_fb);
307 extern int atombios_crtc_mode_set(struct drm_crtc *crtc,
308 struct drm_display_mode *mode,
309 struct drm_display_mode *adjusted_mode,
311 struct drm_framebuffer *old_fb);
312 extern void atombios_crtc_dpms(struct drm_crtc *crtc, int mode);
314 extern int radeon_crtc_set_base(struct drm_crtc *crtc, int x, int y,
315 struct drm_framebuffer *old_fb);
316 extern void radeon_legacy_atom_set_surface(struct drm_crtc *crtc);
318 extern int radeon_crtc_cursor_set(struct drm_crtc *crtc,
319 struct drm_file *file_priv,
323 extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
326 extern bool radeon_atom_get_clock_info(struct drm_device *dev);
327 extern bool radeon_combios_get_clock_info(struct drm_device *dev);
328 extern struct radeon_encoder_atom_dig *
329 radeon_atombios_get_lvds_info(struct radeon_encoder *encoder);
330 extern struct radeon_encoder_int_tmds *
331 radeon_atombios_get_tmds_info(struct radeon_encoder *encoder);
332 extern struct radeon_encoder_primary_dac *
333 radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder);
334 extern struct radeon_encoder_tv_dac *
335 radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder);
336 extern struct radeon_encoder_lvds *
337 radeon_combios_get_lvds_info(struct radeon_encoder *encoder);
338 extern struct radeon_encoder_int_tmds *
339 radeon_combios_get_tmds_info(struct radeon_encoder *encoder);
340 extern void radeon_combios_get_ext_tmds_info(struct radeon_encoder *encoder);
341 extern struct radeon_encoder_tv_dac *
342 radeon_combios_get_tv_dac_info(struct radeon_encoder *encoder);
343 extern struct radeon_encoder_primary_dac *
344 radeon_combios_get_primary_dac_info(struct radeon_encoder *encoder);
345 extern void radeon_combios_output_lock(struct drm_encoder *encoder, bool lock);
346 extern void radeon_combios_initialize_bios_scratch_regs(struct drm_device *dev);
347 extern void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock);
348 extern void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev);
350 radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
352 radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
354 radeon_combios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc);
356 radeon_combios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on);
357 extern void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
358 u16 blue, int regno);
359 struct drm_framebuffer *radeon_framebuffer_create(struct drm_device *dev,
360 struct drm_mode_fb_cmd *mode_cmd,
361 struct drm_gem_object *obj);
363 int radeonfb_probe(struct drm_device *dev);
365 int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
366 bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev);
367 bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev);
368 void radeon_atombios_init_crtc(struct drm_device *dev,
369 struct radeon_crtc *radeon_crtc);
370 void radeon_legacy_init_crtc(struct drm_device *dev,
371 struct radeon_crtc *radeon_crtc);
372 void radeon_i2c_do_lock(struct radeon_connector *radeon_connector, int lock_state);
374 void radeon_get_clock_info(struct drm_device *dev);
376 extern bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev);
377 extern bool radeon_get_atom_connector_info_from_supported_devices_table(struct drm_device *dev);
379 void radeon_rmx_mode_fixup(struct drm_encoder *encoder,
380 struct drm_display_mode *mode,
381 struct drm_display_mode *adjusted_mode);
382 void radeon_enc_destroy(struct drm_encoder *encoder);
383 void radeon_copy_fb(struct drm_device *dev, struct drm_gem_object *dst_obj);
384 void radeon_combios_asic_init(struct drm_device *dev);
385 extern int radeon_static_clocks_init(struct drm_device *dev);
386 void radeon_init_disp_bw_legacy(struct drm_device *dev,
387 struct drm_display_mode *mode1,
388 uint32_t pixel_bytes1,
389 struct drm_display_mode *mode2,
390 uint32_t pixel_bytes2);
391 void radeon_init_disp_bw_avivo(struct drm_device *dev,
392 struct drm_display_mode *mode1,
393 uint32_t pixel_bytes1,
394 struct drm_display_mode *mode2,
395 uint32_t pixel_bytes2);
396 void radeon_init_disp_bandwidth(struct drm_device *dev);