diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2011-05-11 04:52:21 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-05-11 08:52:54 -0400 |
commit | ac34dad26e6786257ef54d8df4f883825bea02eb (patch) | |
tree | a6917dedf2edf31fc9fbdd267c8f3c70e0310609 /sound/firewire/isight.c | |
parent | 8839eedafd2e91e5b124730825e9b39b1ff493dd (diff) |
ALSA: isight: wrap up register accesses
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
[cl: removed superfluous variable]
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/firewire/isight.c')
-rw-r--r-- | sound/firewire/isight.c | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c index 1a8da2614db6..4d2edcfdbbca 100644 --- a/sound/firewire/isight.c +++ b/sound/firewire/isight.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * Licensed under the terms of the GNU General Public License, version 2. | 5 | * Licensed under the terms of the GNU General Public License, version 2. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <asm/byteorder.h> | ||
8 | #include <linux/delay.h> | 9 | #include <linux/delay.h> |
9 | #include <linux/device.h> | 10 | #include <linux/device.h> |
10 | #include <linux/firewire.h> | 11 | #include <linux/firewire.h> |
@@ -311,23 +312,28 @@ static int isight_hw_params(struct snd_pcm_substream *substream, | |||
311 | return 0; | 312 | return 0; |
312 | } | 313 | } |
313 | 314 | ||
314 | static void isight_stop_streaming(struct isight *isight) | 315 | static int reg_read(struct isight *isight, int offset, __be32 *value) |
315 | { | 316 | { |
316 | __be32 value; | 317 | return snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, |
318 | isight->audio_base + offset, value, 4); | ||
319 | } | ||
320 | |||
321 | static int reg_write(struct isight *isight, int offset, __be32 value) | ||
322 | { | ||
323 | return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | ||
324 | isight->audio_base + offset, &value, 4); | ||
325 | } | ||
317 | 326 | ||
327 | static void isight_stop_streaming(struct isight *isight) | ||
328 | { | ||
318 | if (!isight->context) | 329 | if (!isight->context) |
319 | return; | 330 | return; |
320 | 331 | ||
321 | fw_iso_context_stop(isight->context); | 332 | fw_iso_context_stop(isight->context); |
322 | fw_iso_context_destroy(isight->context); | 333 | fw_iso_context_destroy(isight->context); |
323 | isight->context = NULL; | 334 | isight->context = NULL; |
324 | |||
325 | value = 0; | ||
326 | snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | ||
327 | isight->audio_base + REG_AUDIO_ENABLE, | ||
328 | &value, 4); | ||
329 | |||
330 | fw_iso_resources_free(&isight->resources); | 335 | fw_iso_resources_free(&isight->resources); |
336 | reg_write(isight, REG_AUDIO_ENABLE, 0); | ||
331 | } | 337 | } |
332 | 338 | ||
333 | static int isight_hw_free(struct snd_pcm_substream *substream) | 339 | static int isight_hw_free(struct snd_pcm_substream *substream) |
@@ -345,7 +351,6 @@ static int isight_hw_free(struct snd_pcm_substream *substream) | |||
345 | 351 | ||
346 | static int isight_start_streaming(struct isight *isight) | 352 | static int isight_start_streaming(struct isight *isight) |
347 | { | 353 | { |
348 | __be32 value; | ||
349 | unsigned int i; | 354 | unsigned int i; |
350 | int err; | 355 | int err; |
351 | 356 | ||
@@ -356,21 +361,15 @@ static int isight_start_streaming(struct isight *isight) | |||
356 | return 0; | 361 | return 0; |
357 | } | 362 | } |
358 | 363 | ||
359 | value = cpu_to_be32(RATE_48000); | 364 | err = reg_write(isight, REG_SAMPLE_RATE, cpu_to_be32(RATE_48000)); |
360 | err = snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | ||
361 | isight->audio_base + REG_SAMPLE_RATE, | ||
362 | &value, 4); | ||
363 | if (err < 0) | 365 | if (err < 0) |
364 | return err; | 366 | goto error; |
365 | 367 | ||
366 | err = isight_connect(isight); | 368 | err = isight_connect(isight); |
367 | if (err < 0) | 369 | if (err < 0) |
368 | goto error; | 370 | goto error; |
369 | 371 | ||
370 | value = cpu_to_be32(AUDIO_ENABLE); | 372 | err = reg_write(isight, REG_AUDIO_ENABLE, cpu_to_be32(AUDIO_ENABLE)); |
371 | err = snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | ||
372 | isight->audio_base + REG_AUDIO_ENABLE, | ||
373 | &value, 4); | ||
374 | if (err < 0) | 373 | if (err < 0) |
375 | goto err_resources; | 374 | goto err_resources; |
376 | 375 | ||
@@ -407,11 +406,8 @@ err_context: | |||
407 | fw_iso_context_destroy(isight->context); | 406 | fw_iso_context_destroy(isight->context); |
408 | isight->context = NULL; | 407 | isight->context = NULL; |
409 | err_resources: | 408 | err_resources: |
410 | value = 0; | ||
411 | snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | ||
412 | isight->audio_base + REG_AUDIO_ENABLE, | ||
413 | &value, 4); | ||
414 | fw_iso_resources_free(&isight->resources); | 409 | fw_iso_resources_free(&isight->resources); |
410 | reg_write(isight, REG_AUDIO_ENABLE, 0); | ||
415 | error: | 411 | error: |
416 | return err; | 412 | return err; |
417 | } | 413 | } |
@@ -503,8 +499,7 @@ static int isight_gain_get(struct snd_kcontrol *ctl, | |||
503 | __be32 gain; | 499 | __be32 gain; |
504 | int err; | 500 | int err; |
505 | 501 | ||
506 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 502 | err = reg_read(isight, REG_GAIN, &gain); |
507 | isight->audio_base + REG_GAIN, &gain, 4); | ||
508 | if (err < 0) | 503 | if (err < 0) |
509 | return err; | 504 | return err; |
510 | 505 | ||
@@ -517,15 +512,13 @@ static int isight_gain_put(struct snd_kcontrol *ctl, | |||
517 | struct snd_ctl_elem_value *value) | 512 | struct snd_ctl_elem_value *value) |
518 | { | 513 | { |
519 | struct isight *isight = ctl->private_data; | 514 | struct isight *isight = ctl->private_data; |
520 | __be32 gain; | ||
521 | 515 | ||
522 | if (value->value.integer.value[0] < isight->gain_min || | 516 | if (value->value.integer.value[0] < isight->gain_min || |
523 | value->value.integer.value[0] > isight->gain_max) | 517 | value->value.integer.value[0] > isight->gain_max) |
524 | return -EINVAL; | 518 | return -EINVAL; |
525 | 519 | ||
526 | gain = cpu_to_be32(value->value.integer.value[0]); | 520 | return reg_write(isight, REG_GAIN, |
527 | return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | 521 | cpu_to_be32(value->value.integer.value[0])); |
528 | isight->audio_base + REG_GAIN, &gain, 4); | ||
529 | } | 522 | } |
530 | 523 | ||
531 | static int isight_mute_get(struct snd_kcontrol *ctl, | 524 | static int isight_mute_get(struct snd_kcontrol *ctl, |
@@ -535,8 +528,7 @@ static int isight_mute_get(struct snd_kcontrol *ctl, | |||
535 | __be32 mute; | 528 | __be32 mute; |
536 | int err; | 529 | int err; |
537 | 530 | ||
538 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 531 | err = reg_read(isight, REG_MUTE, &mute); |
539 | isight->audio_base + REG_MUTE, &mute, 4); | ||
540 | if (err < 0) | 532 | if (err < 0) |
541 | return err; | 533 | return err; |
542 | 534 | ||
@@ -549,11 +541,9 @@ static int isight_mute_put(struct snd_kcontrol *ctl, | |||
549 | struct snd_ctl_elem_value *value) | 541 | struct snd_ctl_elem_value *value) |
550 | { | 542 | { |
551 | struct isight *isight = ctl->private_data; | 543 | struct isight *isight = ctl->private_data; |
552 | __be32 mute; | ||
553 | 544 | ||
554 | mute = (__force __be32)!value->value.integer.value[0]; | 545 | return reg_write(isight, REG_MUTE, |
555 | return snd_fw_transaction(isight->unit, TCODE_WRITE_QUADLET_REQUEST, | 546 | (__force __be32)!value->value.integer.value[0]); |
556 | isight->audio_base + REG_MUTE, &mute, 4); | ||
557 | } | 547 | } |
558 | 548 | ||
559 | static int isight_create_mixer(struct isight *isight) | 549 | static int isight_create_mixer(struct isight *isight) |
@@ -578,31 +568,25 @@ static int isight_create_mixer(struct isight *isight) | |||
578 | struct snd_kcontrol *ctl; | 568 | struct snd_kcontrol *ctl; |
579 | int err; | 569 | int err; |
580 | 570 | ||
581 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 571 | err = reg_read(isight, REG_GAIN_RAW_START, &value); |
582 | isight->audio_base + REG_GAIN_RAW_START, | ||
583 | &value, 4); | ||
584 | if (err < 0) | 572 | if (err < 0) |
585 | return err; | 573 | return err; |
586 | isight->gain_min = be32_to_cpu(value); | 574 | isight->gain_min = be32_to_cpu(value); |
587 | 575 | ||
588 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 576 | err = reg_read(isight, REG_GAIN_RAW_END, &value); |
589 | isight->audio_base + REG_GAIN_RAW_END, | ||
590 | &value, 4); | ||
591 | if (err < 0) | 577 | if (err < 0) |
592 | return err; | 578 | return err; |
593 | isight->gain_max = be32_to_cpu(value); | 579 | isight->gain_max = be32_to_cpu(value); |
594 | 580 | ||
595 | isight->gain_tlv[0] = SNDRV_CTL_TLVT_DB_MINMAX; | 581 | isight->gain_tlv[0] = SNDRV_CTL_TLVT_DB_MINMAX; |
596 | isight->gain_tlv[1] = 2 * sizeof(unsigned int); | 582 | isight->gain_tlv[1] = 2 * sizeof(unsigned int); |
597 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 583 | |
598 | isight->audio_base + REG_GAIN_DB_START, | 584 | err = reg_read(isight, REG_GAIN_DB_START, &value); |
599 | &value, 4); | ||
600 | if (err < 0) | 585 | if (err < 0) |
601 | return err; | 586 | return err; |
602 | isight->gain_tlv[2] = (s32)be32_to_cpu(value) * 100; | 587 | isight->gain_tlv[2] = (s32)be32_to_cpu(value) * 100; |
603 | err = snd_fw_transaction(isight->unit, TCODE_READ_QUADLET_REQUEST, | 588 | |
604 | isight->audio_base + REG_GAIN_DB_END, | 589 | err = reg_read(isight, REG_GAIN_DB_END, &value); |
605 | &value, 4); | ||
606 | if (err < 0) | 590 | if (err < 0) |
607 | return err; | 591 | return err; |
608 | isight->gain_tlv[3] = (s32)be32_to_cpu(value) * 100; | 592 | isight->gain_tlv[3] = (s32)be32_to_cpu(value) * 100; |