LUT updates
[platform/upstream/libdrm.git] / linux-core / radeon_mode.h
1 /*
2  * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
3  *                VA Linux Systems Inc., Fremont, California.
4  * Copyright 2008 Red Hat Inc.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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.
23  *
24  * Original Authors:
25  *   Kevin E. Martin, Rickard E. Faith, Alan Hourihane
26  *
27  * Kernel port Author: Dave Airlie
28  */
29
30 #ifndef RADEON_MODE_H
31 #define RADEON_MODE_H
32
33 #include <linux/i2c.h>
34 #include <linux/i2c-id.h>
35 #include <linux/i2c-algo-bit.h>
36
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)
41
42 enum radeon_connector_type {
43         CONNECTOR_NONE,
44         CONNECTOR_VGA,
45         CONNECTOR_DVI_I,
46         CONNECTOR_DVI_D,
47         CONNECTOR_DVI_A,
48         CONNECTOR_STV,
49         CONNECTOR_CTV,
50         CONNECTOR_LVDS,
51         CONNECTOR_DIGITAL,
52         CONNECTOR_SCART,
53         CONNECTOR_HDMI_TYPE_A,
54         CONNECTOR_HDMI_TYPE_B,
55         CONNECTOR_0XC,
56         CONNECTOR_0XD,
57         CONNECTOR_DIN,
58         CONNECTOR_DISPLAY_PORT,
59         CONNECTOR_UNSUPPORTED
60 };
61
62 enum radeon_dac_type {
63         DAC_NONE = 0,
64         DAC_PRIMARY = 1,
65         DAC_TVDAC = 2,
66         DAC_EXT = 3
67 };
68
69 enum radeon_tmds_type {
70         TMDS_NONE = 0,
71         TMDS_INT = 1,
72         TMDS_EXT = 2,
73         TMDS_LVTMA = 3,
74         TMDS_DDIA = 4,
75         TMDS_UNIPHY = 5
76 };
77
78 enum radeon_dvi_type {
79         DVI_AUTO,
80         DVI_DIGITAL,
81         DVI_ANALOG
82 };
83
84 enum radeon_rmx_type {
85         RMX_OFF,
86         RMX_FULL,
87         RMX_CENTER,
88 };
89
90 struct radeon_i2c_bus_rec {
91         bool valid;
92         uint32_t mask_clk_reg;
93         uint32_t mask_data_reg;
94         uint32_t a_clk_reg;
95         uint32_t a_data_reg;
96         uint32_t put_clk_reg;
97         uint32_t put_data_reg;
98         uint32_t get_clk_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;
106         uint32_t a_clk_mask;
107         uint32_t a_data_mask;
108 };
109
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;
114         bool valid;
115         int output_id;
116         int devices;
117         int hpd_mask;
118         struct radeon_i2c_bus_rec ddc_i2c;
119         int igp_lane_info;
120 };
121
122 struct radeon_tmds_pll {
123     uint32_t freq;
124     uint32_t value;
125 };
126
127 #define RADEON_MAX_BIOS_CONNECTOR 16
128
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)
134
135 struct radeon_pll {
136         uint16_t reference_freq;
137         uint16_t reference_div;
138         uint32_t pll_in_min;
139         uint32_t pll_in_max;
140         uint32_t pll_out_min;
141         uint32_t pll_out_max;
142         uint16_t xclk;
143
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;
150         uint32_t best_vco;
151 };
152
153 #define MAX_H_CODE_TIMING_LEN 32
154 #define MAX_V_CODE_TIMING_LEN 32
155
156 struct radeon_legacy_state {
157
158         uint32_t bus_cntl;
159
160         /* DAC */
161         uint32_t dac_cntl;
162         uint32_t dac2_cntl;
163         uint32_t dac_macro_cntl;
164
165         /* CRTC 1 */
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;
174         uint32_t crtc_pitch;
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;
179
180         /* CRTC 2 */
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;
190
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;
196
197         /* FP regs */
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;
214
215         /* Computed values for PLL */
216         uint32_t dot_clock_freq;
217         uint32_t pll_output_freq;
218         int  feedback_div;
219         int  reference_div;
220         int  post_div;
221
222         /* PLL registers */
223         uint32_t ppll_ref_div;
224         uint32_t ppll_div_3;
225         uint32_t htotal_cntl;
226         uint32_t vclk_ecp_cntl;
227
228         /* Computed values for PLL2 */
229         uint32_t dot_clock_freq_2;
230         uint32_t pll_output_freq_2;
231         int feedback_div_2;
232         int reference_div_2;
233         int post_div_2;
234
235         /* PLL2 registers */
236         uint32_t p2pll_ref_div;
237         uint32_t p2pll_div_0;
238         uint32_t htotal_cntl2;
239         uint32_t pixclks_cntl;
240
241         bool palette_valid;
242         uint32_t palette[256];
243         uint32_t palette2[256];
244
245         uint32_t disp2_req_cntl1;
246         uint32_t disp2_req_cntl2;
247         uint32_t dmif_mem_cntl1;
248         uint32_t disp1_req_cntl1;
249
250         uint32_t fp_2nd_gen_cntl;
251         uint32_t fp2_2_gen_cntl;
252         uint32_t tmds2_cntl;
253         uint32_t tmds2_transmitter_cntl;
254
255         /* TV out registers */
256         uint32_t tv_master_cntl;
257         uint32_t tv_htotal;
258         uint32_t tv_hsize;
259         uint32_t tv_hdisp;
260         uint32_t tv_hstart;
261         uint32_t tv_vtotal;
262         uint32_t tv_vdisp;
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;
270         uint32_t tv_ftotal;
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;
287         uint32_t tv_uv_adr;
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;
293         uint32_t gpiopad_a;
294         uint32_t pll_test_cntl;
295
296         uint16_t h_code_timing[MAX_H_CODE_TIMING_LEN];
297         uint16_t v_code_timing[MAX_V_CODE_TIMING_LEN];
298
299
300 };
301
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;
307 };
308
309 struct radeon_crtc {
310         struct drm_crtc base;
311         int crtc_id;
312         u8 lut_r[256], lut_g[256], lut_b[256];
313         bool enabled;
314         bool can_tile;
315         uint32_t crtc_offset;
316         struct radeon_framebuffer *fbdev_fb;
317         struct drm_mode_set mode_set;
318 };
319
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;
325 };
326
327
328 #define RADEON_USE_RMX 1
329
330 struct radeon_encoder {
331         struct drm_encoder base;
332         uint32_t encoder_mode;
333         uint32_t flags;
334         enum radeon_rmx_type rmx_type;
335         union {
336                 enum radeon_dac_type dac;
337                 enum radeon_tmds_type tmds;
338         } type;
339         int atom_device; /* atom devices */
340         uint32_t panel_xres, panel_yres;
341         uint32_t hoverplus, hsync_width;
342         uint32_t hblank;
343         uint32_t voverplus, vsync_width;
344         uint32_t vblank;
345         uint32_t panel_pwr_delay;
346         uint32_t dotclock;
347         struct radeon_tmds_pll tmds_pll[4];
348 };
349
350 struct radeon_connector {
351         struct drm_connector base;
352         struct radeon_i2c_chan *ddc_bus;
353         int use_digital;
354         
355 };
356
357 struct radeon_framebuffer {
358         struct drm_framebuffer base;
359         struct drm_gem_object *obj;
360         struct drm_bo_kmap_obj kmap_obj;
361 };
362
363 extern struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
364                                                  struct radeon_i2c_bus_rec *rec,
365                                                  const char *name);
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);
369
370 extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
371
372 extern void radeon_compute_pll(struct radeon_pll *pll,
373                                uint64_t freq,
374                                uint32_t *dot_clock_p,
375                                uint32_t *fb_div_p,
376                                uint32_t *ref_div_p,
377                                uint32_t *post_div_p,
378                                int flags);
379
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);
388
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,
394                                    int x, int y);
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);
406
407 int radeonfb_probe(struct drm_device *dev);
408
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);
416
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);
421
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);
426
427 #endif