This source file includes following definitions.
- cx25840_set_audclk_freq
- cx25836_set_audclk_freq
- cx23885_set_audclk_freq
- cx231xx_set_audclk_freq
- set_audclk_freq
- cx25840_audio_set_path
- set_volume
- set_balance
- cx25840_s_clock_freq
- cx25840_audio_s_ctrl
1
2
3
4
5
6 #include <linux/videodev2.h>
7 #include <linux/i2c.h>
8 #include <media/v4l2-common.h>
9 #include <media/drv-intf/cx25840.h>
10
11 #include "cx25840-core.h"
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 static int cx25840_set_audclk_freq(struct i2c_client *client, u32 freq)
32 {
33 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
34
35 if (state->aud_input != CX25840_AUDIO_SERIAL) {
36 switch (freq) {
37 case 32000:
38
39
40
41
42 cx25840_write4(client, 0x108, 0x1006040f);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 cx25840_write4(client, 0x110, 0x01bb39ee);
58
59
60
61
62
63 cx25840_write(client, 0x127, 0x50);
64
65 if (is_cx2583x(state))
66 break;
67
68
69
70 cx25840_write4(client, 0x900, 0x0801f77f);
71 cx25840_write4(client, 0x904, 0x0801f77f);
72 cx25840_write4(client, 0x90c, 0x0801f77f);
73 break;
74
75 case 44100:
76
77
78
79
80 cx25840_write4(client, 0x108, 0x1009040f);
81
82
83
84
85
86
87
88
89
90
91
92
93
94 cx25840_write4(client, 0x110, 0x00ec6bd6);
95
96
97
98
99
100 cx25840_write(client, 0x127, 0x50);
101
102 if (is_cx2583x(state))
103 break;
104
105
106
107 cx25840_write4(client, 0x900, 0x08016d59);
108 cx25840_write4(client, 0x904, 0x08016d59);
109 cx25840_write4(client, 0x90c, 0x08016d59);
110 break;
111
112 case 48000:
113
114
115
116
117 cx25840_write4(client, 0x108, 0x100a040f);
118
119
120
121
122
123
124
125
126
127
128
129
130
131 cx25840_write4(client, 0x110, 0x0098d6e5);
132
133
134
135
136
137 cx25840_write(client, 0x127, 0x50);
138
139 if (is_cx2583x(state))
140 break;
141
142
143
144 cx25840_write4(client, 0x900, 0x08014faa);
145 cx25840_write4(client, 0x904, 0x08014faa);
146 cx25840_write4(client, 0x90c, 0x08014faa);
147 break;
148 }
149 } else {
150 switch (freq) {
151 case 32000:
152
153
154
155
156 cx25840_write4(client, 0x108, 0x1e08040f);
157
158
159
160
161
162
163
164
165
166
167
168
169
170 cx25840_write4(client, 0x110, 0x012a0869);
171
172
173
174
175
176 cx25840_write(client, 0x127, 0x54);
177
178 if (is_cx2583x(state))
179 break;
180
181
182
183 cx25840_write4(client, 0x8f8, 0x08010000);
184
185
186
187 cx25840_write4(client, 0x900, 0x08020000);
188 cx25840_write4(client, 0x904, 0x08020000);
189 cx25840_write4(client, 0x90c, 0x08020000);
190 break;
191
192 case 44100:
193
194
195
196
197 cx25840_write4(client, 0x108, 0x1809040f);
198
199
200
201
202
203
204
205
206
207
208
209
210
211 cx25840_write4(client, 0x110, 0x00ec6bd6);
212
213
214
215
216
217 cx25840_write(client, 0x127, 0x50);
218
219 if (is_cx2583x(state))
220 break;
221
222
223
224 cx25840_write4(client, 0x8f8, 0x080160cd);
225
226
227
228 cx25840_write4(client, 0x900, 0x08017385);
229 cx25840_write4(client, 0x904, 0x08017385);
230 cx25840_write4(client, 0x90c, 0x08017385);
231 break;
232
233 case 48000:
234
235
236
237
238 cx25840_write4(client, 0x108, 0x180a040f);
239
240
241
242
243
244
245
246
247
248
249
250
251
252 cx25840_write4(client, 0x110, 0x0098d6e5);
253
254
255
256
257
258 cx25840_write(client, 0x127, 0x50);
259
260 if (is_cx2583x(state))
261 break;
262
263
264
265 cx25840_write4(client, 0x8f8, 0x08018000);
266
267
268
269 cx25840_write4(client, 0x900, 0x08015555);
270 cx25840_write4(client, 0x904, 0x08015555);
271 cx25840_write4(client, 0x90c, 0x08015555);
272 break;
273 }
274 }
275
276 state->audclk_freq = freq;
277
278 return 0;
279 }
280
281 static inline int cx25836_set_audclk_freq(struct i2c_client *client, u32 freq)
282 {
283 return cx25840_set_audclk_freq(client, freq);
284 }
285
286 static int cx23885_set_audclk_freq(struct i2c_client *client, u32 freq)
287 {
288 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
289
290 if (state->aud_input != CX25840_AUDIO_SERIAL) {
291 switch (freq) {
292 case 32000:
293 case 44100:
294 case 48000:
295
296
297
298 break;
299 }
300 } else {
301 switch (freq) {
302 case 32000:
303 case 44100:
304
305
306
307 break;
308
309 case 48000:
310
311
312 cx25840_write4(client, 0x8f8, 0x0801867c);
313
314
315
316 cx25840_write4(client, 0x900, 0x08014faa);
317 cx25840_write4(client, 0x904, 0x08014faa);
318 cx25840_write4(client, 0x90c, 0x08014faa);
319 break;
320 }
321 }
322
323 state->audclk_freq = freq;
324
325 return 0;
326 }
327
328 static int cx231xx_set_audclk_freq(struct i2c_client *client, u32 freq)
329 {
330 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
331
332 if (state->aud_input != CX25840_AUDIO_SERIAL) {
333 switch (freq) {
334 case 32000:
335
336
337 cx25840_write4(client, 0x900, 0x0801f77f);
338 cx25840_write4(client, 0x904, 0x0801f77f);
339 cx25840_write4(client, 0x90c, 0x0801f77f);
340 break;
341
342 case 44100:
343
344
345 cx25840_write4(client, 0x900, 0x08016d59);
346 cx25840_write4(client, 0x904, 0x08016d59);
347 cx25840_write4(client, 0x90c, 0x08016d59);
348 break;
349
350 case 48000:
351
352
353 cx25840_write4(client, 0x900, 0x08014faa);
354 cx25840_write4(client, 0x904, 0x08014faa);
355 cx25840_write4(client, 0x90c, 0x08014faa);
356 break;
357 }
358 } else {
359 switch (freq) {
360
361 case 32000:
362
363
364 cx25840_write4(client, 0x8f8, 0x08010000);
365
366
367
368 cx25840_write4(client, 0x900, 0x08020000);
369 cx25840_write4(client, 0x904, 0x08020000);
370 cx25840_write4(client, 0x90c, 0x08020000);
371 break;
372
373 case 44100:
374
375
376 cx25840_write4(client, 0x8f8, 0x080160cd);
377
378
379
380 cx25840_write4(client, 0x900, 0x08017385);
381 cx25840_write4(client, 0x904, 0x08017385);
382 cx25840_write4(client, 0x90c, 0x08017385);
383 break;
384
385 case 48000:
386
387
388 cx25840_write4(client, 0x8f8, 0x0801867c);
389
390
391
392 cx25840_write4(client, 0x900, 0x08014faa);
393 cx25840_write4(client, 0x904, 0x08014faa);
394 cx25840_write4(client, 0x90c, 0x08014faa);
395 break;
396 }
397 }
398
399 state->audclk_freq = freq;
400
401 return 0;
402 }
403
404 static int set_audclk_freq(struct i2c_client *client, u32 freq)
405 {
406 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
407
408 if (freq != 32000 && freq != 44100 && freq != 48000)
409 return -EINVAL;
410
411 if (is_cx231xx(state))
412 return cx231xx_set_audclk_freq(client, freq);
413
414 if (is_cx2388x(state))
415 return cx23885_set_audclk_freq(client, freq);
416
417 if (is_cx2583x(state))
418 return cx25836_set_audclk_freq(client, freq);
419
420 return cx25840_set_audclk_freq(client, freq);
421 }
422
423 void cx25840_audio_set_path(struct i2c_client *client)
424 {
425 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
426
427 if (!is_cx2583x(state)) {
428
429 cx25840_and_or(client, 0x810, ~0x1, 0x01);
430
431
432 cx25840_and_or(client, 0x803, ~0x10, 0);
433
434
435 cx25840_write(client, 0x8d3, 0x1f);
436
437 if (state->aud_input == CX25840_AUDIO_SERIAL) {
438
439 cx25840_write4(client, 0x8d0, 0x01011012);
440
441
442
443
444 } else {
445
446 cx25840_write4(client, 0x8d0, 0x1f063870);
447 }
448 }
449
450 set_audclk_freq(client, state->audclk_freq);
451
452 if (!is_cx2583x(state)) {
453 if (state->aud_input != CX25840_AUDIO_SERIAL) {
454
455
456 cx25840_and_or(client, 0x803, ~0x10, 0x10);
457 }
458
459
460 cx25840_and_or(client, 0x810, ~0x1, 0x00);
461
462
463 if (is_cx2388x(state) || is_cx231xx(state))
464 cx25840_and_or(client, 0x803, ~0x10, 0x10);
465 }
466 }
467
468 static void set_volume(struct i2c_client *client, int volume)
469 {
470 int vol;
471
472
473 vol = volume >> 9;
474
475
476
477
478 if (vol <= 23) {
479 vol = 0;
480 } else {
481 vol -= 23;
482 }
483
484
485 cx25840_write(client, 0x8d4, 228 - (vol * 2));
486 }
487
488 static void set_balance(struct i2c_client *client, int balance)
489 {
490 int bal = balance >> 8;
491 if (bal > 0x80) {
492
493 cx25840_and_or(client, 0x8d5, 0x7f, 0x80);
494
495 cx25840_and_or(client, 0x8d5, ~0x7f, bal & 0x7f);
496 } else {
497
498 cx25840_and_or(client, 0x8d5, 0x7f, 0x00);
499
500 cx25840_and_or(client, 0x8d5, ~0x7f, 0x80 - bal);
501 }
502 }
503
504 int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
505 {
506 struct i2c_client *client = v4l2_get_subdevdata(sd);
507 struct cx25840_state *state = to_state(sd);
508 int retval;
509
510 if (!is_cx2583x(state))
511 cx25840_and_or(client, 0x810, ~0x1, 1);
512 if (state->aud_input != CX25840_AUDIO_SERIAL) {
513 cx25840_and_or(client, 0x803, ~0x10, 0);
514 cx25840_write(client, 0x8d3, 0x1f);
515 }
516 retval = set_audclk_freq(client, freq);
517 if (state->aud_input != CX25840_AUDIO_SERIAL)
518 cx25840_and_or(client, 0x803, ~0x10, 0x10);
519 if (!is_cx2583x(state))
520 cx25840_and_or(client, 0x810, ~0x1, 0);
521 return retval;
522 }
523
524 static int cx25840_audio_s_ctrl(struct v4l2_ctrl *ctrl)
525 {
526 struct v4l2_subdev *sd = to_sd(ctrl);
527 struct cx25840_state *state = to_state(sd);
528 struct i2c_client *client = v4l2_get_subdevdata(sd);
529
530 switch (ctrl->id) {
531 case V4L2_CID_AUDIO_VOLUME:
532 if (state->mute->val)
533 set_volume(client, 0);
534 else
535 set_volume(client, state->volume->val);
536 break;
537 case V4L2_CID_AUDIO_BASS:
538
539 cx25840_and_or(client, 0x8d9, ~0x3f,
540 48 - (ctrl->val * 48 / 0xffff));
541 break;
542 case V4L2_CID_AUDIO_TREBLE:
543
544 cx25840_and_or(client, 0x8db, ~0x3f,
545 48 - (ctrl->val * 48 / 0xffff));
546 break;
547 case V4L2_CID_AUDIO_BALANCE:
548 set_balance(client, ctrl->val);
549 break;
550 default:
551 return -EINVAL;
552 }
553 return 0;
554 }
555
556 const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops = {
557 .s_ctrl = cx25840_audio_s_ctrl,
558 };