summaryrefslogtreecommitdiff
path: root/linux-core/radeon_legacy_encoders.c
blob: 8846653d66a76eabdf7f23065a07d55840473dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
 * Copyright 2007-8 Advanced Micro Devices, Inc.
 * Copyright 2008 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Dave Airlie
 *          Alex Deucher
 */
#include "drmP.h"
#include "drm_crtc_helper.h"
#include "radeon_drm.h"
#include "radeon_drv.h"


void radeon_restore_dac_registers(struct drm_device *dev, struct radeon_legacy_state *state)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;

	if (radeon_is_r300(dev_priv))
		RADEON_WRITE_P(RADEON_GPIOPAD_A, state->gpiopad_a, ~1);

	RADEON_WRITE_P(RADEON_DAC_CNTL,
		       state->dac_cntl,
		       RADEON_DAC_RANGE_CNTL |
		       RADEON_DAC_BLANKING);

	RADEON_WRITE(RADEON_DAC_CNTL2, state->dac2_cntl);

	if ((dev_priv->chip_family != CHIP_R100) &&
	    (dev_priv->chip_family != CHIP_R200))
		RADEON_WRITE (RADEON_TV_DAC_CNTL, state->tv_dac_cntl);

	RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, state->disp_output_cntl);
	
	if ((dev_priv->chip_family == CHIP_R200) ||
	    radeon_is_r300(dev_priv)) {
		RADEON_WRITE(RADEON_DISP_TV_OUT_CNTL, state->disp_tv_out_cntl);
	} else {
		RADEON_WRITE(RADEON_DISP_HW_DEBUG, state->disp_hw_debug);
	}

	RADEON_WRITE(RADEON_DAC_MACRO_CNTL, state->dac_macro_cntl);

	/* R200 DAC connected via DVO */
	if (dev_priv->chip_family == CHIP_R200)
		RADEON_WRITE(RADEON_FP2_GEN_CNTL, state->fp2_gen_cntl);
}


/* Write TMDS registers */
void radeon_restore_fp_registers(struct drm_device *dev, struct radeon_legacy_state *state)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;

	RADEON_WRITE(RADEON_TMDS_PLL_CNTL,        state->tmds_pll_cntl);
	RADEON_WRITE(RADEON_TMDS_TRANSMITTER_CNTL,state->tmds_transmitter_cntl);
	RADEON_WRITE(RADEON_FP_GEN_CNTL,          state->fp_gen_cntl);

	if ((dev_priv->chip_family == CHIP_RS400) ||
	    (dev_priv->chip_family == CHIP_RS480)) {
		RADEON_WRITE(RS400_FP_2ND_GEN_CNTL, state->fp_2nd_gen_cntl);
		/*RADEON_WRITE(RS400_TMDS2_CNTL, state->tmds2_cntl);*/
		RADEON_WRITE(RS400_TMDS2_TRANSMITTER_CNTL, state->tmds2_transmitter_cntl);
	}

	/* old AIW Radeon has some BIOS initialization problem
	 * with display buffer underflow, only occurs to DFP
	 */
	if (dev_priv->flags & RADEON_SINGLE_CRTC)
		RADEON_WRITE(RADEON_GRPH_BUFFER_CNTL,
			     RADEON_READ(RADEON_GRPH_BUFFER_CNTL) & ~0x7f0000);

}

/* Write FP2 registers */
void radeon_restore_fp2_registers(struct drm_device *dev, struct radeon_legacy_state *state)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	RADEON_WRITE(RADEON_FP2_GEN_CNTL, state->fp2_gen_cntl);

	if ((dev_priv->chip_family == CHIP_RS400) ||
	    (dev_priv->chip_family == CHIP_RS480))
		RADEON_WRITE(RS400_FP2_2_GEN_CNTL, state->fp2_2_gen_cntl);
}

/* Write RMX registers */
void radeon_state_rmx_registers(struct drm_device *dev, struct radeon_legacy_state *state)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	RADEON_WRITE(RADEON_FP_HORZ_STRETCH,      state->fp_horz_stretch);
	RADEON_WRITE(RADEON_FP_VERT_STRETCH,      state->fp_vert_stretch);
	RADEON_WRITE(RADEON_CRTC_MORE_CNTL,       state->crtc_more_cntl);
	RADEON_WRITE(RADEON_FP_HORZ_VERT_ACTIVE,  state->fp_horz_vert_active);
	RADEON_WRITE(RADEON_FP_H_SYNC_STRT_WID,   state->fp_h_sync_strt_wid);
	RADEON_WRITE(RADEON_FP_V_SYNC_STRT_WID,   state->fp_v_sync_strt_wid);
	RADEON_WRITE(RADEON_FP_CRTC_H_TOTAL_DISP, state->fp_crtc_h_total_disp);
	RADEON_WRITE(RADEON_FP_CRTC_V_TOTAL_DISP, state->fp_crtc_v_total_disp);

}

/* Write LVDS registers */
void radeon_restore_lvds_registers(struct drm_device *dev, struct radeon_legacy_state *state)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;

	if (dev_priv->flags & RADEON_IS_MOBILITY) {
		RADEON_WRITE(RADEON_LVDS_GEN_CNTL,  state->lvds_gen_cntl);
		/*RADEON_WRITE(RADEON_LVDS_PLL_CNTL,  state->lvds_pll_cntl);*/

		if (dev_priv->chip_family == CHIP_RV410) {
			RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, 0);
		}
	}

}

static void radeon_init_fp_registers(struct drm_encoder *encoder, struct drm_display_mode *mode,
				     bool is_primary)
{
	

}

static void radeon_init_dac_registers(struct drm_encoder *encoder, struct radeon_legacy_state *state,
				      struct drm_display_mode *mode, bool is_primary)
{
	struct drm_device *dev = encoder->dev;
	struct drm_radeon_private *dev_priv = dev->dev_private;

	if (is_primary) {
		if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
			state->disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL &
							      ~RADEON_DISP_DAC_SOURCE_MASK);
		} else {
			state->dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2)  & ~(RADEON_DAC2_DAC_CLK_SEL);
		}
	} else {
		if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
			state->disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL &
							      ~RADEON_DISP_DAC_SOURCE_MASK);
			state->disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
		} else {
			state->dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
		}
	}

	state->dac_cntl = (RADEON_DAC_MASK_ALL |
			   RADEON_DAC_VGA_ADR_EN |
			   /* TODO 6-bits */
			   RADEON_DAC_8BIT_EN);
	state->dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
}

static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
{
	struct drm_device *dev = encoder->dev;
}

static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
{
	radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
}

static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
{
	radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
}

static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
				  struct drm_display_mode *mode,
				  struct drm_display_mode *adjusted_mode)
{


}

static bool radeon_legacy_lvds_mode_fixup(struct drm_encoder *encoder,
				    struct drm_display_mode *mode,
				    struct drm_display_mode *adjusted_mode)
{
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);

	radeon_encoder->flags &= ~RADEON_USE_RMX;

	if (radeon_encoder->rmx_type != RMX_OFF)
		radeon_rmx_mode_fixup(encoder, mode, adjusted_mode);
	
	return true;
}

static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
	.dpms = radeon_legacy_lvds_dpms,
	.mode_fixup = radeon_legacy_lvds_mode_fixup,
	.prepare = radeon_legacy_lvds_prepare,
	.mode_set = radeon_legacy_lvds_mode_set,
	.commit = radeon_legacy_lvds_commit,
};


static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
	.destroy = radeon_enc_destroy,
};


struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_mode_info *mode_info = &dev_priv->mode_info;
	struct radeon_encoder *radeon_encoder;
	struct drm_encoder *encoder;
	radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
	if (!radeon_encoder) {
		return NULL;
	}

	encoder = &radeon_encoder->base;

	encoder->possible_crtcs = 0x3;
	encoder->possible_clones = 0;
	drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs,
			 DRM_MODE_ENCODER_LVDS);

	drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);

	/* TODO get the LVDS info from the BIOS for panel size etc. */
	/* get the lvds info from the bios */
	radeon_combios_get_lvds_info(radeon_encoder);

	/* LVDS gets default RMX full scaling */
	radeon_encoder->rmx_type = RMX_FULL;

	return encoder;
}

static bool radeon_legacy_primary_dac_mode_fixup(struct drm_encoder *encoder,
						 struct drm_display_mode *mode,
						 struct drm_display_mode *adjusted_mode)
{
	return true;
}

static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
{


}

static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
{
	radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
}

static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
{
	radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
}

static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
				  struct drm_display_mode *mode,
				  struct drm_display_mode *adjusted_mode)
{
	struct drm_device *dev = encoder->dev;
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
	radeon_init_dac_registers(encoder, &dev_priv->mode_info.legacy_state, adjusted_mode,
				  (radeon_crtc->crtc_id == 1));

	radeon_restore_dac_registers(dev, &dev_priv->mode_info.legacy_state);
}

static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
	.dpms = radeon_legacy_primary_dac_dpms,
	.mode_fixup = radeon_legacy_primary_dac_mode_fixup,
	.prepare = radeon_legacy_primary_dac_prepare,
	.mode_set = radeon_legacy_primary_dac_mode_set,
	.commit = radeon_legacy_primary_dac_commit,
};


static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
	.destroy = radeon_enc_destroy,
};

struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int has_tv)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_mode_info *mode_info = &dev_priv->mode_info;
	struct radeon_encoder *radeon_encoder;
	struct drm_encoder *encoder;
	radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
	if (!radeon_encoder) {
		return NULL;
	}

	encoder = &radeon_encoder->base;

	encoder->possible_crtcs = 0x3;
	encoder->possible_clones = 0;
	drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs,
			 DRM_MODE_ENCODER_DAC);

	drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);

	return encoder;
}


static bool radeon_legacy_tmds_int_mode_fixup(struct drm_encoder *encoder,
						 struct drm_display_mode *mode,
						 struct drm_display_mode *adjusted_mode)
{

}

static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
{
	/* dfp1 */

}

static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
{
	radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
}

static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
{
	radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
}

static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
				  struct drm_display_mode *mode,
				  struct drm_display_mode *adjusted_mode)
{
	

}

static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
	.dpms = radeon_legacy_tmds_int_dpms,
	.mode_fixup = radeon_legacy_tmds_int_mode_fixup,
	.prepare = radeon_legacy_tmds_int_prepare,
	.mode_set = radeon_legacy_tmds_int_mode_set,
	.commit = radeon_legacy_tmds_int_commit,
};


static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
	.destroy = radeon_enc_destroy,
};

struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index)
{
	struct drm_radeon_private *dev_priv = dev->dev_private;
	struct radeon_mode_info *mode_info = &dev_priv->mode_info;
	struct radeon_encoder *radeon_encoder;
	struct drm_encoder *encoder;
	radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
	if (!radeon_encoder) {
		return NULL;
	}

	encoder = &radeon_encoder->base;

	encoder->possible_crtcs = 0x3;
	encoder->possible_clones = 0;
	drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs,
			 DRM_MODE_ENCODER_TMDS);

	drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);

	radeon_combios_get_tmds_info(radeon_encoder);
	return encoder;
}