Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=01a3affb2eebfd6c996c36d82bbbc6040eb3a7f1
Commit:     01a3affb2eebfd6c996c36d82bbbc6040eb3a7f1
Parent:     7113e95812f508bff10f95f2e52ce6ee8cda1875
Author:     Clemens Ladisch <[EMAIL PROTECTED]>
AuthorDate: Mon Jan 14 08:56:01 2008 +0100
Committer:  Jaroslav Kysela <[EMAIL PROTECTED]>
CommitDate: Thu Jan 31 17:29:57 2008 +0100

    [ALSA] oxygen: use an array of snd_kcontrol pointers
    
    Use an array for the pointers to known controls so that it is easier to
    add more.
    
    Signed-off-by: Clemens Ladisch <[EMAIL PROTECTED]>
    Signed-off-by: Jaroslav Kysela <[EMAIL PROTECTED]>
---
 sound/pci/oxygen/oxygen.h       |    9 +++++++--
 sound/pci/oxygen/oxygen_lib.c   |    4 ++--
 sound/pci/oxygen/oxygen_mixer.c |   27 +++++++++++++++------------
 sound/pci/oxygen/oxygen_pcm.c   |    8 ++++----
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index 248f7ed..a10c377 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -15,6 +15,12 @@
 #define PCM_AC97       5
 #define PCM_COUNT      6
 
+enum {
+       CONTROL_SPDIF_PCM,
+       CONTROL_SPDIF_INPUT_BITS,
+       CONTROL_COUNT
+};
+
 #define OXYGEN_PCI_SUBID(sv, sd) \
        .vendor = PCI_VENDOR_ID_CMEDIA, \
        .device = 0x8788, \
@@ -50,8 +56,7 @@ struct oxygen {
        u32 spdif_bits;
        u32 spdif_pcm_bits;
        struct snd_pcm_substream *streams[PCM_COUNT];
-       struct snd_kcontrol *spdif_pcm_ctl;
-       struct snd_kcontrol *spdif_input_bits_ctl;
+       struct snd_kcontrol *controls[CONTROL_COUNT];
        struct work_struct spdif_input_bits_work;
 };
 
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 9cd4be2..5b77c94 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -114,7 +114,7 @@ static void oxygen_spdif_input_bits_changed(struct 
work_struct *work)
                }
        }
 
-       if (chip->spdif_input_bits_ctl) {
+       if (chip->controls[CONTROL_SPDIF_INPUT_BITS]) {
                spin_lock_irq(&chip->reg_lock);
                chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_CHANGE;
                oxygen_write16(chip, OXYGEN_INTERRUPT_MASK,
@@ -122,7 +122,7 @@ static void oxygen_spdif_input_bits_changed(struct 
work_struct *work)
                spin_unlock_irq(&chip->reg_lock);
 
                snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
-                              &chip->spdif_input_bits_ctl->id);
+                              &chip->controls[CONTROL_SPDIF_INPUT_BITS]->id);
        }
 }
 
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index ca72799..f7350fa 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -586,15 +586,22 @@ static const struct snd_kcontrol_new controls[] = {
 static void oxygen_any_ctl_free(struct snd_kcontrol *ctl)
 {
        struct oxygen *chip = ctl->private_data;
+       unsigned int i;
 
        /* I'm too lazy to write a function for each control :-) */
-       chip->spdif_pcm_ctl = NULL;
-       chip->spdif_input_bits_ctl = NULL;
+       for (i = 0; i < ARRAY_SIZE(chip->controls); ++i)
+               chip->controls[i] = NULL;
 }
 
 int oxygen_mixer_init(struct oxygen *chip)
 {
-       unsigned int i;
+       static const char *const known_ctl_names[CONTROL_COUNT] = {
+               [CONTROL_SPDIF_PCM] =
+                       SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
+               [CONTROL_SPDIF_INPUT_BITS] =
+                       SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
+       };
+       unsigned int i, j;
        struct snd_kcontrol *ctl;
        int err;
 
@@ -610,15 +617,11 @@ int oxygen_mixer_init(struct oxygen *chip)
                err = snd_ctl_add(chip->card, ctl);
                if (err < 0)
                        return err;
-               if (!strcmp(ctl->id.name,
-                           SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM))) {
-                       chip->spdif_pcm_ctl = ctl;
-                       ctl->private_free = oxygen_any_ctl_free;
-               } else if (!strcmp(ctl->id.name,
-                                SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
-                       chip->spdif_input_bits_ctl = ctl;
-                       ctl->private_free = oxygen_any_ctl_free;
-               }
+               for (j = 0; j < CONTROL_COUNT; ++j)
+                       if (!strcmp(ctl->id.name, known_ctl_names[j])) {
+                               chip->controls[j] = ctl;
+                               ctl->private_free = oxygen_any_ctl_free;
+                       }
        }
        return chip->model->mixer_init ? chip->model->mixer_init(chip) : 0;
 }
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index d4a1d73..5f67a79 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -209,11 +209,11 @@ static int oxygen_open(struct snd_pcm_substream 
*substream,
        chip->pcm_active |= 1 << channel;
        if (channel == PCM_SPDIF) {
                chip->spdif_pcm_bits = chip->spdif_bits;
-               chip->spdif_pcm_ctl->vd[0].access &=
+               chip->controls[CONTROL_SPDIF_PCM]->vd[0].access &=
                        ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
                snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
                               SNDRV_CTL_EVENT_MASK_INFO,
-                              &chip->spdif_pcm_ctl->id);
+                              &chip->controls[CONTROL_SPDIF_PCM]->id);
        }
        mutex_unlock(&chip->mutex);
 
@@ -258,11 +258,11 @@ static int oxygen_close(struct snd_pcm_substream 
*substream)
        mutex_lock(&chip->mutex);
        chip->pcm_active &= ~(1 << channel);
        if (channel == PCM_SPDIF) {
-               chip->spdif_pcm_ctl->vd[0].access |=
+               chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |=
                        SNDRV_CTL_ELEM_ACCESS_INACTIVE;
                snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
                               SNDRV_CTL_EVENT_MASK_INFO,
-                              &chip->spdif_pcm_ctl->id);
+                              &chip->controls[CONTROL_SPDIF_PCM]->id);
        }
        if (channel == PCM_SPDIF || channel == PCM_MULTICH)
                oxygen_update_spdif_source(chip);
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to