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
33 #include <linux/i2c.h>
34 #include <linux/i2c-id.h>
35 #include <linux/i2c-algo-bit.h>
37 #define to_radeon_crtc(x) container_of(x, struct radeon_crtc, base)
38 #define to_radeon_connector(x) container_of(x, struct radeon_connector, base)
39 #define to_radeon_encoder(x) container_of(x, struct radeon_encoder, base)
40 #define to_radeon_framebuffer(x) container_of(x, struct radeon_framebuffer, base)
42 enum radeon_connector_type {
53 CONNECTOR_HDMI_TYPE_A,
54 CONNECTOR_HDMI_TYPE_B,
58 CONNECTOR_DISPLAY_PORT,
62 enum radeon_dac_type {
69 enum radeon_tmds_type {
78 enum radeon_dvi_type {
84 enum radeon_rmx_type {
90 struct radeon_i2c_bus_rec {
92 uint32_t mask_clk_reg;
93 uint32_t mask_data_reg;
97 uint32_t put_data_reg;
99 uint32_t get_data_reg;
100 uint32_t mask_clk_mask;
101 uint32_t mask_data_mask;
102 uint32_t put_clk_mask;
103 uint32_t put_data_mask;
104 uint32_t get_clk_mask;
105 uint32_t get_data_mask;
107 uint32_t a_data_mask;
110 struct radeon_bios_connector {
111 enum radeon_dac_type dac_type;
112 enum radeon_tmds_type tmds_type;
113 enum radeon_connector_type connector_type;
118 struct radeon_i2c_bus_rec ddc_i2c;
122 struct radeon_tmds_pll {
127 #define RADEON_MAX_BIOS_CONNECTOR 16
129 #define RADEON_PLL_USE_BIOS_DIVS (1 << 0)
130 #define RADEON_PLL_NO_ODD_POST_DIV (1 << 1)
131 #define RADEON_PLL_USE_REF_DIV (1 << 2)
132 #define RADEON_PLL_LEGACY (1 << 3)
133 #define RADEON_PLL_PREFER_LOW_REF_DIV (1 << 4)
136 uint16_t reference_freq;
137 uint16_t reference_div;
140 uint32_t pll_out_min;
141 uint32_t pll_out_max;
144 uint32_t min_ref_div;
145 uint32_t max_ref_div;
146 uint32_t min_post_div;
147 uint32_t max_post_div;
148 uint32_t min_feedback_div;
149 uint32_t max_feedback_div;
153 #define MAX_H_CODE_TIMING_LEN 32
154 #define MAX_V_CODE_TIMING_LEN 32
156 struct radeon_legacy_state {
163 uint32_t dac_macro_cntl;
166 uint32_t crtc_gen_cntl;
167 uint32_t crtc_ext_cntl;
168 uint32_t crtc_h_total_disp;
169 uint32_t crtc_h_sync_strt_wid;
170 uint32_t crtc_v_total_disp;
171 uint32_t crtc_v_sync_strt_wid;
172 uint32_t crtc_offset;
173 uint32_t crtc_offset_cntl;
175 uint32_t disp_merge_cntl;
176 uint32_t grph_buffer_cntl;
177 uint32_t crtc_more_cntl;
178 uint32_t crtc_tile_x0_y0;
181 uint32_t crtc2_gen_cntl;
182 uint32_t crtc2_h_total_disp;
183 uint32_t crtc2_h_sync_strt_wid;
184 uint32_t crtc2_v_total_disp;
185 uint32_t crtc2_v_sync_strt_wid;
186 uint32_t crtc2_offset;
187 uint32_t crtc2_offset_cntl;
188 uint32_t crtc2_pitch;
189 uint32_t crtc2_tile_x0_y0;
191 uint32_t disp_output_cntl;
192 uint32_t disp_tv_out_cntl;
193 uint32_t disp_hw_debug;
194 uint32_t disp2_merge_cntl;
195 uint32_t grph2_buffer_cntl;
198 uint32_t fp_crtc_h_total_disp;
199 uint32_t fp_crtc_v_total_disp;
200 uint32_t fp_gen_cntl;
201 uint32_t fp2_gen_cntl;
202 uint32_t fp_h_sync_strt_wid;
203 uint32_t fp_h2_sync_strt_wid;
204 uint32_t fp_horz_stretch;
205 uint32_t fp_horz_vert_active;
206 uint32_t fp_panel_cntl;
207 uint32_t fp_v_sync_strt_wid;
208 uint32_t fp_v2_sync_strt_wid;
209 uint32_t fp_vert_stretch;
210 uint32_t lvds_gen_cntl;
211 uint32_t lvds_pll_cntl;
212 uint32_t tmds_pll_cntl;
213 uint32_t tmds_transmitter_cntl;
215 /* Computed values for PLL */
216 uint32_t dot_clock_freq;
217 uint32_t pll_output_freq;
223 uint32_t ppll_ref_div;
225 uint32_t htotal_cntl;
226 uint32_t vclk_ecp_cntl;
228 /* Computed values for PLL2 */
229 uint32_t dot_clock_freq_2;
230 uint32_t pll_output_freq_2;
236 uint32_t p2pll_ref_div;
237 uint32_t p2pll_div_0;
238 uint32_t htotal_cntl2;
239 uint32_t pixclks_cntl;
242 uint32_t palette[256];
243 uint32_t palette2[256];
245 uint32_t disp2_req_cntl1;
246 uint32_t disp2_req_cntl2;
247 uint32_t dmif_mem_cntl1;
248 uint32_t disp1_req_cntl1;
250 uint32_t fp_2nd_gen_cntl;
251 uint32_t fp2_2_gen_cntl;
253 uint32_t tmds2_transmitter_cntl;
255 /* TV out registers */
256 uint32_t tv_master_cntl;
263 uint32_t tv_timing_cntl;
264 uint32_t tv_vscaler_cntl1;
265 uint32_t tv_vscaler_cntl2;
266 uint32_t tv_sync_size;
267 uint32_t tv_vrestart;
268 uint32_t tv_hrestart;
269 uint32_t tv_frestart;
271 uint32_t tv_clock_sel_cntl;
272 uint32_t tv_clkout_cntl;
273 uint32_t tv_data_delay_a;
274 uint32_t tv_data_delay_b;
275 uint32_t tv_dac_cntl;
276 uint32_t tv_pll_cntl;
277 uint32_t tv_pll_cntl1;
278 uint32_t tv_pll_fine_cntl;
279 uint32_t tv_modulator_cntl1;
280 uint32_t tv_modulator_cntl2;
281 uint32_t tv_frame_lock_cntl;
282 uint32_t tv_pre_dac_mux_cntl;
283 uint32_t tv_rgb_cntl;
284 uint32_t tv_y_saw_tooth_cntl;
285 uint32_t tv_y_rise_cntl;
286 uint32_t tv_y_fall_cntl;
288 uint32_t tv_upsamp_and_gain_cntl;
289 uint32_t tv_gain_limit_settings;
290 uint32_t tv_linear_gain_settings;
291 uint32_t tv_crc_cntl;
292 uint32_t tv_sync_cntl;
294 uint32_t pll_test_cntl;
296 uint16_t h_code_timing[MAX_H_CODE_TIMING_LEN];
297 uint16_t v_code_timing[MAX_V_CODE_TIMING_LEN];
302 struct radeon_mode_info {
303 struct atom_context *atom_context;
304 struct radeon_bios_connector bios_connector[RADEON_MAX_BIOS_CONNECTOR];
305 struct radeon_pll pll;
306 struct radeon_legacy_state legacy_state;
310 struct drm_crtc base;
312 u8 lut_r[256], lut_g[256], lut_b[256];
315 uint32_t crtc_offset;
316 struct radeon_framebuffer *fbdev_fb;
317 struct drm_mode_set mode_set;
320 struct radeon_i2c_chan {
321 struct drm_device *dev;
322 struct i2c_adapter adapter;
323 struct i2c_algo_bit_data algo;
324 struct radeon_i2c_bus_rec rec;
328 #define RADEON_USE_RMX 1
330 struct radeon_encoder {
331 struct drm_encoder base;
332 uint32_t encoder_mode;
334 enum radeon_rmx_type rmx_type;
336 enum radeon_dac_type dac;
337 enum radeon_tmds_type tmds;
339 int atom_device; /* atom devices */
340 uint32_t panel_xres, panel_yres;
341 uint32_t hoverplus, hsync_width;
343 uint32_t voverplus, vsync_width;
345 uint32_t panel_pwr_delay;
347 struct radeon_tmds_pll tmds_pll[4];
350 struct radeon_connector {
351 struct drm_connector base;
352 struct radeon_i2c_chan *ddc_bus;
357 struct radeon_framebuffer {
358 struct drm_framebuffer base;
359 struct drm_gem_object *obj;
360 struct drm_bo_kmap_obj kmap_obj;
363 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
364 struct radeon_i2c_bus_rec *rec,
366 extern void radeon_i2c_destroy(struct radeon_i2c_chan *i2c);
367 extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
368 extern struct drm_connector *radeon_connector_add(struct drm_device *dev, int bios_index);
370 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
372 extern void radeon_compute_pll(struct radeon_pll *pll,
374 uint32_t *dot_clock_p,
377 uint32_t *post_div_p,
380 struct drm_encoder *radeon_encoder_lvtma_add(struct drm_device *dev, int bios_index);
381 struct drm_encoder *radeon_encoder_atom_dac_add(struct drm_device *dev, int bios_index, int dac_id, int with_tv);
382 struct drm_encoder *radeon_encoder_atom_tmds_add(struct drm_device *dev, int bios_index, int tmds_type);
383 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index);
384 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int with_tv);
385 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int with_tv);
386 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index);
387 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index);
389 extern void radeon_crtc_load_lut(struct drm_crtc *crtc);
390 extern void atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y);
391 extern void atombios_crtc_mode_set(struct drm_crtc *crtc,
392 struct drm_display_mode *mode,
393 struct drm_display_mode *adjusted_mode,
395 extern void atombios_crtc_dpms(struct drm_crtc *crtc, int mode);
396 extern bool radeon_atom_get_clock_info(struct drm_device *dev);
397 extern bool radeon_combios_get_clock_info(struct drm_device *dev);
398 extern void radeon_get_lvds_info(struct radeon_encoder *encoder);
399 extern bool radeon_combios_get_lvds_info(struct radeon_encoder *encoder);
400 extern bool radeon_combios_get_tmds_info(struct radeon_encoder *encoder);
401 extern void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
402 u16 blue, int regno);
403 struct drm_framebuffer *radeon_user_framebuffer_create(struct drm_device *dev,
404 struct drm_file *filp,
405 struct drm_mode_fb_cmd *mode_cmd);
407 int radeonfb_probe(struct drm_device *dev);
409 int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
410 bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev);
411 void radeon_atombios_init_crtc(struct drm_device *dev,
412 struct radeon_crtc *radeon_crtc);
413 void radeon_legacy_init_crtc(struct drm_device *dev,
414 struct radeon_crtc *radeon_crtc);
415 void radeon_i2c_do_lock(struct radeon_connector *radeon_connector, int lock_state);
417 void radeon_atom_static_pwrmgt_setup(struct drm_device *dev, int enable);
418 void radeon_atom_dyn_clk_setup(struct drm_device *dev, int enable);
419 void radeon_get_clock_info(struct drm_device *dev);
420 extern bool radeon_get_atom_connector_info_from_bios_connector_table(struct drm_device *dev);
422 void radeon_rmx_mode_fixup(struct drm_encoder *encoder,
423 struct drm_display_mode *mode,
424 struct drm_display_mode *adjusted_mode);
425 void radeon_enc_destroy(struct drm_encoder *encoder);