aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2006-08-25 15:53:10 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:00 -0500
commit5eba35714e0dfa5618b438cfe46037f22133badc (patch)
tree127d8fdae1d44e72c0ccfa9f7bd8b69b5d5f8a4e /drivers
parent7a00d45cf017172c74d15bad0f9f14720efd69dd (diff)
V4L/DVB (6420): V4L2 conversion for tda9875 from V4L1 API
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/tda9875.c167
1 files changed, 112 insertions, 55 deletions
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index d11044170872..3c0557130a70 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -7,6 +7,7 @@
7 * 7 *
8 * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and 8 * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and
9 * Eric Sandeen 9 * Eric Sandeen
10 * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * This code is placed under the terms of the GNU General Public License 11 * This code is placed under the terms of the GNU General Public License
11 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) 12 * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu)
12 * Which was based on tda8425.c by Greg Alexander (c) 1998 13 * Which was based on tda8425.c by Greg Alexander (c) 1998
@@ -268,87 +269,143 @@ static int tda9875_detach(struct i2c_client *client)
268 return 0; 269 return 0;
269} 270}
270 271
271static int tda9875_command(struct i2c_client *client, 272static int tda9875_get_ctrl(struct i2c_client *client,
272 unsigned int cmd, void *arg) 273 struct v4l2_control *ctrl)
273{ 274{
274 struct tda9875 *t = i2c_get_clientdata(client); 275 struct tda9875 *t = i2c_get_clientdata(client);
275 276
276 dprintk("In tda9875_command...\n"); 277 switch (ctrl->id) {
278 case V4L2_CID_AUDIO_VOLUME:
279 {
280 int left = (t->lvol+84)*606;
281 int right = (t->rvol+84)*606;
277 282
278 switch (cmd) { 283 ctrl->value=max(left,right);
279 /* --- v4l ioctls --- */ 284 return 0;
280 /* take care: bttv does userspace copying, we'll get a 285 }
281 kernel pointer here... */ 286 case V4L2_CID_AUDIO_BALANCE:
282 case VIDIOCGAUDIO:
283 { 287 {
284 struct video_audio *va = arg; 288 int left = (t->lvol+84)*606;
285 int left,right; 289 int right = (t->rvol+84)*606;
290 int volume = max(left,right);
291 int balance = (32768*min(left,right))/
292 (volume ? volume : 1);
293 ctrl->value=(left<right)?
294 (65535-balance) : balance;
295 return 0;
296 }
297 case V4L2_CID_AUDIO_BASS:
298 ctrl->value = (t->bass+12)*2427; /* min -12 max +15 */
299 return 0;
300 case V4L2_CID_AUDIO_TREBLE:
301 ctrl->value = (t->treble+12)*2730;/* min -12 max +12 */
302 return 0;
303 }
304 return -EINVAL;
305}
286 306
287 dprintk("VIDIOCGAUDIO\n"); 307static int tda9875_set_ctrl(struct i2c_client *client,
308 struct v4l2_control *ctrl)
309{
310 struct tda9875 *t = i2c_get_clientdata(client);
311 int chvol=0, volume, balance, left, right;
288 312
289 va->flags |= VIDEO_AUDIO_VOLUME | 313 switch (ctrl->id) {
290 VIDEO_AUDIO_BASS | 314 case V4L2_CID_AUDIO_VOLUME:
291 VIDEO_AUDIO_TREBLE; 315 left = (t->lvol+84)*606;
316 right = (t->rvol+84)*606;
317
318 volume = max(left,right);
319 balance = (32768*min(left,right))/
320 (volume ? volume : 1);
321 balance =(left<right)?
322 (65535-balance) : balance;
323
324 volume = ctrl->value;
292 325
293 /* min is -84 max is 24 */ 326 chvol=1;
327 break;
328 case V4L2_CID_AUDIO_BALANCE:
294 left = (t->lvol+84)*606; 329 left = (t->lvol+84)*606;
295 right = (t->rvol+84)*606; 330 right = (t->rvol+84)*606;
296 va->volume=max(left,right); 331
297 va->balance=(32768*min(left,right))/ 332 volume=max(left,right);
298 (va->volume ? va->volume : 1); 333
299 va->balance=(left<right)? 334 balance = ctrl->value;
300 (65535-va->balance) : va->balance; 335
301 va->bass = (t->bass+12)*2427; /* min -12 max +15 */ 336 chvol=1;
302 va->treble = (t->treble+12)*2730;/* min -12 max +12 */ 337 break;
303 va->mode |= VIDEO_SOUND_MONO; 338 case V4L2_CID_AUDIO_BASS:
304 339 t->bass = ((ctrl->value/2400)-12) & 0xff;
305 break; /* VIDIOCGAUDIO case */ 340 if (t->bass > 15)
341 t->bass = 15;
342 if (t->bass < -12)
343 t->bass = -12 & 0xff;
344 break;
345 case V4L2_CID_AUDIO_TREBLE:
346 t->treble = ((ctrl->value/2700)-12) & 0xff;
347 if (t->treble > 12)
348 t->treble = 12;
349 if (t->treble < -12)
350 t->treble = -12 & 0xff;
351 break;
352 default:
353 return -EINVAL;
306 } 354 }
307 355
308 case VIDIOCSAUDIO: 356 if (chvol) {
309 { 357 left = (min(65536 - balance,32768) *
310 struct video_audio *va = arg; 358 volume) / 32768;
311 int left,right; 359 right = (min(balance,32768) *
312 360 volume) / 32768;
313 dprintk("VIDEOCSAUDIO...\n");
314 left = (min(65536 - va->balance,32768) *
315 va->volume) / 32768;
316 right = (min(va->balance,(__u16)32768) *
317 va->volume) / 32768;
318 t->lvol = ((left/606)-84) & 0xff; 361 t->lvol = ((left/606)-84) & 0xff;
319 if (t->lvol > 24) 362 if (t->lvol > 24)
320 t->lvol = 24; 363 t->lvol = 24;
321 if (t->lvol < -84) 364 if (t->lvol < -84)
322 t->lvol = -84 & 0xff; 365 t->lvol = -84 & 0xff;
323 366
324 t->rvol = ((right/606)-84) & 0xff; 367 t->rvol = ((right/606)-84) & 0xff;
325 if (t->rvol > 24) 368 if (t->rvol > 24)
326 t->rvol = 24; 369 t->rvol = 24;
327 if (t->rvol < -84) 370 if (t->rvol < -84)
328 t->rvol = -84 & 0xff; 371 t->rvol = -84 & 0xff;
329 372 }
330 t->bass = ((va->bass/2400)-12) & 0xff;
331 if (t->bass > 15)
332 t->bass = 15;
333 if (t->bass < -12)
334 t->bass = -12 & 0xff;
335
336 t->treble = ((va->treble/2700)-12) & 0xff;
337 if (t->treble > 12)
338 t->treble = 12;
339 if (t->treble < -12)
340 t->treble = -12 & 0xff;
341 373
374//printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble);
342 375
376 tda9875_set(client);
343 377
344//printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble); 378 return 0;
379}
345 380
346 381
347 tda9875_set(client); 382static int tda9875_command(struct i2c_client *client,
383 unsigned int cmd, void *arg)
384{
385 dprintk("In tda9875_command...\n");
348 386
349 break; 387 switch (cmd) {
388 /* --- v4l ioctls --- */
389 /* take care: bttv does userspace copying, we'll get a
390 kernel pointer here... */
391 case VIDIOC_QUERYCTRL:
392 {
393 struct v4l2_queryctrl *qc = arg;
394
395 switch (qc->id) {
396 case V4L2_CID_AUDIO_VOLUME:
397 case V4L2_CID_AUDIO_BASS:
398 case V4L2_CID_AUDIO_TREBLE:
399 default:
400 return -EINVAL;
401 }
402 return v4l2_ctrl_query_fill_std(qc);
403 }
404 case VIDIOC_S_CTRL:
405 return tda9875_set_ctrl(client, arg);
350 406
351 } /* end of VIDEOCSAUDIO case */ 407 case VIDIOC_G_CTRL:
408 return tda9875_get_ctrl(client, arg);
352 409
353 default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */ 410 default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */
354 411