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#include "cx18-driver.h"
26
27static int set_audclk_freq(struct cx18 *cx, u32 freq)
28{
29 struct cx18_av_state *state = &cx->av_state;
30
31 if (freq != 32000 && freq != 44100 && freq != 48000)
32 return -EINVAL;
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 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
71 switch (freq) {
72 case 32000:
73
74
75
76
77 cx18_av_write4(cx, 0x108, 0x200d040f);
78
79
80
81 cx18_av_write4(cx, 0x10c, 0x002be2fe);
82
83
84
85 cx18_av_write4(cx, 0x110, 0x0176740c);
86
87
88
89 cx18_av_write4(cx, 0x900, 0x0801f77f);
90 cx18_av_write4(cx, 0x904, 0x0801f77f);
91 cx18_av_write4(cx, 0x90c, 0x0801f77f);
92
93
94 cx18_av_write(cx, 0x127, 0x60);
95
96
97 cx18_av_write4(cx, 0x12c, 0x11202fff);
98
99
100
101
102
103
104 cx18_av_write4(cx, 0x128, 0xa00d2ef8);
105 break;
106
107 case 44100:
108
109
110
111
112 cx18_av_write4(cx, 0x108, 0x180e040f);
113
114
115
116 cx18_av_write4(cx, 0x10c, 0x002be2fe);
117
118
119
120 cx18_av_write4(cx, 0x110, 0x0062a1f2);
121
122
123
124 cx18_av_write4(cx, 0x900, 0x08016d59);
125 cx18_av_write4(cx, 0x904, 0x08016d59);
126 cx18_av_write4(cx, 0x90c, 0x08016d59);
127
128
129 cx18_av_write(cx, 0x127, 0x58);
130
131
132 cx18_av_write4(cx, 0x12c, 0x112092ff);
133
134
135
136
137
138
139 cx18_av_write4(cx, 0x128, 0xa01d4bf8);
140 break;
141
142 case 48000:
143
144
145
146
147 cx18_av_write4(cx, 0x108, 0x160e040f);
148
149
150
151 cx18_av_write4(cx, 0x10c, 0x002be2fe);
152
153
154
155 cx18_av_write4(cx, 0x110, 0x005227ad);
156
157
158
159 cx18_av_write4(cx, 0x900, 0x08014faa);
160 cx18_av_write4(cx, 0x904, 0x08014faa);
161 cx18_av_write4(cx, 0x90c, 0x08014faa);
162
163
164 cx18_av_write(cx, 0x127, 0x56);
165
166
167 cx18_av_write4(cx, 0x12c, 0x11205fff);
168
169
170
171
172
173
174 cx18_av_write4(cx, 0x128, 0xa01193f8);
175 break;
176 }
177 } else {
178 switch (freq) {
179 case 32000:
180
181
182
183
184 cx18_av_write4(cx, 0x108, 0x300d040f);
185
186
187
188 cx18_av_write4(cx, 0x10c, 0x002be2fe);
189
190
191
192 cx18_av_write4(cx, 0x110, 0x0176740c);
193
194
195
196 cx18_av_write4(cx, 0x8f8, 0x08010000);
197
198
199
200 cx18_av_write4(cx, 0x900, 0x08020000);
201 cx18_av_write4(cx, 0x904, 0x08020000);
202 cx18_av_write4(cx, 0x90c, 0x08020000);
203
204
205 cx18_av_write(cx, 0x127, 0x70);
206
207
208 cx18_av_write4(cx, 0x12c, 0x11201fff);
209
210
211
212
213
214
215 cx18_av_write4(cx, 0x128, 0xa00d2ef8);
216 break;
217
218 case 44100:
219
220
221
222
223 cx18_av_write4(cx, 0x108, 0x240e040f);
224
225
226
227 cx18_av_write4(cx, 0x10c, 0x002be2fe);
228
229
230
231 cx18_av_write4(cx, 0x110, 0x0062a1f2);
232
233
234
235 cx18_av_write4(cx, 0x8f8, 0x080160cd);
236
237
238
239 cx18_av_write4(cx, 0x900, 0x08017385);
240 cx18_av_write4(cx, 0x904, 0x08017385);
241 cx18_av_write4(cx, 0x90c, 0x08017385);
242
243
244 cx18_av_write(cx, 0x127, 0x64);
245
246
247 cx18_av_write4(cx, 0x12c, 0x112061ff);
248
249
250
251
252
253
254 cx18_av_write4(cx, 0x128, 0xa01d4bf8);
255 break;
256
257 case 48000:
258
259
260
261
262 cx18_av_write4(cx, 0x108, 0x200d040f);
263
264
265
266 cx18_av_write4(cx, 0x10c, 0x002be2fe);
267
268
269
270 cx18_av_write4(cx, 0x110, 0x0176740c);
271
272
273
274 cx18_av_write4(cx, 0x8f8, 0x08018000);
275
276
277
278 cx18_av_write4(cx, 0x900, 0x08015555);
279 cx18_av_write4(cx, 0x904, 0x08015555);
280 cx18_av_write4(cx, 0x90c, 0x08015555);
281
282
283 cx18_av_write(cx, 0x127, 0x60);
284
285
286 cx18_av_write4(cx, 0x12c, 0x11203fff);
287
288
289
290
291
292
293 cx18_av_write4(cx, 0x128, 0xa01193f8);
294 break;
295 }
296 }
297
298 state->audclk_freq = freq;
299
300 return 0;
301}
302
303void cx18_av_audio_set_path(struct cx18 *cx)
304{
305 struct cx18_av_state *state = &cx->av_state;
306 u8 v;
307
308
309 v = cx18_av_read(cx, 0x803) & ~0x10;
310 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
311
312
313 v = cx18_av_read(cx, 0x810) | 0x01;
314 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
315
316
317 cx18_av_write(cx, 0x8d3, 0x1f);
318
319 if (state->aud_input <= CX18_AV_AUDIO_SERIAL2) {
320
321 cx18_av_write4(cx, 0x8d0, 0x01011012);
322
323
324
325
326 } else {
327
328 cx18_av_write4(cx, 0x8d0, 0x1f063870);
329 }
330
331 set_audclk_freq(cx, state->audclk_freq);
332
333
334 v = cx18_av_read(cx, 0x810) & ~0x01;
335 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
336
337 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
338
339
340 v = cx18_av_read(cx, 0x803) | 0x10;
341 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
342 }
343}
344
345static void set_volume(struct cx18 *cx, int volume)
346{
347
348 int vol = volume >> 9;
349
350
351
352 if (vol <= 23)
353 vol = 0;
354 else
355 vol -= 23;
356
357
358 cx18_av_write(cx, 0x8d4, 228 - (vol * 2));
359}
360
361static void set_bass(struct cx18 *cx, int bass)
362{
363
364 cx18_av_and_or(cx, 0x8d9, ~0x3f, 48 - (bass * 48 / 0xffff));
365}
366
367static void set_treble(struct cx18 *cx, int treble)
368{
369
370 cx18_av_and_or(cx, 0x8db, ~0x3f, 48 - (treble * 48 / 0xffff));
371}
372
373static void set_balance(struct cx18 *cx, int balance)
374{
375 int bal = balance >> 8;
376 if (bal > 0x80) {
377
378 cx18_av_and_or(cx, 0x8d5, 0x7f, 0x80);
379
380 cx18_av_and_or(cx, 0x8d5, ~0x7f, bal & 0x7f);
381 } else {
382
383 cx18_av_and_or(cx, 0x8d5, 0x7f, 0x00);
384
385 cx18_av_and_or(cx, 0x8d5, ~0x7f, 0x80 - bal);
386 }
387}
388
389static void set_mute(struct cx18 *cx, int mute)
390{
391 struct cx18_av_state *state = &cx->av_state;
392 u8 v;
393
394 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
395
396
397
398
399 v = cx18_av_read(cx, 0x803);
400 if (mute) {
401
402 v &= ~0x10;
403 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
404 cx18_av_write(cx, 0x8d3, 0x1f);
405 } else {
406
407 v |= 0x10;
408 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
409 }
410 } else {
411
412 cx18_av_and_or(cx, 0x8d3, ~0x2, mute ? 0x02 : 0x00);
413 }
414}
415
416int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
417{
418 struct cx18 *cx = v4l2_get_subdevdata(sd);
419 struct cx18_av_state *state = &cx->av_state;
420 int retval;
421 u8 v;
422
423 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
424 v = cx18_av_read(cx, 0x803) & ~0x10;
425 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
426 cx18_av_write(cx, 0x8d3, 0x1f);
427 }
428 v = cx18_av_read(cx, 0x810) | 0x1;
429 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
430
431 retval = set_audclk_freq(cx, freq);
432
433 v = cx18_av_read(cx, 0x810) & ~0x1;
434 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
435 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
436 v = cx18_av_read(cx, 0x803) | 0x10;
437 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
438 }
439 return retval;
440}
441
442static int cx18_av_audio_s_ctrl(struct v4l2_ctrl *ctrl)
443{
444 struct v4l2_subdev *sd = to_sd(ctrl);
445 struct cx18 *cx = v4l2_get_subdevdata(sd);
446
447 switch (ctrl->id) {
448 case V4L2_CID_AUDIO_VOLUME:
449 set_volume(cx, ctrl->val);
450 break;
451 case V4L2_CID_AUDIO_BASS:
452 set_bass(cx, ctrl->val);
453 break;
454 case V4L2_CID_AUDIO_TREBLE:
455 set_treble(cx, ctrl->val);
456 break;
457 case V4L2_CID_AUDIO_BALANCE:
458 set_balance(cx, ctrl->val);
459 break;
460 case V4L2_CID_AUDIO_MUTE:
461 set_mute(cx, ctrl->val);
462 break;
463 default:
464 return -EINVAL;
465 }
466 return 0;
467}
468
469const struct v4l2_ctrl_ops cx18_av_audio_ctrl_ops = {
470 .s_ctrl = cx18_av_audio_s_ctrl,
471};
472