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#include <linux/hdmi.h>
28#include <drm/drmP.h>
29#include <drm/radeon_drm.h>
30#include "radeon.h"
31#include "radeon_asic.h"
32#include "evergreend.h"
33#include "atom.h"
34
35
36
37
38static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
39{
40 struct drm_device *dev = encoder->dev;
41 struct radeon_device *rdev = dev->dev_private;
42 struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
43 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
44 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
45 uint32_t offset = dig->afmt->offset;
46
47 WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
48 WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
49
50 WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
51 WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
52
53 WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
54 WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
55}
56
57
58
59
60static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder,
61 void *buffer, size_t size)
62{
63 struct drm_device *dev = encoder->dev;
64 struct radeon_device *rdev = dev->dev_private;
65 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
66 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
67 uint32_t offset = dig->afmt->offset;
68 uint8_t *frame = buffer + 3;
69
70
71
72
73
74
75
76 frame[0x0] += 2;
77
78 WREG32(AFMT_AVI_INFO0 + offset,
79 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
80 WREG32(AFMT_AVI_INFO1 + offset,
81 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
82 WREG32(AFMT_AVI_INFO2 + offset,
83 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
84 WREG32(AFMT_AVI_INFO3 + offset,
85 frame[0xC] | (frame[0xD] << 8));
86}
87
88
89
90
91void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
92{
93 struct drm_device *dev = encoder->dev;
94 struct radeon_device *rdev = dev->dev_private;
95 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
96 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
97 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
98 struct hdmi_avi_infoframe frame;
99 uint32_t offset;
100 ssize_t err;
101
102
103 if (!dig->afmt->enabled)
104 return;
105 offset = dig->afmt->offset;
106
107 r600_audio_set_clock(encoder, mode->clock);
108
109 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
110 HDMI_NULL_SEND);
111
112 WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
113
114 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
115 HDMI_AUDIO_DELAY_EN(1) |
116 HDMI_AUDIO_PACKETS_PER_LINE(3));
117
118 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
119 AFMT_AUDIO_SAMPLE_SEND |
120 AFMT_60958_CS_UPDATE);
121
122 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
123 HDMI_ACR_AUTO_SEND |
124 HDMI_ACR_SOURCE);
125
126 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
127 HDMI_NULL_SEND |
128 HDMI_GC_SEND |
129 HDMI_GC_CONT);
130
131 WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
132 HDMI_AVI_INFO_SEND |
133 HDMI_AVI_INFO_CONT |
134 HDMI_AUDIO_INFO_SEND |
135 HDMI_AUDIO_INFO_CONT);
136
137 WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
138 AFMT_AUDIO_INFO_UPDATE);
139
140 WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
141 HDMI_AVI_INFO_LINE(2) |
142 HDMI_AUDIO_INFO_LINE(2));
143
144 WREG32(HDMI_GC + offset, 0);
145
146 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
147 if (err < 0) {
148 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
149 return;
150 }
151
152 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
153 if (err < 0) {
154 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
155 return;
156 }
157
158 evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer));
159 evergreen_hdmi_update_ACR(encoder, mode->clock);
160
161
162 WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
163 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
164 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
165 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
166}
167