include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / sound / pci / ctxfi / ctatc.c
index a49c766..1bff80c 100644 (file)
@@ -24,6 +24,7 @@
 #include "ctdaio.h"
 #include "cttimer.h"
 #include <linux/delay.h>
+#include <linux/slab.h>
 #include <sound/pcm.h>
 #include <sound/control.h>
 #include <sound/asoundef.h>
@@ -136,7 +137,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        struct snd_pcm_runtime *runtime;
        struct ct_vm *vm;
 
-       if (NULL == apcm->substream)
+       if (!apcm->substream)
                return 0;
 
        runtime = apcm->substream->runtime;
@@ -144,7 +145,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
 
        apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes);
 
-       if (NULL == apcm->vm_block)
+       if (!apcm->vm_block)
                return -ENOENT;
 
        return 0;
@@ -154,7 +155,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
 {
        struct ct_vm *vm;
 
-       if (NULL == apcm->vm_block)
+       if (!apcm->vm_block)
                return;
 
        vm = atc->vm;
@@ -166,18 +167,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
 
 static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index)
 {
-       struct ct_vm *vm;
-       void *kvirt_addr;
-       unsigned long phys_addr;
-
-       vm = atc->vm;
-       kvirt_addr = vm->get_ptp_virt(vm, index);
-       if (kvirt_addr == NULL)
-               phys_addr = (~0UL);
-       else
-               phys_addr = virt_to_phys(kvirt_addr);
-
-       return phys_addr;
+       return atc->vm->get_ptp_phys(atc->vm, index);
 }
 
 static unsigned int convert_format(snd_pcm_format_t snd_format)
@@ -231,16 +221,16 @@ atc_get_pitch(unsigned int input_rate, unsigned int output_rate)
 
 static int select_rom(unsigned int pitch)
 {
-       if ((pitch > 0x00428f5c) && (pitch < 0x01b851ec)) {
+       if (pitch > 0x00428f5c && pitch < 0x01b851ec) {
                /* 0.26 <= pitch <= 1.72 */
                return 1;
-       } else if ((0x01d66666 == pitch) || (0x01d66667 == pitch)) {
+       } else if (pitch == 0x01d66666 || pitch == 0x01d66667) {
                /* pitch == 1.8375 */
                return 2;
-       } else if (0x02000000 == pitch) {
+       } else if (pitch == 0x02000000) {
                /* pitch == 2 */
                return 3;
-       } else if ((pitch >= 0x0) && (pitch <= 0x08000000)) {
+       } else if (pitch <= 0x08000000) {
                /* 0 <= pitch <= 8 */
                return 0;
        } else {
@@ -283,7 +273,7 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        /* Get AMIXER resource */
        n_amixer = (n_amixer < 2) ? 2 : n_amixer;
        apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
-       if (NULL == apcm->amixers) {
+       if (!apcm->amixers) {
                err = -ENOMEM;
                goto error1;
        }
@@ -311,7 +301,7 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                                        INIT_VOL, atc->pcm[i+device*2]);
                mutex_unlock(&atc->atc_mutex);
                src = src->ops->next_interleave(src);
-               if (NULL == src)
+               if (!src)
                        src = apcm->src;
        }
 
@@ -334,7 +324,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        struct srcimp *srcimp;
        int i;
 
-       if (NULL != apcm->srcimps) {
+       if (apcm->srcimps) {
                for (i = 0; i < apcm->n_srcimp; i++) {
                        srcimp = apcm->srcimps[i];
                        srcimp->ops->unmap(srcimp);
@@ -345,7 +335,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                apcm->srcimps = NULL;
        }
 
-       if (NULL != apcm->srccs) {
+       if (apcm->srccs) {
                for (i = 0; i < apcm->n_srcc; i++) {
                        src_mgr->put_src(src_mgr, apcm->srccs[i]);
                        apcm->srccs[i] = NULL;
@@ -354,7 +344,7 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                apcm->srccs = NULL;
        }
 
-       if (NULL != apcm->amixers) {
+       if (apcm->amixers) {
                for (i = 0; i < apcm->n_amixer; i++) {
                        amixer_mgr->put_amixer(amixer_mgr, apcm->amixers[i]);
                        apcm->amixers[i] = NULL;
@@ -363,17 +353,17 @@ atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                apcm->amixers = NULL;
        }
 
-       if (NULL != apcm->mono) {
+       if (apcm->mono) {
                sum_mgr->put_sum(sum_mgr, apcm->mono);
                apcm->mono = NULL;
        }
 
-       if (NULL != apcm->src) {
+       if (apcm->src) {
                src_mgr->put_src(src_mgr, apcm->src);
                apcm->src = NULL;
        }
 
-       if (NULL != apcm->vm_block) {
+       if (apcm->vm_block) {
                /* Undo device virtual mem map */
                ct_unmap_audio_buffer(atc, apcm);
                apcm->vm_block = NULL;
@@ -419,7 +409,7 @@ static int atc_pcm_stop(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        src->ops->set_state(src, SRC_STATE_OFF);
        src->ops->commit_write(src);
 
-       if (NULL != apcm->srccs) {
+       if (apcm->srccs) {
                for (i = 0; i < apcm->n_srcc; i++) {
                        src = apcm->srccs[i];
                        src->ops->set_bm(src, 0);
@@ -544,18 +534,18 @@ atc_pcm_capture_get_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm)
 
        if (n_srcc) {
                apcm->srccs = kzalloc(sizeof(void *)*n_srcc, GFP_KERNEL);
-               if (NULL == apcm->srccs)
+               if (!apcm->srccs)
                        return -ENOMEM;
        }
        if (n_amixer) {
                apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
-               if (NULL == apcm->amixers) {
+               if (!apcm->amixers) {
                        err = -ENOMEM;
                        goto error1;
                }
        }
        apcm->srcimps = kzalloc(sizeof(void *)*n_srcimp, GFP_KERNEL);
-       if (NULL == apcm->srcimps) {
+       if (!apcm->srcimps) {
                err = -ENOMEM;
                goto error1;
        }
@@ -818,7 +808,7 @@ static int spdif_passthru_playback_get_resources(struct ct_atc *atc,
        /* Get AMIXER resource */
        n_amixer = (n_amixer < 2) ? 2 : n_amixer;
        apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL);
-       if (NULL == apcm->amixers) {
+       if (!apcm->amixers) {
                err = -ENOMEM;
                goto error1;
        }
@@ -919,7 +909,7 @@ spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                amixer = apcm->amixers[i];
                amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL);
                src = src->ops->next_interleave(src);
-               if (NULL == src)
+               if (!src)
                        src = apcm->src;
        }
        /* Connect to SPDIFOO */
@@ -1037,7 +1027,7 @@ static int atc_line_front_unmute(struct ct_atc *atc, unsigned char state)
 
 static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state)
 {
-       return atc_daio_unmute(atc, state, LINEO4);
+       return atc_daio_unmute(atc, state, LINEO2);
 }
 
 static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
@@ -1047,7 +1037,7 @@ static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
 
 static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state)
 {
-       return atc_daio_unmute(atc, state, LINEO2);
+       return atc_daio_unmute(atc, state, LINEO4);
 }
 
 static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state)
@@ -1121,7 +1111,7 @@ static int atc_release_resources(struct ct_atc *atc)
        struct ct_mixer *mixer = NULL;
 
        /* disconnect internal mixer objects */
-       if (NULL != atc->mixer) {
+       if (atc->mixer) {
                mixer = atc->mixer;
                mixer->set_input_left(mixer, MIX_LINE_IN, NULL);
                mixer->set_input_right(mixer, MIX_LINE_IN, NULL);
@@ -1131,7 +1121,7 @@ static int atc_release_resources(struct ct_atc *atc)
                mixer->set_input_right(mixer, MIX_SPDIF_IN, NULL);
        }
 
-       if (NULL != atc->daios) {
+       if (atc->daios) {
                daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO];
                for (i = 0; i < atc->n_daio; i++) {
                        daio = atc->daios[i];
@@ -1149,7 +1139,7 @@ static int atc_release_resources(struct ct_atc *atc)
                atc->daios = NULL;
        }
 
-       if (NULL != atc->pcm) {
+       if (atc->pcm) {
                sum_mgr = atc->rsc_mgrs[SUM];
                for (i = 0; i < atc->n_pcm; i++)
                        sum_mgr->put_sum(sum_mgr, atc->pcm[i]);
@@ -1158,7 +1148,7 @@ static int atc_release_resources(struct ct_atc *atc)
                atc->pcm = NULL;
        }
 
-       if (NULL != atc->srcs) {
+       if (atc->srcs) {
                src_mgr = atc->rsc_mgrs[SRC];
                for (i = 0; i < atc->n_src; i++)
                        src_mgr->put_src(src_mgr, atc->srcs[i]);
@@ -1167,7 +1157,7 @@ static int atc_release_resources(struct ct_atc *atc)
                atc->srcs = NULL;
        }
 
-       if (NULL != atc->srcimps) {
+       if (atc->srcimps) {
                srcimp_mgr = atc->rsc_mgrs[SRCIMP];
                for (i = 0; i < atc->n_srcimp; i++) {
                        srcimp = atc->srcimps[i];
@@ -1185,7 +1175,7 @@ static int ct_atc_destroy(struct ct_atc *atc)
 {
        int i = 0;
 
-       if (NULL == atc)
+       if (!atc)
                return 0;
 
        if (atc->timer) {
@@ -1196,21 +1186,20 @@ static int ct_atc_destroy(struct ct_atc *atc)
        atc_release_resources(atc);
 
        /* Destroy internal mixer objects */
-       if (NULL != atc->mixer)
+       if (atc->mixer)
                ct_mixer_destroy(atc->mixer);
 
        for (i = 0; i < NUM_RSCTYP; i++) {
-               if ((NULL != rsc_mgr_funcs[i].destroy) &&
-                   (NULL != atc->rsc_mgrs[i]))
+               if (rsc_mgr_funcs[i].destroy && atc->rsc_mgrs[i])
                        rsc_mgr_funcs[i].destroy(atc->rsc_mgrs[i]);
 
        }
 
-       if (NULL != atc->hw)
+       if (atc->hw)
                destroy_hw_obj((struct hw *)atc->hw);
 
        /* Destroy device virtual memory manager object */
-       if (NULL != atc->vm) {
+       if (atc->vm) {
                ct_vm_destroy(atc->vm);
                atc->vm = NULL;
        }
@@ -1226,10 +1215,11 @@ static int atc_dev_free(struct snd_device *dev)
        return ct_atc_destroy(atc);
 }
 
-static int __devinit atc_identify_card(struct ct_atc *atc)
+static int __devinit atc_identify_card(struct ct_atc *atc, unsigned int ssid)
 {
        const struct snd_pci_quirk *p;
        const struct snd_pci_quirk *list;
+       u16 vendor_id, device_id;
 
        switch (atc->chip_type) {
        case ATC20K1:
@@ -1243,13 +1233,19 @@ static int __devinit atc_identify_card(struct ct_atc *atc)
        default:
                return -ENOENT;
        }
-       p = snd_pci_quirk_lookup(atc->pci, list);
+       if (ssid) {
+               vendor_id = ssid >> 16;
+               device_id = ssid & 0xffff;
+       } else {
+               vendor_id = atc->pci->subsystem_vendor;
+               device_id = atc->pci->subsystem_device;
+       }
+       p = snd_pci_quirk_lookup_id(vendor_id, device_id, list);
        if (p) {
                if (p->value < 0) {
                        printk(KERN_ERR "ctxfi: "
                               "Device %04x:%04x is black-listed\n",
-                              atc->pci->subsystem_vendor,
-                              atc->pci->subsystem_device);
+                              vendor_id, device_id);
                        return -ENOENT;
                }
                atc->model = p->value;
@@ -1262,8 +1258,7 @@ static int __devinit atc_identify_card(struct ct_atc *atc)
        atc->model_name = ct_subsys_name[atc->model];
        snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n",
                   atc->chip_name, atc->model_name,
-                  atc->pci->subsystem_vendor,
-                  atc->pci->subsystem_device);
+                  vendor_id, device_id);
        return 0;
 }
 
@@ -1275,7 +1270,7 @@ int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc)
        alsa_dev_funcs[MIXER].public_name = atc->chip_name;
 
        for (i = 0; i < NUM_CTALSADEVS; i++) {
-               if (NULL == alsa_dev_funcs[i].create)
+               if (!alsa_dev_funcs[i].create)
                        continue;
 
                err = alsa_dev_funcs[i].create(atc, i,
@@ -1312,7 +1307,7 @@ static int __devinit atc_create_hw_devs(struct ct_atc *atc)
                return err;
 
        for (i = 0; i < NUM_RSCTYP; i++) {
-               if (NULL == rsc_mgr_funcs[i].create)
+               if (!rsc_mgr_funcs[i].create)
                        continue;
 
                err = rsc_mgr_funcs[i].create(atc->hw, &atc->rsc_mgrs[i]);
@@ -1339,19 +1334,19 @@ static int atc_get_resources(struct ct_atc *atc)
        int err, i;
 
        atc->daios = kzalloc(sizeof(void *)*(DAIONUM), GFP_KERNEL);
-       if (NULL == atc->daios)
+       if (!atc->daios)
                return -ENOMEM;
 
        atc->srcs = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL);
-       if (NULL == atc->srcs)
+       if (!atc->srcs)
                return -ENOMEM;
 
        atc->srcimps = kzalloc(sizeof(void *)*(2*2), GFP_KERNEL);
-       if (NULL == atc->srcimps)
+       if (!atc->srcimps)
                return -ENOMEM;
 
        atc->pcm = kzalloc(sizeof(void *)*(2*4), GFP_KERNEL);
-       if (NULL == atc->pcm)
+       if (!atc->pcm)
                return -ENOMEM;
 
        daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO];
@@ -1637,7 +1632,8 @@ static struct ct_atc atc_preset __devinitdata = {
 
 int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
                            unsigned int rsr, unsigned int msr,
-                           int chip_type, struct ct_atc **ratc)
+                           int chip_type, unsigned int ssid,
+                           struct ct_atc **ratc)
 {
        struct ct_atc *atc;
        static struct snd_device_ops ops = {
@@ -1648,7 +1644,7 @@ int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
        *ratc = NULL;
 
        atc = kzalloc(sizeof(*atc), GFP_KERNEL);
-       if (NULL == atc)
+       if (!atc)
                return -ENOMEM;
 
        /* Set operations */
@@ -1663,14 +1659,14 @@ int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
        mutex_init(&atc->atc_mutex);
 
        /* Find card model */
-       err = atc_identify_card(atc);
+       err = atc_identify_card(atc, ssid);
        if (err < 0) {
                printk(KERN_ERR "ctatc: Card not recognised\n");
                goto error1;
        }
 
        /* Set up device virtual memory management object */
-       err = ct_vm_create(&atc->vm);
+       err = ct_vm_create(&atc->vm, pci);
        if (err < 0)
                goto error1;