Changeset 76


Ignore:
Timestamp:
Apr 9, 2006, 12:09:39 PM (19 years ago)
Author:
vladest
Message:

Latest ALSA patches
HDA patches
Patch for Intel from Rudy's
Fixes locks on NM256 chipsets
Fixes PM on Maestro3 chipsets

Location:
GPL/trunk
Files:
1 added
45 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/alsa-kernel/core/control.c

    r34 r76  
    316316    struct snd_ctl_elem_id id;
    317317    unsigned int idx;
    318 
    319     snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL);
    320     snd_assert(kcontrol->info != NULL, return -EINVAL);
     318    int err = -EINVAL;
     319
     320    if (! kcontrol)
     321        return err;
     322
     323    snd_assert(card != NULL, goto error);
     324    snd_assert(kcontrol->info != NULL, goto error);
     325
    321326    id = kcontrol->id;
    322327    down_write(&card->controls_rwsem);
    323 #if 0 // doesnt works, traps on some systems
     328#if 1 // doesnt works, traps on some systems
    324329    if (snd_ctl_find_id(card, &id)) {
    325330        up_write(&card->controls_rwsem);
     
    331336                   id.name,
    332337                   id.index);
    333         return -EBUSY;
     338        err = -EBUSY;
     339        goto error;
    334340    }
    335341    if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
    336342        up_write(&card->controls_rwsem);
    337         snd_ctl_free_one(kcontrol);
    338         return -ENOMEM;
     343        err = -ENOMEM;
     344        goto error;
    339345    }
    340346#endif
     
    347353        snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
    348354    return 0;
     355
     356error:
     357    snd_ctl_free_one(kcontrol);
     358    return err;
    349359}
    350360
     
    395405}
    396406
    397 static struct snd_kcontrol *_ctl_find_id
    398 (struct snd_card * card, struct snd_ctl_elem_id *id); /* w/o lock */
    399 
    400407/**
    401408 * snd_ctl_remove_unlocked_id - remove the unlocked control of the given id and release it
     
    441448 * Returns zero if successful, or a negative error code on failure.
    442449 */
    443 int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id)
    444 {
    445     struct snd_kcontrol *kctl;
    446 
    447     down_write(&card->controls_rwsem);
    448     kctl = _ctl_find_id(card, src_id);
    449     if (kctl == NULL) {
    450         up_write(&card->controls_rwsem);
    451         return -ENOENT;
    452     }
    453     kctl->id = *dst_id;
    454     kctl->id.numid = card->last_numid + 1;
    455     card->last_numid += kctl->count;
    456     up_write(&card->controls_rwsem);
    457     return 0;
    458 }
    459 
    460 static struct snd_kcontrol *_ctl_find_numid(struct snd_card * card, unsigned int numid)
     450int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
     451                      struct snd_ctl_elem_id *dst_id)
     452{
     453        struct snd_kcontrol *kctl;
     454
     455        down_write(&card->controls_rwsem);
     456        kctl = snd_ctl_find_id(card, src_id);
     457        if (kctl == NULL) {
     458                up_write(&card->controls_rwsem);
     459                return -ENOENT;
     460        }
     461        kctl->id = *dst_id;
     462        kctl->id.numid = card->last_numid + 1;
     463        card->last_numid += kctl->count;
     464        up_write(&card->controls_rwsem);
     465        return 0;
     466}
     467
     468/**
     469 * snd_ctl_find_numid - find the control instance with the given number-id
     470 * @card: the card instance
     471 * @numid: the number-id to search
     472 *
     473 * Finds the control instance with the given number-id from the card.
     474 *
     475 * Returns the pointer of the instance if found, or NULL if not.
     476 *
     477 * The caller must down card->controls_rwsem before calling this function
     478 * (if the race condition can happen).
     479 */
     480struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid)
    461481{
    462482    struct list_head *list;
    463483    struct snd_kcontrol *kctl;
    464484
    465     snd_runtime_check(card != NULL && numid != 0, return NULL);
     485    snd_assert(card != NULL && numid != 0, return NULL);
    466486    list_for_each(list, &card->controls) {
    467487        kctl = snd_kcontrol(list);
     
    472492}
    473493
    474 static struct snd_kcontrol *_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id)
    475 {
    476     struct list_head *list;
    477     struct snd_kcontrol *kctl;
    478 
    479     snd_runtime_check(card != NULL && id != NULL, return NULL);
    480     if (id->numid != 0)
    481         return _ctl_find_numid(card, id->numid);
    482     list_for_each(list, &card->controls) {
    483         kctl = snd_kcontrol(list);
    484         if (kctl->id.iface != id->iface)
    485             continue;
    486         if (kctl->id.device != id->device)
    487             continue;
    488         if (kctl->id.subdevice != id->subdevice)
    489             continue;
    490         if (strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)))
    491             continue;
    492         if (kctl->id.index > id->index)
    493             continue;
    494         if (kctl->id.index + kctl->count <= id->index)
    495             continue;
    496         return kctl;
    497     }
    498     return NULL;
    499 }
    500 
    501494/**
    502  * snd_ctl_find_id - find the control instance with the given id
    503  * @card: the card instance
    504  * @id: the id to search
    505  *
    506  * Finds the control instance with the given id from the card.
    507  *
    508  * Returns the pointer of the instance if found, or NULL if not.
    509  */
    510 struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id)
    511 {
    512     struct snd_kcontrol *kctl;
    513     down_read(&card->controls_rwsem);
    514     kctl = _ctl_find_id(card, id);
    515     up_read(&card->controls_rwsem);
    516     return kctl;
    517 }
    518 
    519 /**
    520  * snd_ctl_find_numid - find the control instance with the given number-id
    521  * @card: the card instance
    522  * @numid: the number-id to search
    523  *
    524  * Finds the control instance with the given number-id from the card.
    525  *
    526  * Returns the pointer of the instance if found, or NULL if not.
    527  */
    528 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid)
    529 {
    530     struct snd_kcontrol *kctl;
    531     down_read(&card->controls_rwsem);
    532     kctl = _ctl_find_numid(card, numid);
    533     up_read(&card->controls_rwsem);
    534     return kctl;
    535 }
     495* snd_ctl_find_id - find the control instance with the given id
     496* @card: the card instance
     497* @id: the id to search
     498*
     499    * Finds the control instance with the given id from the card.
     500    *
     501    * Returns the pointer of the instance if found, or NULL if not.
     502        *
     503            * The caller must down card->controls_rwsem before calling this function
     504            * (if the race condition can happen).
     505            */
     506            struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card,
     507                                                 struct snd_ctl_elem_id *id)
     508    {
     509        struct list_head *list;
     510        struct snd_kcontrol *kctl;
     511
     512        snd_assert(card != NULL && id != NULL, return NULL);
     513        if (id->numid != 0)
     514            return snd_ctl_find_numid(card, id->numid);
     515        list_for_each(list, &card->controls) {
     516            kctl = snd_kcontrol(list);
     517            if (kctl->id.iface != id->iface)
     518                continue;
     519            if (kctl->id.device != id->device)
     520                continue;
     521            if (kctl->id.subdevice != id->subdevice)
     522                continue;
     523            if (strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)))
     524                continue;
     525            if (kctl->id.index > id->index)
     526                continue;
     527            if (kctl->id.index + kctl->count <= id->index)
     528                continue;
     529            return kctl;
     530        }
     531        return NULL;
     532    }
    536533
    537534static int snd_ctl_card_info(struct snd_card * card, struct snd_ctl_file * ctl,
     
    617614}
    618615
    619 static int snd_ctl_elem_info(struct snd_ctl_file *ctl, struct snd_ctl_elem_info *_info)
     616static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
     617                             struct snd_ctl_elem_info *info)
    620618{
    621619    struct snd_card *card = ctl->card;
    622     struct snd_ctl_elem_info info;
    623620    struct snd_kcontrol *kctl;
    624621    struct snd_kcontrol_volatile *vd;
     
    626623    int result;
    627624
    628     if (copy_from_user(&info, _info, sizeof(info)))
    629         return -EFAULT;
    630625    down_read(&card->controls_rwsem);
    631     kctl = _ctl_find_id(card, &info.id);
     626    kctl = snd_ctl_find_id(card, &info->id);
    632627    if (kctl == NULL) {
    633628        up_read(&card->controls_rwsem);
     
    635630    }
    636631#ifdef CONFIG_SND_DEBUG
    637     info.access = 0;
     632    info->access = 0;
    638633#endif
    639     result = kctl->info(kctl, &info);
     634    result = kctl->info(kctl, info);
    640635    if (result >= 0) {
    641         snd_assert(info.access == 0, );
    642         index_offset = snd_ctl_get_ioff(kctl, &info.id);
     636        snd_assert(info->access == 0, );
     637        index_offset = snd_ctl_get_ioff(kctl, &info->id);
    643638        vd = &kctl->vd[index_offset];
    644         snd_ctl_build_ioff(&info.id, kctl, index_offset);
    645         info.access = vd->access;
     639        snd_ctl_build_ioff(&info->id, kctl, index_offset);
     640        info->access = vd->access;
    646641        if (vd->owner) {
    647             info.access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
     642            info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
    648643            if (vd->owner == ctl)
    649                 info.access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
    650             info.owner = vd->owner_pid;
     644                info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
     645            info->owner = vd->owner_pid;
    651646        } else {
    652             info.owner = -1;
     647            info->owner = -1;
    653648        }
    654649    }
    655650    up_read(&card->controls_rwsem);
    656     if (result >= 0)
    657         if (copy_to_user(_info, &info, sizeof(info)))
    658             return -EFAULT;
    659651    return result;
    660652}
    661 #if 0
    662 int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *_control)
    663 {
    664 
    665     struct snd_ctl_elem_value *control;
    666     struct snd_kcontrol *kctl;
    667     struct snd_kcontrol_volatile *vd;
    668     unsigned int index_offset;
    669     int result, indirect;
    670 
    671     control = kmalloc(sizeof(*control), GFP_KERNEL);
    672     if (control == NULL)
    673         return -ENOMEM;
    674     if (copy_from_user(control, _control, sizeof(*control)))
    675         return -EFAULT;
    676     down_read(&card->controls_rwsem);
    677     kctl = _ctl_find_id(card, &control->id);
    678     if (kctl == NULL) {
    679         result = -ENOENT;
    680     } else {
    681         index_offset = snd_ctl_get_ioff(kctl, &control->id);
    682         vd = &kctl->vd[index_offset];
    683         indirect = vd->access & SNDRV_CTL_ELEM_ACCESS_INDIRECT ? 1 : 0;
    684         if (control->indirect != indirect) {
    685             result = -EACCES;
    686         } else {
    687             if ((vd->access & SNDRV_CTL_ELEM_ACCESS_READ) && kctl->get != NULL) {
    688                 snd_ctl_build_ioff(&control->id, kctl, index_offset);
    689                 result = kctl->get(kctl, control);
    690             } else {
    691                 result = -EPERM;
    692             }
    693         }
    694     }
    695     up_read(&card->controls_rwsem);
    696     if (result >= 0)
    697         if (copy_to_user(_control, control, sizeof(*control)))
    698             return -EFAULT;
    699     kfree(control);
    700     return result;
    701 }
    702 
    703 int snd_ctl_elem_write(struct snd_ctl_file *file, struct snd_ctl_elem_value *_control)
    704 {
    705     struct snd_card *card = file->card;
    706     struct snd_ctl_elem_value *control;
    707     struct snd_kcontrol *kctl;
    708     struct snd_kcontrol_volatile *vd;
    709     unsigned int index_offset;
    710     int result, indirect;
    711 
    712     control = kmalloc(sizeof(*control), GFP_KERNEL);
    713     if (control == NULL)
    714         return -ENOMEM;
    715     if (copy_from_user(control, _control, sizeof(*control)))
    716         return -EFAULT;
    717     down_read(&card->controls_rwsem);
    718     kctl = _ctl_find_id(card, &control->id);
    719     if (kctl == NULL) {
    720         result = -ENOENT;
    721     } else {
    722         index_offset = snd_ctl_get_ioff(kctl, &control->id);
    723         vd = &kctl->vd[index_offset];
    724         indirect = vd->access & SNDRV_CTL_ELEM_ACCESS_INDIRECT ? 1 : 0;
    725         if (control->indirect != indirect) {
    726             result = -EACCES;
    727         } else {
    728             if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_WRITE) ||
    729                 kctl->put == NULL ||
    730                 (vd->owner != NULL && vd->owner != file)) {
    731                 result = -EPERM;
    732             } else {
    733                 snd_ctl_build_ioff(&control->id, kctl, index_offset);
    734                 result = kctl->put(kctl, control);
    735             }
    736             if (result > 0) {
    737                 up_read(&card->controls_rwsem);
    738                 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &control->id);
    739                 result = 0;
    740                 goto __unlocked;
    741             }
    742         }
    743     }
    744     up_read(&card->controls_rwsem);
    745 __unlocked:
    746     if (result >= 0)
    747         if (copy_to_user(_control, control, sizeof(*control)))
    748             return -EFAULT;
    749     kfree(control);
    750     return result;
    751 }
    752 #else
     653
    753654int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *control)
    754655{
     
    785686        struct snd_ctl_elem_value *control;
    786687        int result;
    787        
     688
    788689        control = kmalloc(sizeof(*control), GFP_KERNEL);
    789690        if (control == NULL)
    790                 return -ENOMEM; 
     691                return -ENOMEM;
    791692        if (copy_from_user(control, _control, sizeof(*control))) {
    792693                kfree(control);
     
    845746        control = kmalloc(sizeof(*control), GFP_KERNEL);
    846747        if (control == NULL)
    847                 return -ENOMEM; 
     748                return -ENOMEM;
    848749        if (copy_from_user(control, _control, sizeof(*control))) {
    849750                kfree(control);
     
    858759}
    859760
    860 #endif
    861 static int snd_ctl_elem_lock(struct snd_ctl_file *file, struct snd_ctl_elem_id *_id)
     761
     762static int snd_ctl_elem_lock(struct snd_ctl_file *file,
     763                             struct snd_ctl_elem_id __user *_id)
    862764{
    863765    struct snd_card *card = file->card;
     
    870772        return -EFAULT;
    871773    down_write(&card->controls_rwsem);
    872     kctl = _ctl_find_id(card, &id);
     774    kctl = snd_ctl_find_id(card, &id);
    873775    if (kctl == NULL) {
    874776        result = -ENOENT;
     
    887789}
    888790
    889 static int snd_ctl_elem_unlock(struct snd_ctl_file *file, struct snd_ctl_elem_id *_id)
     791static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
     792                               struct snd_ctl_elem_id __user *_id)
    890793{
    891794    struct snd_card *card = file->card;
     
    898801        return -EFAULT;
    899802    down_write(&card->controls_rwsem);
    900     kctl = _ctl_find_id(card, &id);
     803    kctl = snd_ctl_find_id(card, &id);
    901804    if (kctl == NULL) {
    902805        result = -ENOENT;
     
    948851        int change;
    949852        struct user_element *ue = kcontrol->private_data;
    950        
     853
    951854        change = memcmp(&ucontrol->value, ue->elem_data, ue->elem_data_size) != 0;
    952855        if (change)
     
    970873        struct user_element *ue;
    971874        int idx, err;
    972        
     875
    973876        if (card->user_ctl_count >= MAX_USER_CONTROLS)
    974877                return -ENOMEM;
  • GPL/trunk/alsa-kernel/core/memalloc.c

    r32 r76  
    149149        res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
    150150        if (res != NULL) {
    151 #ifdef NEED_RESERVE_PAGES
    152                 mark_pages(virt_to_page(res), pg); /* should be dma_to_page() */
    153 #endif
    154151                inc_snd_pages(pg);
    155152        }
     
    168165        pg = get_order(size);
    169166        dec_snd_pages(pg);
    170 #ifdef NEED_RESERVE_PAGES
    171         unmark_pages(virt_to_page(ptr), pg); /* should be dma_to_page() */
    172 #endif
    173167        dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
    174168}
     
    402396}
    403397
    404 static void mark_pages(struct page *page, int order)
    405 {
    406     struct page *last_page = page + (1 << order);
    407     while (page < last_page)
    408         SetPageReserved(page++);
    409 }
    410 
    411 static void unmark_pages(struct page *page, int order)
    412 {
    413     struct page *last_page = page + (1 << order);
    414     while (page < last_page)
    415         ClearPageReserved(page++);
    416 }
    417398
    418399/**
     
    434415    pg = get_order(size);
    435416    if ((res = (void *) __get_free_pages(dma_flags, pg)) != NULL) {
    436         mark_pages(virt_to_page(res), pg);
    437417        inc_snd_pages(pg);
    438418    }
     
    456436    pg = get_order(size);
    457437    dec_snd_pages(pg);
    458     unmark_pages(virt_to_page(ptr), pg);
    459438    free_pages((unsigned long) ptr, pg);
    460439}
     
    532511        res = pci_alloc_consistent(pci, PAGE_SIZE * (1 << pg), dmaaddr);
    533512        if (res != NULL) {
    534 #ifdef NEED_RESERVE_PAGES
    535             mark_pages(virt_to_page(res), pg); /* should be dma_to_page() */
    536 #endif
    537513            inc_snd_pages(pg);
    538514        }
     
    589565        for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
    590566        dec_snd_pages(pg);
    591 #ifdef NEED_RESERVE_PAGES
    592         unmark_pages(virt_to_page(ptr), pg); /* should be dma_to_page() */
    593 #endif
    594567        pci_free_consistent(pci, PAGE_SIZE * (1 << pg), ptr, dmaaddr);
    595568}
     
    638611        if (ptr) {
    639612                memset(ptr, 0, PAGE_SIZE);
    640                 mark_pages(ptr, 0);
    641613        }
    642614        *addrp = addr;
  • GPL/trunk/alsa-kernel/core/pcm_native.c

    r35 r76  
    11061106static int snd_pcm_pre_resume(snd_pcm_substream_t *substream, int state)
    11071107{
    1108     snd_pcm_runtime_t *runtime = substream->runtime;
     1108    snd_pcm_runtime_t *runtime;
     1109    if (substream) runtime = substream->runtime;
     1110    if (!runtime) return 0;
    11091111    if (!(runtime->info & SNDRV_PCM_INFO_RESUME))
    11101112        return -ENOSYS;
     
    11151117static int snd_pcm_do_resume(snd_pcm_substream_t *substream, int state)
    11161118{
    1117     snd_pcm_runtime_t *runtime = substream->runtime;
     1119    snd_pcm_runtime_t *runtime;
     1120    if (substream) runtime = substream->runtime;
     1121    if (!runtime) return 0;
    11181122    if (runtime->trigger_master != substream)
    11191123        return 0;
     
    11231127         substream->stream != SNDRV_PCM_STREAM_PLAYBACK))
    11241128        return 0;
    1125     return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME);
     1129    if (substream->ops->trigger)
     1130        return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME);
     1131    else return 0;
    11261132}
    11271133
     
    11351141static void snd_pcm_post_resume(snd_pcm_substream_t *substream, int state)
    11361142{
    1137     snd_pcm_runtime_t *runtime = substream->runtime;
     1143    snd_pcm_runtime_t *runtime;
     1144    if (substream) runtime = substream->runtime;
     1145    if (!runtime) return;
    11381146    snd_pcm_trigger_tstamp(substream);
    11391147    if (substream->timer)
     
    11531161static int snd_pcm_resume(snd_pcm_substream_t *substream)
    11541162{
    1155     snd_card_t *card = substream->pcm->card;
     1163    snd_card_t *card;
    11561164    int res;
    11571165
    1158     snd_power_lock(card);
    1159     if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile)) >= 0)
    1160         res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0);
    1161     snd_power_unlock(card);
     1166    if(substream && substream->pcm)
     1167    {
     1168        card = substream->pcm->card;
     1169        snd_power_lock(card);
     1170        if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile)) >= 0)
     1171            res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0);
     1172        snd_power_unlock(card);
     1173    }
    11621174    return res;
    11631175}
     
    20602072    err = snd_pcm_hw_constraints_init(substream);
    20612073    if (err < 0) {
    2062         snd_printd("snd_pcm_hw_constraints_init failed\n");
     2074        snd_printd("snd_pcm_hw_constraints_init failed: %i\n", err);
    20632075        snd_pcm_release_file(pcm_file);
    20642076        return err;
     
    20672079    if ((err = substream->ops->open(substream)) < 0) {
    20682080        snd_pcm_release_file(pcm_file);
     2081        snd_printd("supbstream open failed: %i\n", err);
    20692082        return err;
    20702083    }
     
    20732086    err = snd_pcm_hw_constraints_complete(substream);
    20742087    if (err < 0) {
    2075         snd_printd("snd_pcm_hw_constraints_complete failed\n");
     2088        snd_printd("snd_pcm_hw_constraints_complete failed: %i\n", err);
    20762089        snd_pcm_release_file(pcm_file);
    20772090        return err;
     
    25322545    case SNDRV_PCM_IOCTL_DROP:
    25332546        return snd_pcm_drop(substream);
     2547    case SNDRV_PCM_IOCTL_PAUSE:
     2548        {
     2549            int res;
     2550            snd_pcm_stream_lock_irq(substream);
     2551            res = snd_pcm_pause(substream, (int)(unsigned long)arg);
     2552            snd_pcm_stream_unlock_irq(substream);
     2553            return res;
     2554        }
    25342555    }
    25352556    snd_printd("unknown ioctl = 0x%x\n", cmd);
     
    26112632            return result < 0 ? result : 0;
    26122633        }
    2613     case SNDRV_PCM_IOCTL_PAUSE:
    2614         {
    2615             int res;
    2616             snd_pcm_stream_lock_irq(substream);
    2617             res = snd_pcm_pause(substream, (long) arg);
    2618             snd_pcm_stream_unlock_irq(substream);
    2619             return res;
    2620         }
    26212634    }
    26222635    return snd_pcm_common_ioctl1(substream, cmd, arg);
  • GPL/trunk/alsa-kernel/include/sound/ac97_codec.h

    r71 r76  
    306306#define AC97_ALC650_SOUCE_MASK      0x000f  /* Source number */
    307307#define AC97_ALC650_CHANNEL_MASK    0x00f0  /* Channel number */
    308 #define AC97_ALC650_CHANNEL_SHIFT   4 
     308#define AC97_ALC650_CHANNEL_SHIFT   4
    309309#define AC97_ALC650_SPSR_MASK       0x0f00  /* S/PDIF Sample Rate bits */
    310310#define AC97_ALC650_SPSR_SHIFT      8
     
    434434};
    435435
     436/* static resolution table */
     437struct snd_ac97_res_table {
     438    unsigned short reg;     /* register */
     439    unsigned short bits;    /* resolution bitmask */
     440};
     441
    436442struct snd_ac97_template {
    437443        void *private_data;
     
    441447        unsigned short addr;    /* physical address of codec [0-3] */
    442448        unsigned int scaps;     /* driver capabilities */
    443         unsigned int limited_regs; /* allow limited registers only */
    444         DECLARE_BITMAP(reg_accessed, 0x80); /* bit flags */
     449        const struct snd_ac97_res_table *res_table;     /* static resolution */
    445450};
    446451
     
    464469        unsigned short caps;    /* capabilities (register 0) */
    465470        unsigned short ext_id;  /* extended feature identification (register 28) */
    466         unsigned short ext_mid; /* extended modem ID (register 3C) */
     471        unsigned short ext_mid; /* extended modem ID (register 3C) */
     472        const struct snd_ac97_res_table *res_table;     /* static resolution */
    467473        unsigned int scaps;     /* driver capabilities */
    468474        unsigned int flags;     /* specific code */
     
    470476        unsigned int spdif_status;
    471477        unsigned short regs[0x80]; /* register cache */
    472         unsigned int limited_regs; /* allow limited registers only */
    473478        DECLARE_BITMAP(reg_accessed, 0x80); /* bit flags */
    474479        union {                 /* vendor specific code */
  • GPL/trunk/alsa-kernel/include/sound/driver.h

    r73 r76  
    655655                ##retval;\
    656656        }
    657 
    658657#define snd_runtime_check snd_assert
    659658
     
    749748typedef unsigned gfp_t;
    750749
     750#ifndef cpu_relax
     751#define cpu_relax()
     752#endif
     753
    751754#endif                          /* __DRIVER_H */
  • GPL/trunk/alsa-kernel/pci/ac97/ac97_codec.c

    r72 r76  
    144144{ 0x49434511, 0xffffffff, "ICE1232",            NULL,           NULL }, // alias VIA VT1611A?
    145145{ 0x49434514, 0xffffffff, "ICE1232A",           NULL,           NULL },
    146 { 0x49434551, 0xffffffff, "VT1616",             patch_vt1616,   NULL }, 
     146{ 0x49434551, 0xffffffff, "VT1616",             patch_vt1616,   NULL },
    147147{ 0x49434552, 0xffffffff, "VT1616i",            patch_vt1616,   NULL }, // VT1616 compatible (chipset integrated)
    148148{ 0x49544520, 0xffffffff, "IT2226E",            NULL,           NULL },
     
    151151{ 0x4e534331, 0xffffffff, "LM4549",             NULL,           NULL },
    152152{ 0x4e534350, 0xffffffff, "LM4550",             NULL,           NULL },
     153{ 0x4e534350, 0xffffffff, "LM4550",             patch_lm4550,   NULL }, // volume wrap fix
    153154{ 0x50534304, 0xffffffff, "UCB1400",            NULL,           NULL },
    154155{ 0x53494c20, 0xffffffe0, "Si3036,8",           mpatch_si3036,  mpatch_si3036, AC97_MODEM_PATCH },
     
    192193static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
    193194{
    194         if (ac97->limited_regs && ! test_bit(reg, ac97->reg_accessed))
    195                 return 0;
    196 
    197195        /* filter some registers for buggy codecs */
    198196        switch (ac97->id) {
     
    257255/**
    258256 * snd_ac97_read - read a value from the given register
    259  * 
     257 *
    260258 * @ac97: the ac97 instance
    261259 * @reg: the register to read
     
    411409{
    412410        struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
    413        
     411
    414412        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    415413        uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
    416414        uinfo->value.enumerated.items = e->mask;
    417        
     415
    418416        if (uinfo->value.enumerated.item > e->mask - 1)
    419417                uinfo->value.enumerated.item = e->mask - 1;
     
    427425        struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
    428426        unsigned short val, bitmask;
    429        
     427
    430428        for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
    431429                ;
     
    444442        unsigned short val;
    445443        unsigned short mask, bitmask;
    446        
     444
    447445        for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
    448446                ;
     
    530528        int err, page_save;
    531529        unsigned short val, val2, val_mask;
    532        
     530
    533531        page_save = snd_ac97_page_save(ac97, reg, kcontrol);
    534532        val = (ucontrol->value.integer.value[0] & mask);
     
    580578};
    581579
    582 static const struct snd_kcontrol_new snd_ac97_control_capture_src = 
    583 AC97_ENUM("Capture Source", std_enum[0]); 
     580static const struct snd_kcontrol_new snd_ac97_control_capture_src =
     581AC97_ENUM("Capture Source", std_enum[0]);
    584582
    585583static const struct snd_kcontrol_new snd_ac97_control_capture_vol =
     
    648646        return 0;
    649647}
    650                        
     648
    651649static int snd_ac97_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    652650{
     
    660658        return 0;
    661659}
    662                        
     660
    663661static int snd_ac97_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    664662{
     
    683681        return 0;
    684682}
    685                        
     683
    686684static int snd_ac97_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    687685{
     
    735733                v = new & (IEC958_AES0_CON_EMPHASIS_5015|IEC958_AES0_CON_NOT_COPYRIGHT) ? 0 : AC97_CXR_COPYRGT;
    736734                v |= new & IEC958_AES0_NONAUDIO ? AC97_CXR_SPDIF_AC3 : AC97_CXR_SPDIF_PCM;
    737                 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC, 
     735                change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
    738736                                                      AC97_CXR_SPDIF_MASK | AC97_CXR_COPYRGT,
    739737                                                      v);
     
    845843        int rshift = (kcontrol->private_value >> 12) & 0x0f;
    846844        int mask = (kcontrol->private_value >> 16) & 0xff;
    847        
     845
    848846        ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
    849847        if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
     
    860858        int mask = (kcontrol->private_value >> 16) & 0xff;
    861859        unsigned short val, valmask;
    862        
     860
    863861        val = (mask - (ucontrol->value.integer.value[0] & mask)) << lshift;
    864862        valmask = mask << lshift;
     
    888886        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
    889887        int codec = kcontrol->private_value & 3;
    890        
     888
    891889        down(&ac97->page_mutex);
    892890        ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
     
    901899        int codec = kcontrol->private_value & 3;
    902900        unsigned short val1, val2;
    903        
     901
    904902        val1 = 31 - (ucontrol->value.integer.value[0] & 31);
    905903        val2 = 31 - (ucontrol->value.integer.value[1] & 31);
     
    10081006        }
    10091007
    1010         if (ac97->limited_regs && test_bit(reg, ac97->reg_accessed))
    1011                 return 1; /* allow without check */
    1012 
    10131008        val = snd_ac97_read(ac97, reg);
    10141009        if (!(val & mask)) {
     
    10301025        int i;
    10311026
    1032         *lo_max = *hi_max = 0;
     1027        /* first look up the static resolution table */
     1028        if (ac97->res_table) {
     1029            const struct snd_ac97_res_table *tbl;
     1030            for (tbl = ac97->res_table; tbl->reg; tbl++) {
     1031                if (tbl->reg == reg) {
     1032                    *lo_max = tbl->bits & 0xff;
     1033                    *hi_max = (tbl->bits >> 8) & 0xff;
     1034                    return;
     1035                }
     1036            }
     1037        }
     1038
     1039        *lo_max = *hi_max = 0;
    10331040        for (i = 0 ; i < ARRAY_SIZE(cbit); i++) {
    10341041                unsigned short val;
     
    12431250        /* build master controls */
    12441251        /* AD claims to remove this control from AD1887, although spec v2.2 does not allow this */
    1245         if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
     1252        if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
     1253#ifndef TARGET_OS2
    12461254                if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
    12471255                        err = snd_ac97_cmute_new(card, "Master Playback Switch", AC97_MASTER, ac97);
    1248                 else
     1256                else
     1257#endif
    12491258                        err = snd_ac97_cmix_new(card, "Master Playback", AC97_MASTER, ac97);
    12501259                if (err < 0)
     
    12901299                        return err;
    12911300        }
    1292        
     1301
    12931302        /* build master mono controls */
    12941303        if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
     
    12961305                        return err;
    12971306        }
    1298        
     1307
    12991308        /* build master tone controls */
    13001309        if (!(ac97->flags & AC97_HAS_NO_TONE)) {
     
    13111320                }
    13121321        }
    1313        
     1322
    13141323        /* build PC Speaker controls */
    1315         if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 
     1324        if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
    13161325                ((ac97->flags & AC97_HAS_PC_BEEP) ||
    13171326            snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
     
    13221331                                     snd_ac97_read(ac97, AC97_PC_BEEP) | 0x801e);
    13231332        }
    1324        
     1333
    13251334        /* build Phone controls */
    13261335        if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
     
    13301339                }
    13311340        }
    1332        
     1341
    13331342        /* build MIC controls */
    13341343        if (!(ac97->flags & AC97_HAS_NO_MIC)) {
     
    13461355                        return err;
    13471356        }
    1348        
     1357
    13491358        /* build CD controls */
    13501359        if (!(ac97->flags & AC97_HAS_NO_CD)) {
     
    13541363                }
    13551364        }
    1356        
     1365
    13571366        /* build Video controls */
    13581367        if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
     
    13971406                snd_ac97_write_cache(ac97, AC97_PCM, init_val);
    13981407        } else {
    1399                 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
     1408            if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
     1409#ifndef TARGET_OS2
    14001410                        if (ac97->flags & AC97_HAS_NO_PCM_VOL)
    14011411                                err = snd_ac97_cmute_new(card, "PCM Playback Switch", AC97_PCM, ac97);
    1402                         else
     1412                        else
     1413#endif
    14031414                                err = snd_ac97_cmix_new(card, "PCM Playback", AC97_PCM, ac97);
    14041415                        if (err < 0)
     
    15141525                ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
    15151526        }
    1516        
     1527
    15171528        /* build chip specific controls */
    15181529        if (ac97->build_ops->build_specific)
     
    15751586        unsigned short saved;
    15761587
    1577         if (ac97->bus->no_vra) {
     1588        if (ac97->bus->no_vra || !(ac97->ext_id & AC97_EI_VRA) ) {
    15781589                *r_result = SNDRV_PCM_RATE_48000;
    15791590                if ((ac97->flags & AC97_DOUBLE_RATE) &&
     
    16781689                    (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
    16791690                        pid->patch(ac97);
    1680         } 
     1691        }
    16811692
    16821693        pid = look_for_codec_id(snd_ac97_codec_ids, id);
     
    17221733        end_time = jiffies + timeout;
    17231734        do {
    1724                
     1735
    17251736                /* use preliminary reads to settle the communication */
    17261737                snd_ac97_read(ac97, AC97_RESET);
     
    17651776 * The ops table must include valid callbacks (at least read and
    17661777 * write).  The other callbacks, wait and reset, are not mandatory.
    1767  * 
     1778 *
    17681779 * The clock is set to 48000.  If another clock is needed, set
    17691780 * (*rbus)->clock manually.
     
    18601871 * The template must include the codec number (num) and address (addr),
    18611872 * and the private data (private_data).
    1862  * 
     1873 *
    18631874 * The ac97 instance is registered as a low-level device, so you don't
    18641875 * have to release it manually.
     
    18971908        ac97->addr = template->addr;
    18981909        ac97->scaps = template->scaps;
    1899         ac97->limited_regs = template->limited_regs;
    1900         memcpy(ac97->reg_accessed, template->reg_accessed, sizeof(ac97->reg_accessed));
     1910        ac97->res_table = template->res_table;
    19011911        bus->codec[ac97->num] = ac97;
    19021912        init_MUTEX(&ac97->reg_mutex);
     
    19551965        if (pid)
    19561966                ac97->flags |= pid->flags;
    1957        
     1967
    19581968        /* test for AC'97 */
    19591969        if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
     
    20402050                snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
    20412051        }
    2042        
     2052
    20432053      __ready_ok:
    20442054        if (ac97_is_audio(ac97))
     
    21392149        if (ac97->scaps && ac97_is_audio(ac97)) {
    21402150                reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
    2141                 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 
     2151                if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
    21422152                        reg &= ~AC97_EA_PRJ;
    2143                 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) 
     2153                if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
    21442154                        reg &= ~(AC97_EA_PRI | AC97_EA_PRK);
    21452155                snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
     
    23162326        else
    23172327                strcpy(dst, src);
    2318 }       
     2328}
    23192329
    23202330/* remove the control with the given name and optional suffix */
     
    24432453}
    24442454
    2445 static const struct snd_kcontrol_new snd_ac97_alc_jack_detect = 
     2455static const struct snd_kcontrol_new snd_ac97_alc_jack_detect =
    24462456AC97_SINGLE("Jack Detect", AC97_ALC650_CLOCK, 5, 1, 0);
    24472457
  • GPL/trunk/alsa-kernel/pci/ac97/ac97_patch.c

    r72 r76  
    390390        /* This is known to work for the ViewSonic ViewPad 1000
    391391         * Randolph Bentson <bentson@holmsjoen.com>
    392          * WM9703/9707/9708/9717 
     392         * WM9703/9707/9708/9717
    393393         */
    394394        int err, i;
    395        
     395
    396396        for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
    397397                if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
     
    474474static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
    475475static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
    476 static const char* wm9711_rec_sel[] = 
     476static const char* wm9711_rec_sel[] =
    477477        {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
    478478static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
     
    572572{
    573573        int err, i;
    574        
     574
    575575        for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
    576576                if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
     
    597597        ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
    598598                AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
    599        
     599
    600600        return 0;
    601601}
     
    603603static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
    604604static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
    605 static const char* wm9713_rec_src[] = 
    606         {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 
     605static const char* wm9713_rec_src[] =
     606        {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
    607607        "Mono Mix", "Zh"};
    608608static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
    609609static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
    610610static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
    611 static const char* wm9713_spk_pga[] = 
     611static const char* wm9713_spk_pga[] =
    612612        {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
    613613static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
    614614static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
    615615static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
    616 static const char* wm9713_dac_inv[] = 
    617         {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 
     616static const char* wm9713_dac_inv[] =
     617        {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
    618618        "Headphone Mix Mono", "NC", "Vmid"};
    619619static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
     
    739739{
    740740        int err, i;
    741    
     741
    742742        for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
    743743                if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
     
    750750{
    751751        int err, i;
    752        
     752
    753753        for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
    754754                if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
     
    783783        .build_specific = patch_wolfson_wm9713_specific,
    784784        .build_3d = patch_wolfson_wm9713_3d,
    785 #ifdef CONFIG_PM       
     785#ifdef CONFIG_PM
    786786        .suspend = patch_wolfson_wm9713_suspend,
    787787        .resume = patch_wolfson_wm9713_resume
     
    11841184
    11851185        /* Gateway M675 notebook */
    1186         if (ac97->pci && 
     1186        if (ac97->pci &&
    11871187            ac97->subsystem_vendor == 0x107b &&
    11881188            ac97->subsystem_device == 0x0601)
     
    12481248
    12491249        ac97->build_ops = &patch_cirrus_ops;
    1250         ac97->flags |= AC97_CS_SPDIF; 
     1250        ac97->flags |= AC97_CS_SPDIF;
    12511251        ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
    12521252        ac97->ext_id |= AC97_EI_SPDIF;  /* force the detection of spdif */
     
    12591259        /* force the detection of PC Beep */
    12601260        ac97->flags |= AC97_HAS_PC_BEEP;
    1261        
     1261
    12621262        return patch_cirrus_spdif(ac97);
    12631263}
     
    13981398        static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
    13991399        unsigned short val;
    1400        
     1400
    14011401        snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
    14021402        snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004);  // SDIE
     
    14491449                {0, 1}
    14501450        };
    1451        
     1451
    14521452        // patch for Analog Devices
    14531453        unsigned short codecs[3];
     
    14871487                /* ok, deselect all ID bits */
    14881488                snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
    1489                 ac97->spec.ad18xx.codec_cfg[0] = 
    1490                         ac97->spec.ad18xx.codec_cfg[1] = 
     1489                ac97->spec.ad18xx.codec_cfg[0] =
     1490                        ac97->spec.ad18xx.codec_cfg[1] =
    14911491                        ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
    14921492        }
     
    18461846{
    18471847        unsigned short misc;
    1848        
     1848
    18491849        patch_ad1881(ac97);
    18501850        ac97->build_ops = &patch_ad1888_build_ops;
     
    19201920{
    19211921        unsigned short misc;
    1922        
     1922
    19231923        patch_ad1881(ac97);
    19241924        ac97->build_ops = &patch_ad1985_build_ops;
     
    19491949{
    19501950        int shared;
    1951        
     1951
    19521952        /* shared Line-In */
    19531953        shared = is_shared_linein(ac97);
     
    20412041
    20422042        /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
    2043         snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 
     2043        snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
    20442044                snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
    20452045
     
    20762076{
    20772077        int shared;
    2078        
     2078
    20792079        /* shared Line-In */
    20802080        shared = is_shared_linein(ac97);
     
    22222222{
    22232223        int shared;
    2224        
     2224
    22252225        /* shared Line-In */
    22262226        shared = is_shared_linein(ac97);
     
    23652365
    23662366        return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
    2367                                     0x01 << 1, 
     2367                                    0x01 << 1,
    23682368                                    (ucontrol->value.enumerated.item[0] & 0x01) << 1);
    23692369}
     
    23812381        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
    23822382        /* BIT 3: SPI2F */
    2383         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 
     2383        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
    23842384        /* BIT 4: SPI2SDI */
    23852385        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
     
    25692569        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
    25702570        /* BIT 3: SPI2F */
    2571         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 
     2571        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
    25722572        /* BIT 4: SPI2SDI */
    25732573        AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
     
    26612661        return 0;
    26622662}
    2663        
     2663
    26642664#define AC97_CM9780_SIDE        0x60
    26652665#define AC97_CM9780_JACK        0x62
     
    28242824        return 0;
    28252825}
     2826
     2827/*
     2828 * LM 4550 Codec
     2829 *
     2830 * We use a static resolution table since LM4550 codec cannot be
     2831 * properly autoprobed to determine the resolution via
     2832 * check_volume_resolution().
     2833 */
     2834
     2835static struct snd_ac97_res_table lm4550_restbl[] = {
     2836    { AC97_MASTER, 0x1f1f },
     2837    { AC97_HEADPHONE, 0x1f1f },
     2838    { AC97_MASTER_MONO, 0x001f },
     2839    { AC97_PC_BEEP, 0x001f },       /* LSB is ignored */
     2840    { AC97_PHONE, 0x001f },
     2841    { AC97_MIC, 0x001f },
     2842    { AC97_LINE, 0x1f1f },
     2843    { AC97_CD, 0x1f1f },
     2844    { AC97_VIDEO, 0x1f1f },
     2845    { AC97_AUX, 0x1f1f },
     2846    { AC97_PCM, 0x1f1f },
     2847    { AC97_REC_GAIN, 0x0f0f },
     2848    {0} /* terminator */
     2849};
     2850
     2851int patch_lm4550(struct snd_ac97 *ac97)
     2852{
     2853    ac97->res_table = lm4550_restbl;
     2854    return 0;
     2855}
     2856
  • GPL/trunk/alsa-kernel/pci/ac97/ac97_patch.h

    r72 r76  
    6060int patch_it2646(struct snd_ac97 * ac97);
    6161int mpatch_si3036(struct snd_ac97 * ac97);
     62int patch_lm4550(struct snd_ac97 * ac97);
  • GPL/trunk/alsa-kernel/pci/bt87x.c

    r70 r76  
    794794    /* AVerMedia Studio No. 103, 203, ...? */
    795795    BT_DEVICE(878, 0x1461, 0x0003, 48000),
     796    /* Leadtek Winfast tv 2000xp delux */
     797    BT_DEVICE(878, 0x107d, 0x6606, 32000),
    796798    {0}
    797799};
     
    804806} blacklist[] __devinitdata = {
    805807    {0x0071, 0x0101}, /* Nebula Electronics DigiTV */
     808    {0x11bd, 0x001c}, /* Pinnacle PCTV Sat */
    806809    {0x11bd, 0x0026}, /* Pinnacle PCTV SAT CI */
    807810    {0x1461, 0x0761}, /* AVermedia AverTV DVB-T */
    808811    {0x1461, 0x0771}, /* AVermedia DVB-T 771 */
    809812    {0x1822, 0x0001}, /* Twinhan VisionPlus DVB-T */
     813    {0x18ac, 0xd500}, /* DVICO FusionHDTV 5 Lite */
    810814    {0x18ac, 0xdb10}, /* DVICO FusionHDTV DVB-T Lite */
    811815    {0x270f, 0xfc00}, /* Chaintech Digitop DST-1000 DVB-S */
     816    {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */
    812817};
    813818
     
    825830        if (blacklist[i].subvendor == pci->subsystem_vendor &&
    826831            blacklist[i].subdevice == pci->subsystem_device) {
    827             snd_printdd(KERN_INFO "card %#04x:%#04x has no audio\n",
    828                         pci->subsystem_vendor, pci->subsystem_device);
     832            snd_printdd(KERN_INFO "card %#04x-%#04x:%#04x has no audio\n",
     833                        pci->device, pci->subsystem_vendor, pci->subsystem_device);
    829834            return -EBUSY;
    830835        }
    831836
    832     snd_printk(KERN_INFO "unknown card %#04x:%#04x, using default rate 32000\n",
    833                pci->subsystem_vendor, pci->subsystem_device);
     837    snd_printk(KERN_INFO "unknown card %#04x-%#04x:%#04x, using default rate 32000\n",
     838               pci->device, pci->subsystem_vendor, pci->subsystem_device);
    834839    snd_printk(KERN_DEBUG "please mail id, board name, and, "
    835840               "if it works, the correct digital_rate option to "
  • GPL/trunk/alsa-kernel/pci/ca0106/ca0106.h

    r32 r76  
    66 *  FEATURES currently supported:
    77 *    See ca0106_main.c for features.
    8  *
     8 * 
    99 *  Changelog:
    1010 *    Support interrupts per period.
     
    154154                                                 * bit 9 0 = Mute / 1 = Analog out.
    155155                                                 * bit 10 0 = Line-in / 1 = Mic-in.
    156                                                 * bit 11 0 = ? / 1 = ?
    157                                                 * bit 12 0 = 48 Khz / 1 = 96 Khz Analog out on SB Live 24bit.
     156                                                * bit 11 0 = ? / 1 = ?
     157                                                * bit 12 0 = 48 Khz / 1 = 96 Khz Analog out on SB Live 24bit.
    158158                                                 * bit 13 0 = ? / 1 = ?
    159159                                                 * bit 14 0 = Mute / 1 = Analog out
     
    173173/* CA0106 pointer-offset register set, accessed through the PTR and DATA registers                     */
    174174/********************************************************************************************************/
    175 
     175                                                                                                                           
    176176/* Initally all registers from 0x00 to 0x3f have zero contents. */
    177177#define PLAYBACK_LIST_ADDR      0x00            /* Base DMA address of a list of pointers to each period/size */
    178                                                 /* One list entry: 4 bytes for DMA address,
     178                                                /* One list entry: 4 bytes for DMA address, 
    179179                                                 * 4 bytes for period_size << 16.
    180180                                                 * One list entry is 8 bytes long.
     
    218218                                                 * Playback mixer out enable [31:28] (one bit per channel)
    219219                                                 */
    220 /* The Digital out jack is shared with the Center/LFE Analogue output.
     220/* The Digital out jack is shared with the Center/LFE Analogue output. 
    221221 * The jack has 4 poles. I will call 1 - Tip, 2 - Next to 1, 3 - Next to 2, 4 - Next to 3
    222222 * For Analogue: 1 -> Center Speaker, 2 -> Sub Woofer, 3 -> Ground, 4 -> Ground
     
    231231 */
    232232/* A standard 2 pole mono mini-jack to RCA plug can be used for SPDIF Stereo PCM output from the Front channel.
    233  * A standard 3 pole stereo mini-jack to 2 RCA plugs can be used for SPDIF AC3/DTS and Stereo PCM output utilising the Rear channel and just one of the RCA plugs.
     233 * A standard 3 pole stereo mini-jack to 2 RCA plugs can be used for SPDIF AC3/DTS and Stereo PCM output utilising the Rear channel and just one of the RCA plugs. 
    234234 */
    235235#define SPCS0                   0x41            /* SPDIF output Channel Status 0 register. For Rear. default=0x02108004, non-audio=0x02108006   */
     
    331331#define CAPTURE_SOURCE_CHANNEL3 0x000f0000      /* 3 - Mic in, Line in, TAD in, Aux in. */
    332332#define CAPTURE_SOURCE_RECORD_MAP 0x0000ffff    /* Default 0x00e4 */
    333                                                 /* Record Map [7:0] (2 bits per channel) 0=mapped to channel 0, 1=mapped to channel 1, 2=mapped to channel2, 3=mapped to channel3
     333                                                /* Record Map [7:0] (2 bits per channel) 0=mapped to channel 0, 1=mapped to channel 1, 2=mapped to channel2, 3=mapped to channel3 
    334334                                                 * Record source select for channel 0 [18:16]
    335335                                                 * Record source select for channel 1 [22:20]
     
    400400                                                /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
    401401#define UNKNOWN6b               0x6b            /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */
    402 #define UART_A_DATA             0x6c            /* Uart, used in setting sample rates, bits per sample etc. */
    403 #define UART_A_CMD              0x6d            /* Uart, used in setting sample rates, bits per sample etc. */
    404 #define UART_B_DATA             0x6e            /* Uart, Unknown. */
    405 #define UART_B_CMD              0x6f            /* Uart, Unknown. */
     402#define MIDI_UART_A_DATA                0x6c            /* Midi Uart A Data */
     403#define MIDI_UART_A_CMD         0x6d            /* Midi Uart A Command/Status */
     404#define MIDI_UART_B_DATA                0x6e            /* Midi Uart B Data (currently unused) */
     405#define MIDI_UART_B_CMD         0x6f            /* Midi Uart B Command/Status (currently unused) */
     406
     407/* unique channel identifier for midi->channel */
     408
     409#define CA0106_MIDI_CHAN_A              0x1
     410#define CA0106_MIDI_CHAN_B              0x2
     411
     412/* from mpu401 */
     413
     414#define CA0106_MIDI_INPUT_AVAIL         0x80
     415#define CA0106_MIDI_OUTPUT_READY        0x40
     416#define CA0106_MPU401_RESET             0xff
     417#define CA0106_MPU401_ENTER_UART        0x3f
     418#define CA0106_MPU401_ACK               0xfe
     419
    406420#define SAMPLE_RATE_TRACKER_STATUS 0x70         /* Readonly. Default 00108000 00108000 00500000 00500000 */
    407421                                                /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 =  1.0
     
    418432                                                 * SRC input source select [4] 0=Audio from digital mixer, 1=Audio from analog source.
    419433                                                 * Record rate [9:8] (0=48kHz, 1=Not available, 2=96kHz, 3=192Khz)
    420                                                  * Record mixer output enable [12:10]
     434                                                 * Record mixer output enable [12:10] 
    421435                                                 * I2S input rate master mode [15:14] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
    422436                                                 * I2S output rate [17:16] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
     
    431445                                                 * Record Source 0 input [29:28] (0=SPDIF in, 1=I2S in, 2=AC97 Mic, 3=AC97 PCM)
    432446                                                 * Record Source 1 input [31:30] (0=SPDIF in, 1=I2S in, 2=AC97 Mic, 3=AC97 PCM)
    433                                                  */
     447                                                 */ 
    434448                                                /* Sample rate output control register Channel=1
    435449                                                 * I2S Input 0 volume Right [7:0]
     
    453467                                                 * I2S output enable [19:16]
    454468                                                 * SPDIF output enable [27:24]
    455                                                  */
     469                                                 */ 
    456470#define UNKNOWN73               0x73            /* Unknown. Readonly. Default 0x0 */
    457471#define CHIP_VERSION            0x74            /* P17 Chip version. Channel_id 0 only. Default 00000071 */
     
    478492#define SPI                     0x7a            /* SPI: Serial Interface Register */
    479493#define I2C_A                   0x7b            /* I2C Address. 32 bit */
    480 #define I2C_D0                  0x7c            /* I2C Data Port 0. 32 bit */
    481 #define I2C_D1                  0x7d            /* I2C Data Port 1. 32 bit */
     494#define I2C_D0                  0x7c            /* I2C Data Port 0. 32 bit */
     495#define I2C_D1                  0x7d            /* I2C Data Port 1. 32 bit */
    482496//I2C values
    483 #define I2C_A_ADC_ADD_MASK      0x000000fe      //The address is a 7 bit address
    484 #define I2C_A_ADC_RW_MASK       0x00000001      //bit mask for R/W
    485 #define I2C_A_ADC_TRANS_MASK    0x00000010      //Bit mask for I2c address DAC value
    486 #define I2C_A_ADC_ABORT_MASK    0x00000020      //Bit mask for I2C transaction abort flag
    487 #define I2C_A_ADC_LAST_MASK     0x00000040      //Bit mask for Last word transaction
    488 #define I2C_A_ADC_BYTE_MASK     0x00000080      //Bit mask for Byte Mode
    489 
    490 #define I2C_A_ADC_ADD           0x00000034      //This is the Device address for ADC
    491 #define I2C_A_ADC_READ          0x00000001      //To perform a read operation
    492 #define I2C_A_ADC_START         0x00000100      //Start I2C transaction
    493 #define I2C_A_ADC_ABORT         0x00000200      //I2C transaction abort
    494 #define I2C_A_ADC_LAST          0x00000400      //I2C last transaction
    495 #define I2C_A_ADC_BYTE          0x00000800      //I2C one byte mode
    496 
    497 #define I2C_D_ADC_REG_MASK      0xfe000000      //ADC address register
    498 #define I2C_D_ADC_DAT_MASK      0x01ff0000      //ADC data register
    499 
    500 #define ADC_TIMEOUT             0x00000007      //ADC Timeout Clock Disable
    501 #define ADC_IFC_CTRL            0x0000000b      //ADC Interface Control
    502 #define ADC_MASTER              0x0000000c      //ADC Master Mode Control
    503 #define ADC_POWER               0x0000000d      //ADC PowerDown Control
    504 #define ADC_ATTEN_ADCL          0x0000000e      //ADC Attenuation ADCL
    505 #define ADC_ATTEN_ADCR          0x0000000f      //ADC Attenuation ADCR
    506 #define ADC_ALC_CTRL1           0x00000010      //ADC ALC Control 1
    507 #define ADC_ALC_CTRL2           0x00000011      //ADC ALC Control 2
    508 #define ADC_ALC_CTRL3           0x00000012      //ADC ALC Control 3
    509 #define ADC_NOISE_CTRL          0x00000013      //ADC Noise Gate Control
    510 #define ADC_LIMIT_CTRL          0x00000014      //ADC Limiter Control
    511 #define ADC_MUX                 0x00000015      //ADC Mux offset
     497#define I2C_A_ADC_ADD_MASK      0x000000fe      //The address is a 7 bit address
     498#define I2C_A_ADC_RW_MASK       0x00000001      //bit mask for R/W
     499#define I2C_A_ADC_TRANS_MASK    0x00000010      //Bit mask for I2c address DAC value
     500#define I2C_A_ADC_ABORT_MASK    0x00000020      //Bit mask for I2C transaction abort flag
     501#define I2C_A_ADC_LAST_MASK     0x00000040      //Bit mask for Last word transaction
     502#define I2C_A_ADC_BYTE_MASK     0x00000080      //Bit mask for Byte Mode
     503
     504#define I2C_A_ADC_ADD           0x00000034      //This is the Device address for ADC
     505#define I2C_A_ADC_READ          0x00000001      //To perform a read operation
     506#define I2C_A_ADC_START         0x00000100      //Start I2C transaction
     507#define I2C_A_ADC_ABORT         0x00000200      //I2C transaction abort
     508#define I2C_A_ADC_LAST          0x00000400      //I2C last transaction
     509#define I2C_A_ADC_BYTE          0x00000800      //I2C one byte mode
     510
     511#define I2C_D_ADC_REG_MASK      0xfe000000      //ADC address register
     512#define I2C_D_ADC_DAT_MASK      0x01ff0000      //ADC data register
     513
     514#define ADC_TIMEOUT             0x00000007      //ADC Timeout Clock Disable
     515#define ADC_IFC_CTRL            0x0000000b      //ADC Interface Control
     516#define ADC_MASTER              0x0000000c      //ADC Master Mode Control
     517#define ADC_POWER               0x0000000d      //ADC PowerDown Control
     518#define ADC_ATTEN_ADCL          0x0000000e      //ADC Attenuation ADCL
     519#define ADC_ATTEN_ADCR          0x0000000f      //ADC Attenuation ADCR
     520#define ADC_ALC_CTRL1           0x00000010      //ADC ALC Control 1
     521#define ADC_ALC_CTRL2           0x00000011      //ADC ALC Control 2
     522#define ADC_ALC_CTRL3           0x00000012      //ADC ALC Control 3
     523#define ADC_NOISE_CTRL          0x00000013      //ADC Noise Gate Control
     524#define ADC_LIMIT_CTRL          0x00000014      //ADC Limiter Control
     525#define ADC_MUX                 0x00000015      //ADC Mux offset
    512526
    513527#if 0
    514528/* FIXME: Not tested yet. */
    515 #define ADC_GAIN_MASK           0x000000ff      //Mask for ADC Gain
    516 #define ADC_ZERODB              0x000000cf      //Value to set ADC to 0dB
    517 #define ADC_MUTE_MASK           0x000000c0      //Mask for ADC mute
    518 #define ADC_MUTE                0x000000c0      //Value to mute ADC
    519 #define ADC_OSR                 0x00000008      //Mask for ADC oversample rate select
    520 #define ADC_TIMEOUT_DISABLE     0x00000008      //Value and mask to disable Timeout clock
    521 #define ADC_HPF_DISABLE         0x00000100      //Value and mask to disable High pass filter
    522 #define ADC_TRANWIN_MASK        0x00000070      //Mask for Length of Transient Window
     529#define ADC_GAIN_MASK           0x000000ff      //Mask for ADC Gain
     530#define ADC_ZERODB              0x000000cf      //Value to set ADC to 0dB
     531#define ADC_MUTE_MASK           0x000000c0      //Mask for ADC mute
     532#define ADC_MUTE                0x000000c0      //Value to mute ADC
     533#define ADC_OSR                 0x00000008      //Mask for ADC oversample rate select
     534#define ADC_TIMEOUT_DISABLE     0x00000008      //Value and mask to disable Timeout clock
     535#define ADC_HPF_DISABLE         0x00000100      //Value and mask to disable High pass filter
     536#define ADC_TRANWIN_MASK        0x00000070      //Mask for Length of Transient Window
    523537#endif
    524538
    525 #define ADC_MUX_MASK            0x0000000f      //Mask for ADC Mux
    526 #define ADC_MUX_MIC             0x00000002      //Value to select Mic at ADC Mux
    527 #define ADC_MUX_LINEIN          0x00000004      //Value to select LineIn at ADC Mux
    528 #define ADC_MUX_PHONE           0x00000001      //Value to select TAD at ADC Mux (Not used)
    529 #define ADC_MUX_AUX             0x00000008      //Value to select Aux at ADC Mux
     539#define ADC_MUX_MASK            0x0000000f      //Mask for ADC Mux
     540#define ADC_MUX_MIC             0x00000002      //Value to select Mic at ADC Mux
     541#define ADC_MUX_LINEIN          0x00000004      //Value to select LineIn at ADC Mux
     542#define ADC_MUX_PHONE           0x00000001      //Value to select TAD at ADC Mux (Not used)
     543#define ADC_MUX_AUX             0x00000008      //Value to select Aux at ADC Mux
    530544
    531545#define SET_CHANNEL 0  /* Testing channel outputs 0=Front, 1=Center/LFE, 2=Unknown, 3=Rear */
     
    539553#define CONTROL_UNKNOWN_CHANNEL 2
    540554
    541 typedef struct snd_ca0106_channel ca0106_channel_t;
    542 typedef struct snd_ca0106 ca0106_t;
    543 typedef struct snd_ca0106_pcm ca0106_pcm_t;
     555#include "ca_midi.h"
     556
     557struct snd_ca0106;
    544558
    545559struct snd_ca0106_channel {
    546         ca0106_t *emu;
     560        struct snd_ca0106 *emu;
    547561        int number;
    548562        int use;
    549         void (*interrupt)(ca0106_t *emu, ca0106_channel_t *channel);
    550         ca0106_pcm_t *epcm;
     563        void (*interrupt)(struct snd_ca0106 *emu, struct snd_ca0106_channel *channel);
     564        struct snd_ca0106_pcm *epcm;
    551565};
    552566
    553567struct snd_ca0106_pcm {
    554         ca0106_t *emu;
    555         snd_pcm_substream_t *substream;
     568        struct snd_ca0106 *emu;
     569        struct snd_pcm_substream *substream;
    556570        int channel_id;
    557571        unsigned short running;
    558572};
    559573
    560 typedef struct {
    561     u32 serial;
    562     char * name;
    563     int ac97;
    564     int gpio_type;
    565     int i2c_adc;
    566 } ca0106_details_t;
     574struct snd_ca0106_details {
     575        u32 serial;
     576        char * name;
     577        int ac97;
     578        int gpio_type;
     579        int i2c_adc;
     580        int spi_dac;
     581};
    567582
    568583// definition of the chip-specific record
    569584struct snd_ca0106 {
    570     snd_card_t *card;
    571     ca0106_details_t *details;
    572     struct pci_dev *pci;
    573 
    574     unsigned long port;
    575     struct resource *res_port;
    576     int irq;
    577 
    578     unsigned int revision;              /* chip revision */
    579     unsigned int serial;            /* serial number */
    580     unsigned short model;               /* subsystem id */
    581 
    582     spinlock_t emu_lock;
    583 
    584     ac97_t *ac97;
    585     snd_pcm_t *pcm;
    586 
    587     ca0106_channel_t playback_channels[4];
    588     ca0106_channel_t capture_channels[4];
    589     u32 spdif_bits[4];             /* s/pdif out setup */
    590     int spdif_enable;
    591     int capture_source;
    592     int capture_mic_line_in;
    593 
    594     struct snd_dma_buffer buffer;
     585        struct snd_card *card;
     586        struct snd_ca0106_details *details;
     587        struct pci_dev *pci;
     588
     589        unsigned long port;
     590        struct resource *res_port;
     591        int irq;
     592
     593        unsigned int revision;          /* chip revision */
     594        unsigned int serial;            /* serial number */
     595        unsigned short model;           /* subsystem id */
     596
     597        spinlock_t emu_lock;
     598
     599        struct snd_ac97 *ac97;
     600        struct snd_pcm *pcm;
     601
     602        struct snd_ca0106_channel playback_channels[4];
     603        struct snd_ca0106_channel capture_channels[4];
     604        u32 spdif_bits[4];             /* s/pdif out setup */
     605        int spdif_enable;
     606        int capture_source;
     607        int capture_mic_line_in;
     608
     609        struct snd_dma_buffer buffer;
     610
     611        struct snd_ca_midi midi;
     612        struct snd_ca_midi midi2;
    595613};
    596614
    597 int __devinit snd_ca0106_mixer(ca0106_t *emu);
    598 int __devinit snd_ca0106_proc_init(ca0106_t * emu);
    599 
    600 unsigned int snd_ca0106_ptr_read(ca0106_t * emu,
    601                                           unsigned int reg,
    602                                           unsigned int chn);
    603 
    604 void snd_ca0106_ptr_write(ca0106_t *emu,
    605                                    unsigned int reg,
    606                                    unsigned int chn,
    607                                    unsigned int data);
    608 
    609 int snd_ca0106_i2c_write(ca0106_t *emu, u32 reg, u32 value);
     615int snd_ca0106_mixer(struct snd_ca0106 *emu);
     616int snd_ca0106_proc_init(struct snd_ca0106 * emu);
     617
     618unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
     619                                 unsigned int reg,
     620                                 unsigned int chn);
     621
     622void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
     623                          unsigned int reg,
     624                          unsigned int chn,
     625                          unsigned int data);
     626
     627int snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value);
     628
     629
  • GPL/trunk/alsa-kernel/pci/ca0106/ca0106_main.c

    r32 r76  
    1919 *      unmute the MIC and turn up the MASTER Playback volume.
    2020 *      So, to prevent feedback when capturing, minimise the "Capture feedback into Playback" volume.
    21  *
     21 *   
    2222 *    The only playback controls that currently do anything are: -
    2323 *    Analog Front
     
    2727 *    SPDIF Rear
    2828 *    SPDIF Center/LFE
    29  *
     29 *   
    3030 *    For capture from Mic in or Line in.
    3131 *    Digital/Analog ( switch must be in Analog mode for CAPTURE. )
    32  *
     32 * 
    3333 *    CAPTURE feedback into PLAYBACK
    34  *
     34 * 
    3535 *  Changelog:
    3636 *    Support interrupts per period.
     
    105105 *    SPDIF Out control switches between Mic in and SPDIF out.
    106106 *    No sound out or mic input working yet.
    107  *
     107 * 
    108108 *  GENERAL INFO:
    109109 *    Model: SB0413
     
    138138#include <linux/pci.h>
    139139#include <linux/slab.h>
    140 //#include <linux/moduleparam.h>
     140#include <linux/moduleparam.h>
     141//#include <linux/dma-mapping.h>
    141142#include <sound/core.h>
    142143#include <sound/initval.h>
     
    164165#include "ca0106.h"
    165166
    166 static ca0106_details_t ca0106_chip_details[] = {
    167     /* AudigyLS[SB0310] */
    168     { /*.serial = */0x10021102,
    169     /*.name   = */"AudigyLS [SB0310]",
    170     /*.ac97   = */1,0,0 } ,
    171     /* Unknown AudigyLS that also says SB0310 on it */
    172     { /*.serial = */0x10051102,
    173     /*.name   = */"AudigyLS [SB0310b]",
    174     /*.ac97   = */1,0,0 } ,
    175     /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
    176     { /*.serial = */0x10061102,
    177     /*.name   = */"Live! 7.1 24bit [SB0410]",0,
    178     /*.gpio_type = */1,
    179     /*.i2c_adc = */1 } ,
    180     /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97.  */
    181     { /*.serial = */0x10071102,
    182     /*.name   = */"Live! 7.1 24bit [SB0413]",0,
    183     /*.gpio_type = */1,
    184     /*.i2c_adc = */1 } ,
    185     /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */
    186     { /*.serial = */0x10091462,
    187     /*.name   = */"MSI K8N Diamond MB [SB0438]",0,
    188     /*.gpio_type = */1,
    189     /*.i2c_adc = */1 } ,
    190     /* Shuttle XPC SD31P which has an onboard Creative Labs Sound Blaster Live! 24-bit EAX
    191      * high-definition 7.1 audio processor".
    192      * Added using info from andrewvegan in alsa bug #1298
    193      */
    194     { .serial = 0x30381297,
    195     .name   = "Shuttle XPC SD31P [SD31P]",
    196     .gpio_type = 1,
    197     .i2c_adc = 1 } ,
    198     { /*.serial = */0,
    199     /*.name   = */"AudigyLS [Unknown]",0,0,0 }
     167static struct snd_ca0106_details ca0106_chip_details[] = {
     168         /* AudigyLS[SB0310] */
     169         { .serial = 0x10021102,
     170           .name   = "AudigyLS [SB0310]",
     171           .ac97   = 1 } ,
     172         /* Unknown AudigyLS that also says SB0310 on it */
     173         { .serial = 0x10051102,
     174           .name   = "AudigyLS [SB0310b]",
     175           .ac97   = 1 } ,
     176         /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
     177         { .serial = 0x10061102,
     178           .name   = "Live! 7.1 24bit [SB0410]",
     179           .gpio_type = 1,
     180           .i2c_adc = 1 } ,
     181         /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97.  */
     182         { .serial = 0x10071102,
     183           .name   = "Live! 7.1 24bit [SB0413]",
     184           .gpio_type = 1,
     185           .i2c_adc = 1 } ,
     186         /* New Audigy SE. Has a different DAC. */
     187         /* SB0570:
     188          * CTRL:CA0106-DAT
     189          * ADC: WM8768GEDS
     190          * DAC: WM8775EDS
     191          */
     192         { .serial = 0x100a1102,
     193           .name   = "Audigy SE [SB0570]",
     194           .gpio_type = 1,
     195           .i2c_adc = 1,
     196           .spi_dac = 1 } ,
     197         /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */
     198         { .serial = 0x10091462,
     199           .name   = "MSI K8N Diamond MB [SB0438]",
     200           .gpio_type = 1,
     201           .i2c_adc = 1 } ,
     202         /* Shuttle XPC SD31P which has an onboard Creative Labs
     203          * Sound Blaster Live! 24-bit EAX
     204          * high-definition 7.1 audio processor".
     205          * Added using info from andrewvegan in alsa bug #1298
     206          */
     207         { .serial = 0x30381297,
     208           .name   = "Shuttle XPC SD31P [SD31P]",
     209           .gpio_type = 1,
     210           .i2c_adc = 1 } ,
     211        /* Shuttle XPC SD11G5 which has an onboard Creative Labs
     212         * Sound Blaster Live! 24-bit EAX
     213         * high-definition 7.1 audio processor".
     214         * Fixes ALSA bug#1600
     215         */
     216        { .serial = 0x30411297,
     217          .name = "Shuttle XPC SD11G5 [SD11G5]",
     218          .gpio_type = 1,
     219          .i2c_adc = 1 } ,
     220         { .serial = 0,
     221           .name   = "AudigyLS [Unknown]" }
    200222};
    201223
    202224/* hardware definition */
    203 static snd_pcm_hardware_t snd_ca0106_playback_hw = {
    204         /*.info =               */(SNDRV_PCM_INFO_MMAP |
     225static struct snd_pcm_hardware snd_ca0106_playback_hw = {
     226        .info =                 (SNDRV_PCM_INFO_MMAP |
    205227                                 SNDRV_PCM_INFO_INTERLEAVED |
    206228                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    207229                                 SNDRV_PCM_INFO_MMAP_VALID),
    208         /*.formats =            */SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
    209         /*.rates =              */SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
    210         /*.rate_min =           */48000,
    211         /*.rate_max =           */192000,
    212         /*.channels_min =       */2,  //1,
    213         /*.channels_max =       */2,  //6,
    214         /*.buffer_bytes_max =   */((65536 - 64) * 8),
    215         /*.period_bytes_min =   */64,
    216         /*.period_bytes_max =   */(65536 - 64),
    217         /*.periods_min =        */2,
    218         /*.periods_max =        */8,
    219         /*.fifo_size =          */0,
     230        .formats =              SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
     231        .rates =                (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
     232                                 SNDRV_PCM_RATE_192000),
     233        .rate_min =             48000,
     234        .rate_max =             192000,
     235        .channels_min =         2,  //1,
     236        .channels_max =         2,  //6,
     237        .buffer_bytes_max =     ((65536 - 64) * 8),
     238        .period_bytes_min =     64,
     239        .period_bytes_max =     (65536 - 64),
     240        .periods_min =          2,
     241        .periods_max =          8,
     242        .fifo_size =            0,
    220243};
    221244
    222 static snd_pcm_hardware_t snd_ca0106_capture_hw = {
    223         /*.info =               */      (SNDRV_PCM_INFO_MMAP |
     245static struct snd_pcm_hardware snd_ca0106_capture_hw = {
     246        .info =                 (SNDRV_PCM_INFO_MMAP |
    224247                                 SNDRV_PCM_INFO_INTERLEAVED |
    225248                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    226249                                 SNDRV_PCM_INFO_MMAP_VALID),
    227         /*.formats =            */SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
    228         /*.rates =              */SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
    229         /*.rate_min =           */44100,
    230         /*.rate_max =           */192000,
    231         /*.channels_min =       */2,
    232         /*.channels_max =       */2,
    233         /*.buffer_bytes_max =   */((65536 - 64) * 8),
    234         /*.period_bytes_min =   */64,
    235         /*.period_bytes_max =   */(65536 - 64),
    236         /*.periods_min =        */2,
    237         /*.periods_max =        */2,
    238         /*.fifo_size =          */0,
     250        .formats =              SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
     251        .rates =                (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
     252                                 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
     253        .rate_min =             44100,
     254        .rate_max =             192000,
     255        .channels_min =         2,
     256        .channels_max =         2,
     257        .buffer_bytes_max =     ((65536 - 64) * 8),
     258        .period_bytes_min =     64,
     259        .period_bytes_max =     (65536 - 64),
     260        .periods_min =          2,
     261        .periods_max =          2,
     262        .fifo_size =            0,
    239263};
    240264
    241 unsigned int snd_ca0106_ptr_read(ca0106_t * emu,
    242                                           unsigned int reg,
     265unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
     266                                          unsigned int reg, 
    243267                                          unsigned int chn)
    244268{
    245269        unsigned long flags;
    246270        unsigned int regptr, val;
    247 
     271 
    248272        regptr = (reg << 16) | chn;
    249273
     
    255279}
    256280
    257 void snd_ca0106_ptr_write(ca0106_t *emu,
    258                                    unsigned int reg,
    259                                    unsigned int chn,
     281void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
     282                                   unsigned int reg, 
     283                                   unsigned int chn, 
    260284                                   unsigned int data)
    261285{
     
    271295}
    272296
    273 int snd_ca0106_i2c_write(ca0106_t *emu,
    274                          u32 reg,
    275                          u32 value)
    276 {
    277     u32 tmp;
    278     int timeout=0;
    279     int status;
    280     int retry;
    281     if ((reg > 0x7f) || (value > 0x1ff))
    282     {
    283         snd_printk("i2c_write: invalid values.\n");
    284         return -EINVAL;
    285     }
    286 
    287     tmp = reg << 25 | value << 16;
    288     /* Not sure what this I2C channel controls. */
    289     /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
    290 
    291     /* This controls the I2C connected to the WM8775 ADC Codec */
    292     snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
    293 
    294     for(retry=0;retry<10;retry++)
    295     {
    296         /* Send the data to i2c */
    297         tmp = snd_ca0106_ptr_read(emu, I2C_A, 0);
    298         tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK);
    299         tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD);
    300         snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
    301 
    302         /* Wait till the transaction ends */
    303         while(1)
    304         {
    305             status = snd_ca0106_ptr_read(emu, I2C_A, 0);
    306             //snd_printk("I2C:status=0x%x\n", status);
    307             timeout++;
    308             if((status & I2C_A_ADC_START)==0)
    309                 break;
    310 
    311             if(timeout>1000)
    312                 break;
    313         }
    314         //Read back and see if the transaction is successful
    315         if((status & I2C_A_ADC_ABORT)==0)
    316             break;
    317     }
    318 
    319     if(retry==10)
    320     {
    321         snd_printk("Writing to ADC failed!\n");
    322         return -EINVAL;
    323     }
    324 
    325     return 0;
    326 }
    327 
    328 
    329 static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb)
     297int snd_ca0106_spi_write(struct snd_ca0106 * emu,
     298                                   unsigned int data)
     299{
     300        unsigned int reset, set;
     301        unsigned int reg, tmp;
     302        int n, result;
     303        reg = SPI;
     304        if (data > 0xffff) /* Only 16bit values allowed */
     305                return 1;
     306        tmp = snd_ca0106_ptr_read(emu, reg, 0);
     307        reset = (tmp & ~0x3ffff) | 0x20000; /* Set xxx20000 */
     308        set = reset | 0x10000; /* Set xxx1xxxx */
     309        snd_ca0106_ptr_write(emu, reg, 0, reset | data);
     310        tmp = snd_ca0106_ptr_read(emu, reg, 0); /* write post */
     311        snd_ca0106_ptr_write(emu, reg, 0, set | data);
     312        result = 1;
     313        /* Wait for status bit to return to 0 */
     314        for (n = 0; n < 100; n++) {
     315                udelay(10);
     316                tmp = snd_ca0106_ptr_read(emu, reg, 0);
     317                if (!(tmp & 0x10000)) {
     318                        result = 0;
     319                        break;
     320                }
     321        }
     322        if (result) /* Timed out */
     323                return 1;
     324        snd_ca0106_ptr_write(emu, reg, 0, reset | data);
     325        tmp = snd_ca0106_ptr_read(emu, reg, 0); /* Write post */
     326        return 0;
     327}
     328
     329int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
     330                                u32 reg,
     331                                u32 value)
     332{
     333        u32 tmp;
     334        int timeout = 0;
     335        int status;
     336        int retry;
     337        if ((reg > 0x7f) || (value > 0x1ff)) {
     338                snd_printk(KERN_ERR "i2c_write: invalid values.\n");
     339                return -EINVAL;
     340        }
     341
     342        tmp = reg << 25 | value << 16;
     343        /* Not sure what this I2C channel controls. */
     344        /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
     345
     346        /* This controls the I2C connected to the WM8775 ADC Codec */
     347        snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
     348
     349        for (retry = 0; retry < 10; retry++) {
     350                /* Send the data to i2c */
     351                tmp = snd_ca0106_ptr_read(emu, I2C_A, 0);
     352                tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK);
     353                tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD);
     354                snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
     355
     356                /* Wait till the transaction ends */
     357                while (1) {
     358                        status = snd_ca0106_ptr_read(emu, I2C_A, 0);
     359                        //snd_printk("I2C:status=0x%x\n", status);
     360                        timeout++;
     361                        if ((status & I2C_A_ADC_START) == 0)
     362                                break;
     363
     364                        if (timeout > 1000)
     365                                break;
     366                }
     367                //Read back and see if the transaction is successful
     368                if ((status & I2C_A_ADC_ABORT) == 0)
     369                        break;
     370        }
     371
     372        if (retry == 10) {
     373                snd_printk(KERN_ERR "Writing to ADC failed!\n");
     374                return -EINVAL;
     375        }
     376   
     377        return 0;
     378}
     379
     380
     381static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
    330382{
    331383        unsigned long flags;
    332384        unsigned int enable;
    333 
     385 
    334386        spin_lock_irqsave(&emu->emu_lock, flags);
    335387        enable = inl(emu->port + INTE) | intrenb;
     
    338390}
    339391
    340 static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime)
    341 {
    342         ca0106_pcm_t *epcm = runtime->private_data;
    343 
    344         if (epcm) {
    345                 kfree(epcm);
    346         }
     392static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
     393{
     394        unsigned long flags;
     395        unsigned int enable;
     396 
     397        spin_lock_irqsave(&emu->emu_lock, flags);
     398        enable = inl(emu->port + INTE) & ~intrenb;
     399        outl(enable, emu->port + INTE);
     400        spin_unlock_irqrestore(&emu->emu_lock, flags);
     401}
     402
     403
     404static void snd_ca0106_pcm_free_substream(struct snd_pcm_runtime *runtime)
     405{
     406        kfree(runtime->private_data);
    347407}
    348408
    349409/* open_playback callback */
    350 static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
    351 {
    352         ca0106_t *chip = snd_pcm_substream_chip(substream);
    353         ca0106_channel_t *channel = &(chip->playback_channels[channel_id]);
    354         ca0106_pcm_t *epcm;
    355         snd_pcm_runtime_t *runtime = substream->runtime;
     410static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream,
     411                                                int channel_id)
     412{
     413        struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
     414        struct snd_ca0106_channel *channel = &(chip->playback_channels[channel_id]);
     415        struct snd_ca0106_pcm *epcm;
     416        struct snd_pcm_runtime *runtime = substream->runtime;
    356417        int err;
    357418
    358         epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
     419        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    359420
    360421        if (epcm == NULL)
     
    363424        epcm->substream = substream;
    364425        epcm->channel_id=channel_id;
    365 
     426 
    366427        runtime->private_data = epcm;
    367428        runtime->private_free = snd_ca0106_pcm_free_substream;
    368 
     429 
    369430        runtime->hw = snd_ca0106_playback_hw;
    370431
     
    372433        channel->number = channel_id;
    373434
    374         channel->use=1;
     435        channel->use = 1;
    375436        //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
    376437        //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
    377         channel->epcm=epcm;
     438        channel->epcm = epcm;
    378439        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
    379440                return err;
     
    384445
    385446/* close callback */
    386 static int snd_ca0106_pcm_close_playback(snd_pcm_substream_t *substream)
    387 {
    388         ca0106_t *chip = snd_pcm_substream_chip(substream);
    389         snd_pcm_runtime_t *runtime = substream->runtime;
    390         ca0106_pcm_t *epcm = runtime->private_data;
    391         chip->playback_channels[epcm->channel_id].use=0;
    392 /* FIXME: maybe zero others */
     447static int snd_ca0106_pcm_close_playback(struct snd_pcm_substream *substream)
     448{
     449        struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
     450        struct snd_pcm_runtime *runtime = substream->runtime;
     451        struct snd_ca0106_pcm *epcm = runtime->private_data;
     452        chip->playback_channels[epcm->channel_id].use = 0;
     453        /* FIXME: maybe zero others */
    393454        return 0;
    394455}
    395456
    396 static int snd_ca0106_pcm_open_playback_front(snd_pcm_substream_t *substream)
     457static int snd_ca0106_pcm_open_playback_front(struct snd_pcm_substream *substream)
    397458{
    398459        return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
    399460}
    400461
    401 static int snd_ca0106_pcm_open_playback_center_lfe(snd_pcm_substream_t *substream)
     462static int snd_ca0106_pcm_open_playback_center_lfe(struct snd_pcm_substream *substream)
    402463{
    403464        return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL);
    404465}
    405466
    406 static int snd_ca0106_pcm_open_playback_unknown(snd_pcm_substream_t *substream)
     467static int snd_ca0106_pcm_open_playback_unknown(struct snd_pcm_substream *substream)
    407468{
    408469        return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL);
    409470}
    410471
    411 static int snd_ca0106_pcm_open_playback_rear(snd_pcm_substream_t *substream)
     472static int snd_ca0106_pcm_open_playback_rear(struct snd_pcm_substream *substream)
    412473{
    413474        return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL);
     
    415476
    416477/* open_capture callback */
    417 static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id)
    418 {
    419         ca0106_t *chip = snd_pcm_substream_chip(substream);
    420         ca0106_channel_t *channel = &(chip->capture_channels[channel_id]);
    421         ca0106_pcm_t *epcm;
    422         snd_pcm_runtime_t *runtime = substream->runtime;
     478static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substream,
     479                                               int channel_id)
     480{
     481        struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
     482        struct snd_ca0106_channel *channel = &(chip->capture_channels[channel_id]);
     483        struct snd_ca0106_pcm *epcm;
     484        struct snd_pcm_runtime *runtime = substream->runtime;
    423485        int err;
    424486
    425         epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
     487        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    426488        if (epcm == NULL) {
    427                 snd_printk("open_capture_channel: failed epcm alloc\n");
     489                snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n");
    428490                return -ENOMEM;
    429491        }
     
    431493        epcm->substream = substream;
    432494        epcm->channel_id=channel_id;
    433 
     495 
    434496        runtime->private_data = epcm;
    435497        runtime->private_free = snd_ca0106_pcm_free_substream;
    436 
     498 
    437499        runtime->hw = snd_ca0106_capture_hw;
    438500
     
    440502        channel->number = channel_id;
    441503
    442         channel->use=1;
     504        channel->use = 1;
    443505        //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
    444506        //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
    445         channel->epcm=epcm;
     507        channel->epcm = epcm;
    446508        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
    447509                return err;
     
    453515
    454516/* close callback */
    455 static int snd_ca0106_pcm_close_capture(snd_pcm_substream_t *substream)
    456 {
    457         ca0106_t *chip = snd_pcm_substream_chip(substream);
    458         snd_pcm_runtime_t *runtime = substream->runtime;
    459         ca0106_pcm_t *epcm = runtime->private_data;
    460         chip->capture_channels[epcm->channel_id].use=0;
    461 /* FIXME: maybe zero others */
     517static int snd_ca0106_pcm_close_capture(struct snd_pcm_substream *substream)
     518{
     519        struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
     520        struct snd_pcm_runtime *runtime = substream->runtime;
     521        struct snd_ca0106_pcm *epcm = runtime->private_data;
     522        chip->capture_channels[epcm->channel_id].use = 0;
     523        /* FIXME: maybe zero others */
    462524        return 0;
    463525}
    464526
    465 static int snd_ca0106_pcm_open_0_capture(snd_pcm_substream_t *substream)
     527static int snd_ca0106_pcm_open_0_capture(struct snd_pcm_substream *substream)
    466528{
    467529        return snd_ca0106_pcm_open_capture_channel(substream, 0);
    468530}
    469531
    470 static int snd_ca0106_pcm_open_1_capture(snd_pcm_substream_t *substream)
     532static int snd_ca0106_pcm_open_1_capture(struct snd_pcm_substream *substream)
    471533{
    472534        return snd_ca0106_pcm_open_capture_channel(substream, 1);
    473535}
    474536
    475 static int snd_ca0106_pcm_open_2_capture(snd_pcm_substream_t *substream)
     537static int snd_ca0106_pcm_open_2_capture(struct snd_pcm_substream *substream)
    476538{
    477539        return snd_ca0106_pcm_open_capture_channel(substream, 2);
    478540}
    479541
    480 static int snd_ca0106_pcm_open_3_capture(snd_pcm_substream_t *substream)
     542static int snd_ca0106_pcm_open_3_capture(struct snd_pcm_substream *substream)
    481543{
    482544        return snd_ca0106_pcm_open_capture_channel(substream, 3);
     
    484546
    485547/* hw_params callback */
    486 static int snd_ca0106_pcm_hw_params_playback(snd_pcm_substream_t *substream,
    487                                       snd_pcm_hw_params_t * hw_params)
     548static int snd_ca0106_pcm_hw_params_playback(struct snd_pcm_substream *substream,
     549                                      struct snd_pcm_hw_params *hw_params)
    488550{
    489551        return snd_pcm_lib_malloc_pages(substream,
     
    492554
    493555/* hw_free callback */
    494 static int snd_ca0106_pcm_hw_free_playback(snd_pcm_substream_t *substream)
     556static int snd_ca0106_pcm_hw_free_playback(struct snd_pcm_substream *substream)
    495557{
    496558        return snd_pcm_lib_free_pages(substream);
     
    498560
    499561/* hw_params callback */
    500 static int snd_ca0106_pcm_hw_params_capture(snd_pcm_substream_t *substream,
    501                                       snd_pcm_hw_params_t * hw_params)
     562static int snd_ca0106_pcm_hw_params_capture(struct snd_pcm_substream *substream,
     563                                      struct snd_pcm_hw_params *hw_params)
    502564{
    503565        return snd_pcm_lib_malloc_pages(substream,
     
    506568
    507569/* hw_free callback */
    508 static int snd_ca0106_pcm_hw_free_capture(snd_pcm_substream_t *substream)
     570static int snd_ca0106_pcm_hw_free_capture(struct snd_pcm_substream *substream)
    509571{
    510572        return snd_pcm_lib_free_pages(substream);
     
    512574
    513575/* prepare playback callback */
    514 static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t *substream)
    515 {
    516         ca0106_t *emu = snd_pcm_substream_chip(substream);
    517         snd_pcm_runtime_t *runtime = substream->runtime;
    518         ca0106_pcm_t *epcm = runtime->private_data;
     576static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
     577{
     578        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     579        struct snd_pcm_runtime *runtime = substream->runtime;
     580        struct snd_ca0106_pcm *epcm = runtime->private_data;
    519581        int channel = epcm->channel_id;
    520582        u32 *table_base = (u32 *)(emu->buffer.area+(8*16*channel));
     
    531593        u32 reg71;
    532594        int i;
    533 
     595       
    534596        //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
    535597        //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
     
    541603        case 44100:
    542604                reg40_set = 0x10000 << (channel<<1);
    543                 reg71_set = 0x01010000;
     605                reg71_set = 0x01010000; 
    544606                break;
    545607        case 48000:
    546608                reg40_set = 0;
    547                 reg71_set = 0;
     609                reg71_set = 0; 
    548610                break;
    549611        case 96000:
    550612                reg40_set = 0x20000 << (channel<<1);
    551                 reg71_set = 0x02020000;
     613                reg71_set = 0x02020000; 
    552614                break;
    553615        case 192000:
    554616                reg40_set = 0x30000 << (channel<<1);
    555                 reg71_set = 0x03030000;
     617                reg71_set = 0x03030000; 
    556618                break;
    557619        default:
    558620                reg40_set = 0;
    559                 reg71_set = 0;
     621                reg71_set = 0; 
    560622                break;
    561623        }
     
    585647        /* FIXME: Check emu->buffer.size before actually writing to it. */
    586648        for(i=0; i < runtime->periods; i++) {
    587                 table_base[i*2]=runtime->dma_addr+(i*period_size_bytes);
    588                 table_base[(i*2)+1]=period_size_bytes<<16;
    589         }
    590 
     649                table_base[i*2] = runtime->dma_addr + (i * period_size_bytes);
     650                table_base[i*2+1] = period_size_bytes << 16;
     651        }
     652 
    591653        snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel));
    592654        snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
    593655        snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0);
    594656        snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
    595         snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
    596         /* FIXME  test what 0 bytes does. */
    597         snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes
     657        snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
     658        /* FIXME  test what 0 bytes does. */
     659        snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes
    598660        snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0);
    599661        snd_ca0106_ptr_write(emu, 0x07, channel, 0x0);
     
    613675
    614676/* prepare capture callback */
    615 static int snd_ca0106_pcm_prepare_capture(snd_pcm_substream_t *substream)
    616 {
    617         ca0106_t *emu = snd_pcm_substream_chip(substream);
    618         snd_pcm_runtime_t *runtime = substream->runtime;
    619         ca0106_pcm_t *epcm = runtime->private_data;
    620         int channel = epcm->channel_id;
    621         u32 hcfg_mask = HCFG_CAPTURE_S32_LE;
    622         u32 hcfg_set = 0x00000000;
    623         u32 hcfg;
    624         u32 over_sampling=0x2;
    625         u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */
    626         u32 reg71_set = 0;
    627         u32 reg71;
    628 
     677static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
     678{
     679        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     680        struct snd_pcm_runtime *runtime = substream->runtime;
     681        struct snd_ca0106_pcm *epcm = runtime->private_data;
     682        int channel = epcm->channel_id;
     683        u32 hcfg_mask = HCFG_CAPTURE_S32_LE;
     684        u32 hcfg_set = 0x00000000;
     685        u32 hcfg;
     686        u32 over_sampling=0x2;
     687        u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */
     688        u32 reg71_set = 0;
     689        u32 reg71;
     690       
    629691        //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
    630692        //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
    631         //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
    632         /* reg71 controls ADC rate. */
    633         switch (runtime->rate) {
    634         case 44100:
    635             reg71_set = 0x00004000;
    636             break;
     693        //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
     694        /* reg71 controls ADC rate. */
     695        switch (runtime->rate) {
     696        case 44100:
     697                reg71_set = 0x00004000;
     698                break;
    637699        case 48000:
    638             reg71_set = 0;
    639             break;
    640         case 96000:
    641             reg71_set = 0x00008000;
    642             over_sampling=0xa;
    643             break;
    644         case 192000:
    645             reg71_set = 0x0000c000;
    646             over_sampling=0xa;
    647             break;
    648         default:
    649             reg71_set = 0;
    650             break;
    651         }
    652         /* Format is a global setting */
    653         /* FIXME: Only let the first channel accessed set this. */
    654         switch (runtime->format) {
    655         case SNDRV_PCM_FORMAT_S16_LE:
    656             hcfg_set = 0;
    657             break;
    658         case SNDRV_PCM_FORMAT_S32_LE:
    659             hcfg_set = HCFG_CAPTURE_S32_LE;
    660             break;
    661         default:
    662             hcfg_set = 0;
    663             break;
    664         }
    665         hcfg = inl(emu->port + HCFG) ;
    666         hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
    667         outl(hcfg, emu->port + HCFG);
    668         reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
    669         reg71 = (reg71 & ~reg71_mask) | reg71_set;
    670         snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
     700                reg71_set = 0;
     701                break;
     702        case 96000:
     703                reg71_set = 0x00008000;
     704                over_sampling=0xa;
     705                break;
     706        case 192000:
     707                reg71_set = 0x0000c000;
     708                over_sampling=0xa;
     709                break;
     710        default:
     711                reg71_set = 0;
     712                break;
     713        }
     714        /* Format is a global setting */
     715        /* FIXME: Only let the first channel accessed set this. */
     716        switch (runtime->format) {
     717        case SNDRV_PCM_FORMAT_S16_LE:
     718                hcfg_set = 0;
     719                break;
     720        case SNDRV_PCM_FORMAT_S32_LE:
     721                hcfg_set = HCFG_CAPTURE_S32_LE;
     722                break;
     723        default:
     724                hcfg_set = 0;
     725                break;
     726        }
     727        hcfg = inl(emu->port + HCFG) ;
     728        hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
     729        outl(hcfg, emu->port + HCFG);
     730        reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
     731        reg71 = (reg71 & ~reg71_mask) | reg71_set;
     732        snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
    671733        if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
    672             snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */
    673         }
     734                snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */
     735        }
    674736
    675737
     
    684746
    685747/* trigger_playback callback */
    686 static int snd_ca0106_pcm_trigger_playback(snd_pcm_substream_t *substream,
     748static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
    687749                                    int cmd)
    688750{
    689         ca0106_t *emu = snd_pcm_substream_chip(substream);
    690         snd_pcm_runtime_t *runtime;
    691         ca0106_pcm_t *epcm;
     751        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     752        struct snd_pcm_runtime *runtime;
     753        struct snd_ca0106_pcm *epcm;
    692754        int channel;
    693755        int result = 0;
    694756        struct list_head *pos;
    695         snd_pcm_substream_t *s;
     757        struct snd_pcm_substream *s;
    696758        u32 basic = 0;
    697759        u32 extended = 0;
     
    737799
    738800/* trigger_capture callback */
    739 static int snd_ca0106_pcm_trigger_capture(snd_pcm_substream_t *substream,
     801static int snd_ca0106_pcm_trigger_capture(struct snd_pcm_substream *substream,
    740802                                    int cmd)
    741803{
    742         ca0106_t *emu = snd_pcm_substream_chip(substream);
    743         snd_pcm_runtime_t *runtime = substream->runtime;
    744         ca0106_pcm_t *epcm = runtime->private_data;
     804        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     805        struct snd_pcm_runtime *runtime = substream->runtime;
     806        struct snd_ca0106_pcm *epcm = runtime->private_data;
    745807        int channel = epcm->channel_id;
    746808        int result = 0;
     
    766828/* pointer_playback callback */
    767829static snd_pcm_uframes_t
    768 snd_ca0106_pcm_pointer_playback(snd_pcm_substream_t *substream)
    769 {
    770         ca0106_t *emu = snd_pcm_substream_chip(substream);
    771         snd_pcm_runtime_t *runtime = substream->runtime;
    772         ca0106_pcm_t *epcm = runtime->private_data;
     830snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
     831{
     832        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     833        struct snd_pcm_runtime *runtime = substream->runtime;
     834        struct snd_ca0106_pcm *epcm = runtime->private_data;
    773835        snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
    774836        int channel = epcm->channel_id;
     
    793855/* pointer_capture callback */
    794856static snd_pcm_uframes_t
    795 snd_ca0106_pcm_pointer_capture(snd_pcm_substream_t *substream)
    796 {
    797         ca0106_t *emu = snd_pcm_substream_chip(substream);
    798         snd_pcm_runtime_t *runtime = substream->runtime;
    799         ca0106_pcm_t *epcm = runtime->private_data;
     857snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
     858{
     859        struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
     860        struct snd_pcm_runtime *runtime = substream->runtime;
     861        struct snd_ca0106_pcm *epcm = runtime->private_data;
    800862        snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
    801863        int channel = channel=epcm->channel_id;
     
    815877
    816878/* operators */
    817 static snd_pcm_ops_t snd_ca0106_playback_front_ops = {
    818         /*.open =        */snd_ca0106_pcm_open_playback_front,
    819         /*.close =       */snd_ca0106_pcm_close_playback,
    820         /*.ioctl =       */snd_pcm_lib_ioctl,
    821         /*.hw_params =   */snd_ca0106_pcm_hw_params_playback,
    822         /*.hw_free =     */snd_ca0106_pcm_hw_free_playback,
    823         /*.prepare =     */snd_ca0106_pcm_prepare_playback,
    824         /*.trigger =     */snd_ca0106_pcm_trigger_playback,
    825         /*.pointer =     */snd_ca0106_pcm_pointer_playback,
    826         0,0,0,0
     879static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
     880        .open =        snd_ca0106_pcm_open_playback_front,
     881        .close =       snd_ca0106_pcm_close_playback,
     882        .ioctl =       snd_pcm_lib_ioctl,
     883        .hw_params =   snd_ca0106_pcm_hw_params_playback,
     884        .hw_free =     snd_ca0106_pcm_hw_free_playback,
     885        .prepare =     snd_ca0106_pcm_prepare_playback,
     886        .trigger =     snd_ca0106_pcm_trigger_playback,
     887        .pointer =     snd_ca0106_pcm_pointer_playback,
    827888};
    828889
    829 static snd_pcm_ops_t snd_ca0106_capture_0_ops = {
    830         /*.open =        */snd_ca0106_pcm_open_0_capture,
    831         /*.close =       */snd_ca0106_pcm_close_capture,
    832         /*.ioctl =       */snd_pcm_lib_ioctl,
    833         /*.hw_params =   */snd_ca0106_pcm_hw_params_capture,
    834         /*.hw_free =     */snd_ca0106_pcm_hw_free_capture,
    835         /*.prepare =     */snd_ca0106_pcm_prepare_capture,
    836         /*.trigger =     */snd_ca0106_pcm_trigger_capture,
    837         /*.pointer =     */snd_ca0106_pcm_pointer_capture,
    838         0,0,0,0
     890static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
     891        .open =        snd_ca0106_pcm_open_0_capture,
     892        .close =       snd_ca0106_pcm_close_capture,
     893        .ioctl =       snd_pcm_lib_ioctl,
     894        .hw_params =   snd_ca0106_pcm_hw_params_capture,
     895        .hw_free =     snd_ca0106_pcm_hw_free_capture,
     896        .prepare =     snd_ca0106_pcm_prepare_capture,
     897        .trigger =     snd_ca0106_pcm_trigger_capture,
     898        .pointer =     snd_ca0106_pcm_pointer_capture,
    839899};
    840900
    841 static snd_pcm_ops_t snd_ca0106_capture_1_ops = {
    842         /*.open =        */snd_ca0106_pcm_open_1_capture,
    843         /*.close =       */snd_ca0106_pcm_close_capture,
    844         /*.ioctl =       */snd_pcm_lib_ioctl,
    845         /*.hw_params =   */snd_ca0106_pcm_hw_params_capture,
    846         /*.hw_free =     */snd_ca0106_pcm_hw_free_capture,
    847         /*.prepare =     */snd_ca0106_pcm_prepare_capture,
    848         /*.trigger =     */snd_ca0106_pcm_trigger_capture,
    849         /*.pointer =     */snd_ca0106_pcm_pointer_capture,
    850         0,0,0,0
     901static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
     902        .open =        snd_ca0106_pcm_open_1_capture,
     903        .close =       snd_ca0106_pcm_close_capture,
     904        .ioctl =       snd_pcm_lib_ioctl,
     905        .hw_params =   snd_ca0106_pcm_hw_params_capture,
     906        .hw_free =     snd_ca0106_pcm_hw_free_capture,
     907        .prepare =     snd_ca0106_pcm_prepare_capture,
     908        .trigger =     snd_ca0106_pcm_trigger_capture,
     909        .pointer =     snd_ca0106_pcm_pointer_capture,
    851910};
    852911
    853 static snd_pcm_ops_t snd_ca0106_capture_2_ops = {
    854         /*.open =        */snd_ca0106_pcm_open_2_capture,
    855         /*.close =       */snd_ca0106_pcm_close_capture,
    856         /*.ioctl =       */snd_pcm_lib_ioctl,
    857         /*.hw_params =   */snd_ca0106_pcm_hw_params_capture,
    858         /*.hw_free =     */snd_ca0106_pcm_hw_free_capture,
    859         /*.prepare =     */snd_ca0106_pcm_prepare_capture,
    860         /*.trigger =     */snd_ca0106_pcm_trigger_capture,
    861         /*.pointer =     */snd_ca0106_pcm_pointer_capture,
    862         0,0,0,0
     912static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
     913        .open =        snd_ca0106_pcm_open_2_capture,
     914        .close =       snd_ca0106_pcm_close_capture,
     915        .ioctl =       snd_pcm_lib_ioctl,
     916        .hw_params =   snd_ca0106_pcm_hw_params_capture,
     917        .hw_free =     snd_ca0106_pcm_hw_free_capture,
     918        .prepare =     snd_ca0106_pcm_prepare_capture,
     919        .trigger =     snd_ca0106_pcm_trigger_capture,
     920        .pointer =     snd_ca0106_pcm_pointer_capture,
    863921};
    864922
    865 static snd_pcm_ops_t snd_ca0106_capture_3_ops = {
    866         /*.open =        */snd_ca0106_pcm_open_3_capture,
    867         /*.close =       */snd_ca0106_pcm_close_capture,
    868         /*.ioctl =       */snd_pcm_lib_ioctl,
    869         /*.hw_params =   */snd_ca0106_pcm_hw_params_capture,
    870         /*.hw_free =     */snd_ca0106_pcm_hw_free_capture,
    871         /*.prepare =     */snd_ca0106_pcm_prepare_capture,
    872         /*.trigger =     */snd_ca0106_pcm_trigger_capture,
    873         /*.pointer =     */snd_ca0106_pcm_pointer_capture,
    874         0,0,0,0
     923static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
     924        .open =        snd_ca0106_pcm_open_3_capture,
     925        .close =       snd_ca0106_pcm_close_capture,
     926        .ioctl =       snd_pcm_lib_ioctl,
     927        .hw_params =   snd_ca0106_pcm_hw_params_capture,
     928        .hw_free =     snd_ca0106_pcm_hw_free_capture,
     929        .prepare =     snd_ca0106_pcm_prepare_capture,
     930        .trigger =     snd_ca0106_pcm_trigger_capture,
     931        .pointer =     snd_ca0106_pcm_pointer_capture,
    875932};
    876933
    877 static snd_pcm_ops_t snd_ca0106_playback_center_lfe_ops = {
    878         /*.open =         */snd_ca0106_pcm_open_playback_center_lfe,
    879         /*.close =        */snd_ca0106_pcm_close_playback,
    880         /*.ioctl =        */snd_pcm_lib_ioctl,
    881         /*.hw_params =    */snd_ca0106_pcm_hw_params_playback,
    882         /*.hw_free =      */snd_ca0106_pcm_hw_free_playback,
    883         /*.prepare =      */snd_ca0106_pcm_prepare_playback,
    884         /*.trigger =      */snd_ca0106_pcm_trigger_playback,
    885         /*.pointer =      */snd_ca0106_pcm_pointer_playback,
    886         0,0,0,0
     934static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
     935        .open =         snd_ca0106_pcm_open_playback_center_lfe,
     936        .close =        snd_ca0106_pcm_close_playback,
     937        .ioctl =        snd_pcm_lib_ioctl,
     938        .hw_params =    snd_ca0106_pcm_hw_params_playback,
     939        .hw_free =      snd_ca0106_pcm_hw_free_playback,
     940        .prepare =      snd_ca0106_pcm_prepare_playback,     
     941        .trigger =      snd_ca0106_pcm_trigger_playback, 
     942        .pointer =      snd_ca0106_pcm_pointer_playback,
    887943};
    888944
    889 static snd_pcm_ops_t snd_ca0106_playback_unknown_ops = {
    890         /*.open =         */snd_ca0106_pcm_open_playback_unknown,
    891         /*.close =        */snd_ca0106_pcm_close_playback,
    892         /*.ioctl =        */snd_pcm_lib_ioctl,
    893         /*.hw_params =    */snd_ca0106_pcm_hw_params_playback,
    894         /*.hw_free =      */snd_ca0106_pcm_hw_free_playback,
    895         /*.prepare =      */snd_ca0106_pcm_prepare_playback,
    896         /*.trigger =      */snd_ca0106_pcm_trigger_playback,
    897         /*.pointer =      */snd_ca0106_pcm_pointer_playback,
    898         0,0,0,0
     945static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
     946        .open =         snd_ca0106_pcm_open_playback_unknown,
     947        .close =        snd_ca0106_pcm_close_playback,
     948        .ioctl =        snd_pcm_lib_ioctl,
     949        .hw_params =    snd_ca0106_pcm_hw_params_playback,
     950        .hw_free =      snd_ca0106_pcm_hw_free_playback,
     951        .prepare =      snd_ca0106_pcm_prepare_playback,     
     952        .trigger =      snd_ca0106_pcm_trigger_playback, 
     953        .pointer =      snd_ca0106_pcm_pointer_playback,
    899954};
    900955
    901 static snd_pcm_ops_t snd_ca0106_playback_rear_ops = {
    902         /*.open =         */snd_ca0106_pcm_open_playback_rear,
    903         /*.close =        */snd_ca0106_pcm_close_playback,
    904         /*.ioctl =        */snd_pcm_lib_ioctl,
    905         /*.hw_params =    */snd_ca0106_pcm_hw_params_playback,
    906         /*.hw_free =      */snd_ca0106_pcm_hw_free_playback,
    907         /*.prepare =      */snd_ca0106_pcm_prepare_playback,
    908         /*.trigger =      */snd_ca0106_pcm_trigger_playback,
    909         /*.pointer =      */snd_ca0106_pcm_pointer_playback,
    910         0,0,0,0
     956static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
     957        .open =         snd_ca0106_pcm_open_playback_rear,
     958        .close =        snd_ca0106_pcm_close_playback,
     959        .ioctl =        snd_pcm_lib_ioctl,
     960        .hw_params =    snd_ca0106_pcm_hw_params_playback,
     961                .hw_free =      snd_ca0106_pcm_hw_free_playback,
     962        .prepare =      snd_ca0106_pcm_prepare_playback,     
     963        .trigger =      snd_ca0106_pcm_trigger_playback, 
     964        .pointer =      snd_ca0106_pcm_pointer_playback,
    911965};
    912966
    913967
    914 static unsigned short snd_ca0106_ac97_read(ac97_t *ac97,
     968static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97,
    915969                                             unsigned short reg)
    916970{
    917         ca0106_t *emu = ac97->private_data;
     971        struct snd_ca0106 *emu = ac97->private_data;
    918972        unsigned long flags;
    919973        unsigned short val;
     
    926980}
    927981
    928 static void snd_ca0106_ac97_write(ac97_t *ac97,
     982static void snd_ca0106_ac97_write(struct snd_ac97 *ac97,
    929983                                    unsigned short reg, unsigned short val)
    930984{
    931         ca0106_t *emu = ac97->private_data;
     985        struct snd_ca0106 *emu = ac97->private_data;
    932986        unsigned long flags;
    933 
     987 
    934988        spin_lock_irqsave(&emu->emu_lock, flags);
    935989        outb(reg, emu->port + AC97ADDRESS);
     
    938992}
    939993
    940 static int snd_ca0106_ac97(ca0106_t *chip)
    941 {
    942         ac97_bus_t *pbus;
    943         ac97_template_t ac97;
     994static int snd_ca0106_ac97(struct snd_ca0106 *chip)
     995{
     996        struct snd_ac97_bus *pbus;
     997        struct snd_ac97_template ac97;
    944998        int err;
    945         static ac97_bus_ops_t ops = {
    946             0,
    947               /*  .write = */snd_ca0106_ac97_write,
    948               /*  .read = */snd_ca0106_ac97_read,
    949               0,0
     999        static struct snd_ac97_bus_ops ops = {
     1000                .write = snd_ca0106_ac97_write,
     1001                .read = snd_ca0106_ac97_read,
    9501002        };
    951 
     1003 
    9521004        if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
    953             return err;
    954         pbus->no_vra = 1; /* we don't need VRA */
     1005                return err;
     1006        pbus->no_vra = 1; /* we don't need VRA */
     1007
    9551008        memset(&ac97, 0, sizeof(ac97));
    956         ac97.private_data = chip;
    957         ac97.scaps = AC97_SCAP_NO_SPDIF;
     1009        ac97.private_data = chip;
     1010        ac97.scaps = AC97_SCAP_NO_SPDIF;
    9581011        return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
    9591012}
    9601013
    961 static int snd_ca0106_free(ca0106_t *chip)
     1014static int snd_ca0106_free(struct snd_ca0106 *chip)
    9621015{
    9631016        if (chip->res_port != NULL) {    /* avoid access to already used hardware */
     
    9821035
    9831036        // release the i/o port
    984         if (chip->res_port) {
    985                 release_resource(chip->res_port);
    986                 kfree_nocheck(chip->res_port);
    987         }
     1037        release_and_free_resource(chip->res_port);
     1038
    9881039        // release the irq
    9891040        if (chip->irq >= 0)
     
    9941045}
    9951046
    996 static int snd_ca0106_dev_free(snd_device_t *device)
    997 {
    998         ca0106_t *chip = device->device_data;
     1047static int snd_ca0106_dev_free(struct snd_device *device)
     1048{
     1049        struct snd_ca0106 *chip = device->device_data;
    9991050        return snd_ca0106_free(chip);
    10001051}
     
    10051056        unsigned int status;
    10061057
    1007         ca0106_t *chip = dev_id;
     1058        struct snd_ca0106 *chip = dev_id;
    10081059        int i;
    10091060        int mask;
    10101061        unsigned int stat76;
    1011         ca0106_channel_t *pchannel;
    1012 
    1013         spin_lock(&chip->emu_lock);
     1062        struct snd_ca0106_channel *pchannel;
    10141063
    10151064        status = inl(chip->port + IPR);
    1016 
    1017         // call updater, unlock before it
    1018         spin_unlock(&chip->emu_lock);
    1019 
    10201065        if (! status)
    10211066                return IRQ_NONE;
     
    10271072        for(i = 0; i < 4; i++) {
    10281073                pchannel = &(chip->playback_channels[i]);
    1029                 if(stat76 & mask) {
     1074                if (stat76 & mask) {
    10301075/* FIXME: Select the correct substream for period elapsed */
    10311076                        if(pchannel->use) {
    1032                           snd_pcm_period_elapsed(pchannel->epcm->substream);
    1033                         //printk(KERN_INFO "interrupt [%d] used\n", i);
     1077                                snd_pcm_period_elapsed(pchannel->epcm->substream);
     1078                                //printk(KERN_INFO "interrupt [%d] used\n", i);
    10341079                        }
    10351080                }
     
    10411086        for(i = 0; i < 4; i++) {
    10421087                pchannel = &(chip->capture_channels[i]);
    1043                 if(stat76 & mask) {
     1088                if (stat76 & mask) {
    10441089/* FIXME: Select the correct substream for period elapsed */
    10451090                        if(pchannel->use) {
    1046                           snd_pcm_period_elapsed(pchannel->epcm->substream);
    1047                         //printk(KERN_INFO "interrupt [%d] used\n", i);
     1091                                snd_pcm_period_elapsed(pchannel->epcm->substream);
     1092                                //printk(KERN_INFO "interrupt [%d] used\n", i);
    10481093                        }
    10491094                }
     
    10541099
    10551100        snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
    1056         spin_lock(&chip->emu_lock);
     1101
     1102        if (chip->midi.dev_id &&
     1103            (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
     1104                if (chip->midi.interrupt)
     1105                        chip->midi.interrupt(&chip->midi, status);
     1106                else
     1107                        chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
     1108        }
     1109
    10571110        // acknowledge the interrupt if necessary
    10581111        outl(status, chip->port+IPR);
    10591112
    1060         spin_unlock(&chip->emu_lock);
    1061 
    1062         eoi_irq(irq);
    1063 
    10641113        return IRQ_HANDLED;
    10651114}
    10661115
    1067 static void snd_ca0106_pcm_free(snd_pcm_t *pcm)
    1068 {
    1069         ca0106_t *emu = pcm->private_data;
    1070         emu->pcm = NULL;
    1071         snd_pcm_lib_preallocate_free_for_all(pcm);
    1072 }
    1073 
    1074 static int __devinit snd_ca0106_pcm(ca0106_t *emu, int device, snd_pcm_t **rpcm)
    1075 {
    1076         snd_pcm_t *pcm;
    1077         snd_pcm_substream_t *substream;
     1116static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm)
     1117{
     1118        struct snd_pcm *pcm;
     1119        struct snd_pcm_substream *substream;
    10781120        int err;
    1079 
     1121 
    10801122        if (rpcm)
    10811123                *rpcm = NULL;
    10821124        if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
    10831125                return err;
    1084 
     1126 
    10851127        pcm->private_data = emu;
    1086         pcm->private_free = snd_ca0106_pcm_free;
    10871128
    10881129        switch (device) {
     
    11101151        emu->pcm = pcm;
    11111152
    1112         for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
    1113             substream;
     1153        for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; 
     1154            substream; 
    11141155            substream = substream->next) {
    1115                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    1116                                                          SNDRV_DMA_TYPE_DEV,
    1117                                                          snd_dma_pci_data(emu->pci),
     1156                if ((err = snd_pcm_lib_preallocate_pages(substream, 
     1157                                                         SNDRV_DMA_TYPE_DEV, 
     1158                                                         snd_dma_pci_data(emu->pci), 
    11181159                                                         64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
    11191160                        return err;
    11201161        }
    11211162
    1122         for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
    1123               substream;
     1163        for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; 
     1164              substream; 
    11241165              substream = substream->next) {
    1125                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    1126                                                    SNDRV_DMA_TYPE_DEV,
    1127                                                    snd_dma_pci_data(emu->pci),
     1166                if ((err = snd_pcm_lib_preallocate_pages(substream, 
     1167                                                   SNDRV_DMA_TYPE_DEV, 
     1168                                                   snd_dma_pci_data(emu->pci), 
    11281169                                                   64*1024, 64*1024)) < 0)
    11291170                        return err;
    11301171        }
    1131 
     1172 
    11321173        if (rpcm)
    11331174                *rpcm = pcm;
    1134 
     1175 
    11351176        return 0;
    11361177}
    11371178
    1138 static int __devinit snd_ca0106_create(snd_card_t *card,
     1179static unsigned int spi_dac_init[] = {
     1180        0x00ff,
     1181        0x02ff,
     1182        0x0400,
     1183        0x0520,
     1184        0x0600,
     1185        0x08ff,
     1186        0x0aff,
     1187        0x0cff,
     1188        0x0eff,
     1189        0x10ff,
     1190        0x1200,
     1191        0x1400,
     1192        0x1480,
     1193        0x1800,
     1194        0x1aff,
     1195        0x1cff,
     1196        0x1e00,
     1197        0x0530,
     1198        0x0602,
     1199        0x0622,
     1200        0x1400,
     1201};
     1202
     1203static int __devinit snd_ca0106_create(struct snd_card *card,
    11391204                                         struct pci_dev *pci,
    1140                                          ca0106_t **rchip)
    1141 {
    1142     ca0106_t *chip;
    1143     ca0106_details_t *c;
     1205                                         struct snd_ca0106 **rchip)
     1206{
     1207        struct snd_ca0106 *chip;
     1208        struct snd_ca0106_details *c;
    11441209        int err;
    11451210        int ch;
    1146         static snd_device_ops_t ops = {
    1147                 /*.dev_free = */snd_ca0106_dev_free, 0,0,0
     1211        static struct snd_device_ops ops = {
     1212                .dev_free = snd_ca0106_dev_free,
    11481213        };
    1149 
     1214 
    11501215        *rchip = NULL;
    1151 
     1216 
    11521217        if ((err = pci_enable_device(pci)) < 0)
    1153             return err;
    1154         pci_set_dma_mask(pci, 0xffffffffUL);
    1155         pci_set_consistent_dma_mask(pci, 0xffffffffUL);
    1156 
    1157         chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
     1218                return err;
     1219        pci_set_dma_mask(pci, 0xFFFFFFFF);
     1220 
     1221        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    11581222        if (chip == NULL) {
    11591223                pci_disable_device(pci);
    11601224                return -ENOMEM;
    11611225        }
    1162 
     1226 
    11631227        chip->card = card;
    11641228        chip->pci = pci;
     
    11661230
    11671231        spin_lock_init(&chip->emu_lock);
    1168 
     1232 
    11691233        chip->port = pci_resource_start(pci, 0);
    11701234        if ((chip->res_port = request_region(chip->port, 0x20,
    1171                                              "snd_ca0106")) == NULL) {
     1235                                             "snd_ca0106")) == NULL) { 
    11721236                snd_ca0106_free(chip);
    11731237                printk(KERN_ERR "cannot allocate the port\n");
     
    11831247        }
    11841248        chip->irq = pci->irq;
    1185 
    1186         /* This stores the periods table. */
     1249 
     1250        /* This stores the periods table. */ 
    11871251        if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
    11881252                snd_ca0106_free(chip);
     
    11991263               chip->revision, chip->serial);
    12001264#endif
    1201         strcpy(card->driver, "CA0106");
    1202         strcpy(card->shortname, "CA0106");
    1203 
    1204         for (c=ca0106_chip_details; c->serial; c++) {
    1205             if (c->serial == chip->serial) break;
    1206         }
    1207         chip->details = c;
    1208         sprintf(card->longname, "%s at 0x%lx irq %i",
    1209                 c->name, chip->port, chip->irq);
     1265        strcpy(card->driver, "CA0106");
     1266        strcpy(card->shortname, "CA0106");
     1267
     1268        for (c = ca0106_chip_details; c->serial; c++) {
     1269                if (c->serial == chip->serial)
     1270                        break;
     1271        }
     1272        chip->details = c;
     1273        sprintf(card->longname, "%s at 0x%lx irq %i",
     1274                c->name, chip->port, chip->irq);
    12101275
    12111276        outl(0, chip->port + INTE);
     
    12661331        //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */
    12671332        /* Analog or Digital output */
    1268         snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
    1269         snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
     1333        snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
     1334        snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
    12701335        chip->spdif_enable = 0; /* Set digital SPDIF output off */
    12711336        chip->capture_source = 3; /* Set CAPTURE_SOURCE */
     
    12951360                /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
    12961361                outl(0x0, chip->port+GPIO);
    1297                 //outl(0x00f0e000, chip->port+GPIO); /* Analog */
    1298                 outl(0x005f5301, chip->port+GPIO); /* Analog */
     1362                //outl(0x00f0e000, chip->port+GPIO); /* Analog */
     1363                outl(0x005f5301, chip->port+GPIO); /* Analog */
    12991364        } else {
    13001365                outl(0x0, chip->port+GPIO);
     
    13101375
    13111376        if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
    1312             snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */
    1313         }
     1377                snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */
     1378        }
     1379        if (chip->details->spi_dac == 1) { /* The SB0570 use SPI to control DAC. */
     1380                int size, n;
     1381
     1382                size = ARRAY_SIZE(spi_dac_init);
     1383                for (n=0; n < size; n++)
     1384                        snd_ca0106_spi_write(chip, spi_dac_init[n]);
     1385        }
    13141386
    13151387        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
     
    13221394}
    13231395
     1396
     1397static void ca0106_midi_interrupt_enable(struct snd_ca_midi *midi, int intr)
     1398{
     1399        snd_ca0106_intr_enable((struct snd_ca0106 *)(midi->dev_id), intr);
     1400}
     1401
     1402static void ca0106_midi_interrupt_disable(struct snd_ca_midi *midi, int intr)
     1403{
     1404        snd_ca0106_intr_disable((struct snd_ca0106 *)(midi->dev_id), intr);
     1405}
     1406
     1407static unsigned char ca0106_midi_read(struct snd_ca_midi *midi, int idx)
     1408{
     1409        return (unsigned char)snd_ca0106_ptr_read((struct snd_ca0106 *)(midi->dev_id),
     1410                                                  midi->port + idx, 0);
     1411}
     1412
     1413static void ca0106_midi_write(struct snd_ca_midi *midi, int data, int idx)
     1414{
     1415        snd_ca0106_ptr_write((struct snd_ca0106 *)(midi->dev_id), midi->port + idx, 0, data);
     1416}
     1417
     1418static struct snd_card *ca0106_dev_id_card(void *dev_id)
     1419{
     1420        return ((struct snd_ca0106 *)dev_id)->card;
     1421}
     1422
     1423static int ca0106_dev_id_port(void *dev_id)
     1424{
     1425        return ((struct snd_ca0106 *)dev_id)->port;
     1426}
     1427
     1428static int __devinit snd_ca0106_midi(struct snd_ca0106 *chip, unsigned int channel)
     1429{
     1430        struct snd_ca_midi *midi;
     1431        char *name;
     1432        int err;
     1433
     1434        if (channel == CA0106_MIDI_CHAN_B) {
     1435                name = "CA0106 MPU-401 (UART) B";
     1436                midi =  &chip->midi2;
     1437                midi->tx_enable = INTE_MIDI_TX_B;
     1438                midi->rx_enable = INTE_MIDI_RX_B;
     1439                midi->ipr_tx = IPR_MIDI_TX_B;
     1440                midi->ipr_rx = IPR_MIDI_RX_B;
     1441                midi->port = MIDI_UART_B_DATA;
     1442        } else {
     1443                name = "CA0106 MPU-401 (UART)";
     1444                midi =  &chip->midi;
     1445                midi->tx_enable = INTE_MIDI_TX_A;
     1446                midi->rx_enable = INTE_MIDI_TX_B;
     1447                midi->ipr_tx = IPR_MIDI_TX_A;
     1448                midi->ipr_rx = IPR_MIDI_RX_A;
     1449                midi->port = MIDI_UART_A_DATA;
     1450        }
     1451
     1452        midi->reset = CA0106_MPU401_RESET;
     1453        midi->enter_uart = CA0106_MPU401_ENTER_UART;
     1454        midi->ack = CA0106_MPU401_ACK;
     1455
     1456        midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
     1457        midi->output_ready = CA0106_MIDI_OUTPUT_READY;
     1458
     1459        midi->channel = channel;
     1460
     1461        midi->interrupt_enable = ca0106_midi_interrupt_enable;
     1462        midi->interrupt_disable = ca0106_midi_interrupt_disable;
     1463
     1464        midi->read = ca0106_midi_read;
     1465        midi->write = ca0106_midi_write;
     1466
     1467        midi->get_dev_id_card = ca0106_dev_id_card;
     1468        midi->get_dev_id_port = ca0106_dev_id_port;
     1469
     1470        midi->dev_id = chip;
     1471       
     1472        if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
     1473                return err;
     1474
     1475        return 0;
     1476}
     1477
     1478
    13241479static int __devinit snd_ca0106_probe(struct pci_dev *pci,
    13251480                                        const struct pci_device_id *pci_id)
    13261481{
    13271482        static int dev;
    1328         snd_card_t *card;
    1329         ca0106_t *chip;
     1483        struct snd_card *card;
     1484        struct snd_ca0106 *chip;
    13301485        int err;
    13311486
     
    13611516                snd_card_free(card);
    13621517                return err;
    1363         }
     1518        }
    13641519        if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
    1365             if ((err = snd_ca0106_ac97(chip)) < 0) {
    1366                 snd_card_free(card);
    1367                 return err;
    1368             }
    1369         }
     1520                if ((err = snd_ca0106_ac97(chip)) < 0) {
     1521                        snd_card_free(card);
     1522                        return err;
     1523                }
     1524        }
    13701525        if ((err = snd_ca0106_mixer(chip)) < 0) {
    13711526                snd_card_free(card);
     
    13731528        }
    13741529
     1530        snd_printdd("ca0106: probe for MIDI channel A ...");
     1531        if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
     1532                snd_card_free(card);
     1533                snd_printdd(" failed, err=0x%x\n",err);
     1534                return err;
     1535        }
     1536        snd_printdd(" done.\n");
     1537
     1538#ifdef CONFIG_PROC_FS
    13751539        snd_ca0106_proc_init(chip);
     1540#endif
    13761541
    13771542        if ((err = snd_card_register(card)) < 0) {
     
    14001565// pci_driver definition
    14011566static struct pci_driver driver = {
    1402     0,0,0,
    1403         /*.name = */"CA0106",
    1404         /*.id_table = */snd_ca0106_ids,
    1405         /*.probe = */snd_ca0106_probe,
    1406         /*.remove = */snd_ca0106_remove,
    1407         0,0
     1567        .name = "CA0106",
     1568        .id_table = snd_ca0106_ids,
     1569        .probe = snd_ca0106_probe,
     1570        .remove = __devexit_p(snd_ca0106_remove),
    14081571};
    14091572
     
    14111574static int __init alsa_card_ca0106_init(void)
    14121575{
    1413         int err;
    1414 
    1415         if ((err = pci_module_init(&driver)) > 0)
    1416                 return err;
    1417 
    1418         return 0;
     1576        return pci_register_driver(&driver);
    14191577}
    14201578
  • GPL/trunk/alsa-kernel/pci/ca0106/ca0106_mixer.c

    r32 r76  
    1 #define __NO_VERSION__
    21/*
    32 *  Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
     
    76 *  FEATURES currently supported:
    87 *    See ca0106_main.c for features.
    9  *
     8 * 
    109 *  Changelog:
    1110 *    Support interrupts per period.
     
    6665#include <linux/pci.h>
    6766#include <linux/slab.h>
    68 //#include <linux/moduleparam.h>
     67#include <linux/moduleparam.h>
    6968#include <sound/core.h>
    7069#include <sound/initval.h>
     
    7574#include "ca0106.h"
    7675
    77 static int snd_ca0106_shared_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     76static int snd_ca0106_shared_spdif_info(struct snd_kcontrol *kcontrol,
     77                                        struct snd_ctl_elem_info *uinfo)
    7878{
    7979        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     
    8484}
    8585
    86 static int snd_ca0106_shared_spdif_get(snd_kcontrol_t * kcontrol,
    87                                         snd_ctl_elem_value_t * ucontrol)
    88 {
    89         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     86static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol,
     87                                        struct snd_ctl_elem_value *ucontrol)
     88{
     89        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    9090
    9191        ucontrol->value.enumerated.item[0] = emu->spdif_enable;
     
    9393}
    9494
    95 static int snd_ca0106_shared_spdif_put(snd_kcontrol_t * kcontrol,
    96                                         snd_ctl_elem_value_t * ucontrol)
    97 {
    98         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     95static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,
     96                                        struct snd_ctl_elem_value *ucontrol)
     97{
     98        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    9999        unsigned int val;
    100100        int change = 0;
     
    116116                } else {
    117117                        /* Analog */
    118                     snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
    119                     snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
    120                     snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
    121                                          snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000);
    122                     mask = inl(emu->port + GPIO) | 0x101;
    123                     outl(mask, emu->port + GPIO);
     118                        snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
     119                        snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
     120                        snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,
     121                                snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000);
     122                        mask = inl(emu->port + GPIO) | 0x101;
     123                        outl(mask, emu->port + GPIO);
    124124                }
    125125        }
     
    127127}
    128128
    129 static snd_kcontrol_new_t snd_ca0106_shared_spdif __devinitdata =
    130 {
    131         /*.iface =      */SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,
    132         /*.name =       */      "SPDIF Out", 0,0,0,
    133         /*.info =       */      snd_ca0106_shared_spdif_info,
    134         /*.get =        */      snd_ca0106_shared_spdif_get,
    135         /*.put =        */      snd_ca0106_shared_spdif_put,0
    136 };
    137 
    138 static int snd_ca0106_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    139 {
    140         static char *texts[6] = { "SPDIF out", "i2s mixer out", "SPDIF in", "i2s in", "AC97 in", "SRC out" };
     129static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol,
     130                                          struct snd_ctl_elem_info *uinfo)
     131{
     132        static char *texts[6] = {
     133                "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out"
     134        };
    141135
    142136        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     
    149143}
    150144
    151 static int snd_ca0106_capture_source_get(snd_kcontrol_t * kcontrol,
    152                                         snd_ctl_elem_value_t * ucontrol)
    153 {
    154         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     145static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol,
     146                                        struct snd_ctl_elem_value *ucontrol)
     147{
     148        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    155149
    156150        ucontrol->value.enumerated.item[0] = emu->capture_source;
     
    158152}
    159153
    160 static int snd_ca0106_capture_source_put(snd_kcontrol_t * kcontrol,
    161                                         snd_ctl_elem_value_t * ucontrol)
    162 {
    163         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     154static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
     155                                        struct snd_ctl_elem_value *ucontrol)
     156{
     157        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    164158        unsigned int val;
    165159        int change = 0;
     
    178172}
    179173
    180 static snd_kcontrol_new_t snd_ca0106_capture_source __devinitdata =
    181 {
    182         /*.iface =    */  SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    183         /*.name =     */        "Capture Source",0,0,0,
    184         /*.info =     */        snd_ca0106_capture_source_info,
    185         /*.get =      */        snd_ca0106_capture_source_get,
    186         /*.put =      */        snd_ca0106_capture_source_put,0
     174static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol,
     175                                               struct snd_ctl_elem_info *uinfo)
     176{
     177        static char *texts[2] = { "Line in", "Mic in" };
     178
     179        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     180        uinfo->count = 1;
     181        uinfo->value.enumerated.items = 2;
     182        if (uinfo->value.enumerated.item > 1)
     183                uinfo->value.enumerated.item = 1;
     184        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     185        return 0;
     186}
     187
     188static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol,
     189                                        struct snd_ctl_elem_value *ucontrol)
     190{
     191        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
     192
     193        ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in;
     194        return 0;
     195}
     196
     197static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,
     198                                        struct snd_ctl_elem_value *ucontrol)
     199{
     200        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
     201        unsigned int val;
     202        int change = 0;
     203        u32 tmp;
     204
     205        val = ucontrol->value.enumerated.item[0] ;
     206        change = (emu->capture_mic_line_in != val);
     207        if (change) {
     208                emu->capture_mic_line_in = val;
     209                if (val) {
     210                        snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */
     211                        tmp = inl(emu->port+GPIO) & ~0x400;
     212                        tmp = tmp | 0x400;
     213                        outl(tmp, emu->port+GPIO);
     214                        snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC);
     215                } else {
     216                        snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */
     217                        tmp = inl(emu->port+GPIO) & ~0x400;
     218                        outl(tmp, emu->port+GPIO);
     219                        snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN);
     220                }
     221        }
     222        return change;
     223}
     224
     225static struct snd_kcontrol_new snd_ca0106_capture_mic_line_in __devinitdata =
     226{
     227        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     228        .name =         "Mic/Line in Capture",
     229        .info =         snd_ca0106_capture_mic_line_in_info,
     230        .get =          snd_ca0106_capture_mic_line_in_get,
     231        .put =          snd_ca0106_capture_mic_line_in_put
    187232};
    188233
    189 static int snd_ca0106_capture_mic_line_in_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    190 {
    191     static char *texts[2] = { "Line in", "Mic in" };
    192 
    193     uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    194     uinfo->count = 1;
    195     uinfo->value.enumerated.items = 2;
    196     if (uinfo->value.enumerated.item > 1)
    197         uinfo->value.enumerated.item = 1;
    198     strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    199     return 0;
    200 }
    201 
    202 static int snd_ca0106_capture_mic_line_in_get(snd_kcontrol_t * kcontrol,
    203                                               snd_ctl_elem_value_t * ucontrol)
    204 {
    205     ca0106_t *emu = snd_kcontrol_chip(kcontrol);
    206 
    207     ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in;
    208     return 0;
    209 }
    210 
    211 static int snd_ca0106_capture_mic_line_in_put(snd_kcontrol_t * kcontrol,
    212                                               snd_ctl_elem_value_t * ucontrol)
    213 {
    214     ca0106_t *emu = snd_kcontrol_chip(kcontrol);
    215     unsigned int val;
    216     int change = 0;
    217     u32 tmp;
    218 
    219     val = ucontrol->value.enumerated.item[0] ;
    220     change = (emu->capture_mic_line_in != val);
    221     if (change) {
    222         emu->capture_mic_line_in = val;
    223         if (val) {
    224             snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */
    225             tmp = inl(emu->port+GPIO) & ~0x400;
    226             tmp = tmp | 0x400;
    227             outl(tmp, emu->port+GPIO);
    228             snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC);
    229         } else {
    230             snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_PHONE); /* Mute input */
    231             tmp = inl(emu->port+GPIO) & ~0x400;
    232             outl(tmp, emu->port+GPIO);
    233             snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN);
    234         }
    235     }
    236     return change;
    237 }
    238 
    239 static snd_kcontrol_new_t snd_ca0106_capture_mic_line_in __devinitdata =
    240 {
    241     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    242     "Mic/Line in Capture",0,0,0,
    243     snd_ca0106_capture_mic_line_in_info,
    244     snd_ca0106_capture_mic_line_in_get,
    245     snd_ca0106_capture_mic_line_in_put,0
    246 };
    247 
    248 static int snd_ca0106_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     234static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol,
     235                                 struct snd_ctl_elem_info *uinfo)
    249236{
    250237        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
     
    253240}
    254241
    255 static int snd_ca0106_spdif_get(snd_kcontrol_t * kcontrol,
    256                                  snd_ctl_elem_value_t * ucontrol)
    257 {
    258         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     242static int snd_ca0106_spdif_get(struct snd_kcontrol *kcontrol,
     243                                 struct snd_ctl_elem_value *ucontrol)
     244{
     245        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    259246        unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    260247
     
    266253}
    267254
    268 static int snd_ca0106_spdif_get_mask(snd_kcontrol_t * kcontrol,
    269                                       snd_ctl_elem_value_t * ucontrol)
     255static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol,
     256                                      struct snd_ctl_elem_value *ucontrol)
    270257{
    271258        ucontrol->value.iec958.status[0] = 0xff;
     
    276263}
    277264
    278 static int snd_ca0106_spdif_put(snd_kcontrol_t * kcontrol,
    279                                  snd_ctl_elem_value_t * ucontrol)
    280 {
    281         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     265static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol,
     266                                 struct snd_ctl_elem_value *ucontrol)
     267{
     268        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    282269        unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    283270        int change;
     
    296283}
    297284
    298 static snd_kcontrol_new_t snd_ca0106_spdif_mask_control =
    299 {
    300       /*  .iface =      */  SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    301       /*  .name =       */  SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), 0,
    302       /*  .access =     */  SNDRV_CTL_ELEM_ACCESS_READ,
    303       /*  .count =      */  4,
    304       /*  .info =       */  snd_ca0106_spdif_info,
    305       /*  .get =        */  snd_ca0106_spdif_get_mask,0,0
    306 };
    307 
    308 static snd_kcontrol_new_t snd_ca0106_spdif_control =
    309 {
    310       /*  .iface =      */  SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    311       /*  .name =       */  SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),0,0,
    312       /*  .count =      */  4,
    313       /*  .info =       */  snd_ca0106_spdif_info,
    314       /*  .get =        */  snd_ca0106_spdif_get,
    315       /*  .put =        */  snd_ca0106_spdif_put, 0
    316 };
    317 
    318 static int snd_ca0106_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     285static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol,
     286                                  struct snd_ctl_elem_info *uinfo)
    319287{
    320288        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     
    325293}
    326294
    327 static int snd_ca0106_volume_get(snd_kcontrol_t * kcontrol,
    328                                        snd_ctl_elem_value_t * ucontrol, int reg, int channel_id)
    329 {
    330         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
     295static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol,
     296                                 struct snd_ctl_elem_value *ucontrol)
     297{
     298        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
    331299        unsigned int value;
     300        int channel_id, reg;
     301
     302        channel_id = (kcontrol->private_value >> 8) & 0xff;
     303        reg = kcontrol->private_value & 0xff;
    332304
    333305        value = snd_ca0106_ptr_read(emu, reg, channel_id);
     
    337309}
    338310
    339 static int snd_ca0106_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
    340                                        snd_ctl_elem_value_t * ucontrol)
    341 {
    342         int channel_id = CONTROL_FRONT_CHANNEL;
    343         int reg = PLAYBACK_VOLUME1;
    344         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    345 }
    346 
    347 static int snd_ca0106_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
    348                                        snd_ctl_elem_value_t * ucontrol)
    349 {
    350         int channel_id = CONTROL_CENTER_LFE_CHANNEL;
    351         int reg = PLAYBACK_VOLUME1;
    352         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    353 }
    354 static int snd_ca0106_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
    355                                        snd_ctl_elem_value_t * ucontrol)
    356 {
    357         int channel_id = CONTROL_UNKNOWN_CHANNEL;
    358         int reg = PLAYBACK_VOLUME1;
    359         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    360 }
    361 static int snd_ca0106_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
    362                                        snd_ctl_elem_value_t * ucontrol)
    363 {
    364         int channel_id = CONTROL_REAR_CHANNEL;
    365         int reg = PLAYBACK_VOLUME1;
    366         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    367 }
    368 static int snd_ca0106_volume_get_analog_front(snd_kcontrol_t * kcontrol,
    369                                        snd_ctl_elem_value_t * ucontrol)
    370 {
    371         int channel_id = CONTROL_FRONT_CHANNEL;
    372         int reg = PLAYBACK_VOLUME2;
    373         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    374 }
    375 
    376 static int snd_ca0106_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
    377                                        snd_ctl_elem_value_t * ucontrol)
    378 {
    379         int channel_id = CONTROL_CENTER_LFE_CHANNEL;
    380         int reg = PLAYBACK_VOLUME2;
    381         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    382 }
    383 static int snd_ca0106_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
    384                                        snd_ctl_elem_value_t * ucontrol)
    385 {
    386         int channel_id = CONTROL_UNKNOWN_CHANNEL;
    387         int reg = PLAYBACK_VOLUME2;
    388         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    389 }
    390 static int snd_ca0106_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
    391                                        snd_ctl_elem_value_t * ucontrol)
    392 {
    393         int channel_id = CONTROL_REAR_CHANNEL;
    394         int reg = PLAYBACK_VOLUME2;
    395         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    396 }
    397 
    398 static int snd_ca0106_volume_get_feedback(snd_kcontrol_t * kcontrol,
    399                                        snd_ctl_elem_value_t * ucontrol)
    400 {
    401         int channel_id = 1;
    402         int reg = CAPTURE_CONTROL;
    403         return snd_ca0106_volume_get(kcontrol, ucontrol, reg, channel_id);
    404 }
    405 
    406 static int snd_ca0106_volume_put(snd_kcontrol_t * kcontrol,
    407                                        snd_ctl_elem_value_t * ucontrol, int reg, int channel_id)
    408 {
    409         ca0106_t *emu = snd_kcontrol_chip(kcontrol);
    410         unsigned int value;
    411         //value = snd_ca0106_ptr_read(emu, reg, channel_id);
    412         //value = value & 0xffff;
    413         value = ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
    414         value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
    415         snd_ca0106_ptr_write(emu, reg, channel_id, value);
    416         return 1;
    417 }
    418 static int snd_ca0106_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
    419                                        snd_ctl_elem_value_t * ucontrol)
    420 {
    421         int channel_id = CONTROL_FRONT_CHANNEL;
    422         int reg = PLAYBACK_VOLUME1;
    423         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    424 }
    425 static int snd_ca0106_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
    426                                        snd_ctl_elem_value_t * ucontrol)
    427 {
    428         int channel_id = CONTROL_CENTER_LFE_CHANNEL;
    429         int reg = PLAYBACK_VOLUME1;
    430         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    431 }
    432 static int snd_ca0106_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
    433                                        snd_ctl_elem_value_t * ucontrol)
    434 {
    435         int channel_id = CONTROL_UNKNOWN_CHANNEL;
    436         int reg = PLAYBACK_VOLUME1;
    437         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    438 }
    439 static int snd_ca0106_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
    440                                        snd_ctl_elem_value_t * ucontrol)
    441 {
    442         int channel_id = CONTROL_REAR_CHANNEL;
    443         int reg = PLAYBACK_VOLUME1;
    444         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    445 }
    446 static int snd_ca0106_volume_put_analog_front(snd_kcontrol_t * kcontrol,
    447                                        snd_ctl_elem_value_t * ucontrol)
    448 {
    449         int channel_id = CONTROL_FRONT_CHANNEL;
    450         int reg = PLAYBACK_VOLUME2;
    451         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    452 }
    453 static int snd_ca0106_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
    454                                        snd_ctl_elem_value_t * ucontrol)
    455 {
    456         int channel_id = CONTROL_CENTER_LFE_CHANNEL;
    457         int reg = PLAYBACK_VOLUME2;
    458         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    459 }
    460 static int snd_ca0106_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
    461                                        snd_ctl_elem_value_t * ucontrol)
    462 {
    463         int channel_id = CONTROL_UNKNOWN_CHANNEL;
    464         int reg = PLAYBACK_VOLUME2;
    465         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    466 }
    467 static int snd_ca0106_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
    468                                        snd_ctl_elem_value_t * ucontrol)
    469 {
    470         int channel_id = CONTROL_REAR_CHANNEL;
    471         int reg = PLAYBACK_VOLUME2;
    472         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    473 }
    474 
    475 static int snd_ca0106_volume_put_feedback(snd_kcontrol_t * kcontrol,
    476                                        snd_ctl_elem_value_t * ucontrol)
    477 {
    478         int channel_id = 1;
    479         int reg = CAPTURE_CONTROL;
    480         return snd_ca0106_volume_put(kcontrol, ucontrol, reg, channel_id);
    481 }
    482 
    483 static snd_kcontrol_new_t snd_ca0106_volume_control_analog_front =
    484 {
    485     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    486     "Analog Front Playback Volume"
    487         ,0,0,0,
    488         snd_ca0106_volume_info,
    489         snd_ca0106_volume_get_analog_front,
    490         snd_ca0106_volume_put_analog_front,0
     311static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol,
     312                                 struct snd_ctl_elem_value *ucontrol)
     313{
     314        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
     315        unsigned int oval, nval;
     316        int channel_id, reg;
     317
     318        channel_id = (kcontrol->private_value >> 8) & 0xff;
     319        reg = kcontrol->private_value & 0xff;
     320
     321        oval = snd_ca0106_ptr_read(emu, reg, channel_id);
     322        nval = ((0xff - ucontrol->value.integer.value[0]) << 24) |
     323                ((0xff - ucontrol->value.integer.value[1]) << 16);
     324        nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) |
     325                ((0xff - ucontrol->value.integer.value[1]) );
     326        if (oval == nval)
     327                return 0;
     328        snd_ca0106_ptr_write(emu, reg, channel_id, nval);
     329        return 1;
     330}
     331
     332#define CA_VOLUME(xname,chid,reg) \
     333{                                                               \
     334        .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,     \
     335        .info = snd_ca0106_volume_info,                         \
     336        .get =          snd_ca0106_volume_get,                  \
     337        .put =          snd_ca0106_volume_put,                  \
     338        .private_value = ((chid) << 8) | (reg)                  \
     339}
     340
     341
     342static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = {
     343        CA_VOLUME("Analog Front Playback Volume",
     344                  CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),
     345        CA_VOLUME("Analog Rear Playback Volume",
     346                  CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),
     347        CA_VOLUME("Analog Center/LFE Playback Volume",
     348                  CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),
     349        CA_VOLUME("Analog Side Playback Volume",
     350                  CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),
     351
     352        CA_VOLUME("IEC958 Front Playback Volume",
     353                  CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),
     354        CA_VOLUME("IEC958 Rear Playback Volume",
     355                  CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),
     356        CA_VOLUME("IEC958 Center/LFE Playback Volume",
     357                  CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),
     358        CA_VOLUME("IEC958 Unknown Playback Volume",
     359                  CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),
     360
     361        CA_VOLUME("CAPTURE feedback Playback Volume",
     362                  1, CAPTURE_CONTROL),
     363
     364        {
     365                .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     366                .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     367                .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
     368                .count =        4,
     369                .info =         snd_ca0106_spdif_info,
     370                .get =          snd_ca0106_spdif_get_mask
     371        },
     372        {
     373                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     374                .name =         "IEC958 Playback Switch",
     375                .info =         snd_ca0106_shared_spdif_info,
     376                .get =          snd_ca0106_shared_spdif_get,
     377                .put =          snd_ca0106_shared_spdif_put
     378        },
     379        {
     380                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     381                .name =         "Capture Source",
     382                .info =         snd_ca0106_capture_source_info,
     383                .get =          snd_ca0106_capture_source_get,
     384                .put =          snd_ca0106_capture_source_put
     385        },
     386        {
     387                .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     388                .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
     389                .count =        4,
     390                .info =         snd_ca0106_spdif_info,
     391                .get =          snd_ca0106_spdif_get,
     392                .put =          snd_ca0106_spdif_put
     393        },
    491394};
    492 static snd_kcontrol_new_t snd_ca0106_volume_control_analog_center_lfe =
    493 {
    494          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    495          "Analog Center/LFE Playback Volume",0,0,0,
    496          snd_ca0106_volume_info,
    497          snd_ca0106_volume_get_analog_center_lfe,
    498          snd_ca0106_volume_put_analog_center_lfe,0
    499 };
    500 static snd_kcontrol_new_t snd_ca0106_volume_control_analog_unknown =
    501 {
    502          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    503          "Analog Side Playback Volume",0,0,0,
    504          snd_ca0106_volume_info,
    505          snd_ca0106_volume_get_analog_unknown,
    506          snd_ca0106_volume_put_analog_unknown,0
    507 };
    508 static snd_kcontrol_new_t snd_ca0106_volume_control_analog_rear =
    509 {
    510         SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    511         "Analog Rear Playback Volume",0,0,0,
    512         snd_ca0106_volume_info,
    513         snd_ca0106_volume_get_analog_rear,
    514         snd_ca0106_volume_put_analog_rear,0
    515 };
    516 static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_front =
    517 {
    518          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    519          "SPDIF Front Playback Volume",0,0,0,
    520          snd_ca0106_volume_info,
    521          snd_ca0106_volume_get_spdif_front,
    522          snd_ca0106_volume_put_spdif_front,0
    523 };
    524 static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_center_lfe =
    525 {
    526          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    527          "SPDIF Center/LFE Playback Volume",0,0,0,
    528          snd_ca0106_volume_info,
    529          snd_ca0106_volume_get_spdif_center_lfe,
    530          snd_ca0106_volume_put_spdif_center_lfe,0
    531 };
    532 static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_unknown =
    533 {
    534          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    535          "SPDIF Unknown Playback Volume",0,0,0,
    536          snd_ca0106_volume_info,
    537          snd_ca0106_volume_get_spdif_unknown,
    538          snd_ca0106_volume_put_spdif_unknown,0
    539 };
    540 static snd_kcontrol_new_t snd_ca0106_volume_control_spdif_rear =
    541 {
    542          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    543          "SPDIF Rear Playback Volume",0,0,0,
    544          snd_ca0106_volume_info,
    545          snd_ca0106_volume_get_spdif_rear,
    546          snd_ca0106_volume_put_spdif_rear,0
    547 };
    548 
    549 static snd_kcontrol_new_t snd_ca0106_volume_control_feedback =
    550 {
    551          SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    552          "CAPTURE feedback Playback",0,0,0,
    553          snd_ca0106_volume_info,
    554          snd_ca0106_volume_get_feedback,
    555          snd_ca0106_volume_put_feedback,0
    556 };
    557 
    558 
    559 static int remove_ctl(snd_card_t *card, const char *name)
    560 {
    561         snd_ctl_elem_id_t id;
     395
     396static int __devinit remove_ctl(struct snd_card *card, const char *name)
     397{
     398        struct snd_ctl_elem_id id;
    562399        memset(&id, 0, sizeof(id));
    563400        strcpy(id.name, name);
     
    566403}
    567404
    568 static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
    569 {
    570         snd_ctl_elem_id_t sid;
     405static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card, const char *name)
     406{
     407        struct snd_ctl_elem_id sid;
    571408        memset(&sid, 0, sizeof(sid));
    572409        /* FIXME: strcpy is bad. */
     
    576413}
    577414
    578 static int rename_ctl(snd_card_t *card, const char *src, const char *dst)
    579 {
    580         snd_kcontrol_t *kctl = ctl_find(card, src);
     415static int __devinit rename_ctl(struct snd_card *card, const char *src, const char *dst)
     416{
     417        struct snd_kcontrol *kctl = ctl_find(card, src);
    581418        if (kctl) {
    582419                strcpy(kctl->id.name, dst);
     
    586423}
    587424
    588 int __devinit snd_ca0106_mixer(ca0106_t *emu)
    589 {
    590         int err;
    591         snd_kcontrol_t *kctl;
    592         snd_card_t *card = emu->card;
     425int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
     426{
     427        int i, err;
     428        struct snd_card *card = emu->card;
    593429        char **c;
    594430        static char *ca0106_remove_ctls[] = {
     
    630466        };
    631467#if 1
    632         for (c=ca0106_remove_ctls; *c; c++)
     468        for (c = ca0106_remove_ctls; *c; c++)
    633469                remove_ctl(card, *c);
    634         for (c=ca0106_rename_ctls; *c; c += 2)
     470        for (c = ca0106_rename_ctls; *c; c += 2)
    635471                rename_ctl(card, c[0], c[1]);
    636472#endif
    637473
    638         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_front, emu)) == NULL)
    639                 return -ENOMEM;
    640         if ((err = snd_ctl_add(card, kctl)))
    641                 return err;
    642         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_rear, emu)) == NULL)
    643                 return -ENOMEM;
    644         if ((err = snd_ctl_add(card, kctl)))
    645                 return err;
    646         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_center_lfe, emu)) == NULL)
    647                 return -ENOMEM;
    648         if ((err = snd_ctl_add(card, kctl)))
    649                 return err;
    650         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_analog_unknown, emu)) == NULL)
    651                 return -ENOMEM;
    652         if ((err = snd_ctl_add(card, kctl)))
    653                 return err;
    654         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_front, emu)) == NULL)
    655                 return -ENOMEM;
    656         if ((err = snd_ctl_add(card, kctl)))
    657                 return err;
    658         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_rear, emu)) == NULL)
    659                 return -ENOMEM;
    660         if ((err = snd_ctl_add(card, kctl)))
    661                 return err;
    662         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_center_lfe, emu)) == NULL)
    663                 return -ENOMEM;
    664         if ((err = snd_ctl_add(card, kctl)))
    665                 return err;
    666         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_spdif_unknown, emu)) == NULL)
    667                 return -ENOMEM;
    668         if ((err = snd_ctl_add(card, kctl)))
    669                 return err;
    670         if ((kctl = snd_ctl_new1(&snd_ca0106_volume_control_feedback, emu)) == NULL)
    671                 return -ENOMEM;
    672         if ((err = snd_ctl_add(card, kctl)))
    673                 return err;
    674         if ((kctl = snd_ctl_new1(&snd_ca0106_spdif_mask_control, emu)) == NULL)
    675                 return -ENOMEM;
    676         if ((err = snd_ctl_add(card, kctl)))
    677                 return err;
    678         if ((kctl = snd_ctl_new1(&snd_ca0106_shared_spdif, emu)) == NULL)
    679                 return -ENOMEM;
    680         if ((err = snd_ctl_add(card, kctl)))
    681                 return err;
    682         if ((kctl = snd_ctl_new1(&snd_ca0106_capture_source, emu)) == NULL)
    683                 return -ENOMEM;
    684         if ((err = snd_ctl_add(card, kctl)))
    685             return err;
    686         if (emu->details->i2c_adc == 1) {
    687             if ((kctl = snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)) == NULL)
    688                 return -ENOMEM;
    689             if ((err = snd_ctl_add(card, kctl)))
    690                 return err;
    691         }
    692         if ((kctl = snd_ctl_new1(&snd_ca0106_spdif_control, emu)) == NULL)
    693                 return -ENOMEM;
    694         if ((err = snd_ctl_add(card, kctl)))
    695                 return err;
     474        for (i = 0; i < ARRAY_SIZE(snd_ca0106_volume_ctls); i++) {
     475                err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_volume_ctls[i], emu));
     476                if (err < 0)
     477                        return err;
     478        }
     479        if (emu->details->i2c_adc == 1) {
     480                err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
     481                if (err < 0)
     482                        return err;
     483        }
    696484        return 0;
    697485}
  • GPL/trunk/alsa-kernel/pci/ca0106/ca0106_proc.c

    r32 r76  
    1 #define __NO_VERSION__
    21/*
    32 *  Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
    43 *  Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
    5  *  Version: 0.0.17
     4 *  Version: 0.0.18
    65 *
    76 *  FEATURES currently supported:
     
    4140 *  0.0.17
    4241 *    Add iec958 file in proc file system to show status of SPDIF in.
    43  *   
     42 *  0.0.18
     43 *    Implement support for Line-in capture on SB Live 24bit.
     44 *
    4445 *  This code was initally based on code from ALSA's emu10k1x.c which is:
    4546 *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
     
    6667#include <linux/pci.h>
    6768#include <linux/slab.h>
    68 //#include <linux/moduleparam.h>
     69#include <linux/moduleparam.h>
    6970#include <sound/core.h>
    7071#include <sound/initval.h>
     
    7677#include "ca0106.h"
    7778
     79
     80#ifdef CONFIG_PROC_FS
    7881
    7982struct snd_ca0106_category_str {
     
    97100
    98101
    99 void snd_ca0106_proc_dump_iec958( snd_info_buffer_t *buffer, u32 value)
     102static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 value)
    100103{
    101104        int i;
     
    271274}
    272275
    273 static void snd_ca0106_proc_iec958(snd_info_entry_t *entry,
    274                                        snd_info_buffer_t * buffer)
    275 {
    276         ca0106_t *emu = entry->private_data;
     276static void snd_ca0106_proc_iec958(struct snd_info_entry *entry,
     277                                       struct snd_info_buffer *buffer)
     278{
     279        struct snd_ca0106 *emu = entry->private_data;
    277280        u32 value;
    278281
     
    293296}
    294297
    295 static void snd_ca0106_proc_reg_write32(snd_info_entry_t *entry,
    296                                        snd_info_buffer_t * buffer)
    297 {
    298         ca0106_t *emu = entry->private_data;
     298static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
     299                                       struct snd_info_buffer *buffer)
     300{
     301        struct snd_ca0106 *emu = entry->private_data;
    299302        unsigned long flags;
    300303        char line[64];
     
    313316}
    314317
    315 static void snd_ca0106_proc_reg_read32(snd_info_entry_t *entry,
    316                                        snd_info_buffer_t * buffer)
    317 {
    318         ca0106_t *emu = entry->private_data;
     318static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry,
     319                                       struct snd_info_buffer *buffer)
     320{
     321        struct snd_ca0106 *emu = entry->private_data;
    319322        unsigned long value;
    320323        unsigned long flags;
     
    329332}
    330333
    331 static void snd_ca0106_proc_reg_read16(snd_info_entry_t *entry,
    332                                        snd_info_buffer_t * buffer)
    333 {
    334         ca0106_t *emu = entry->private_data;
     334static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry,
     335                                       struct snd_info_buffer *buffer)
     336{
     337        struct snd_ca0106 *emu = entry->private_data;
    335338        unsigned int value;
    336339        unsigned long flags;
     
    345348}
    346349
    347 static void snd_ca0106_proc_reg_read8(snd_info_entry_t *entry,
    348                                        snd_info_buffer_t * buffer)
    349 {
    350         ca0106_t *emu = entry->private_data;
     350static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry,
     351                                       struct snd_info_buffer *buffer)
     352{
     353        struct snd_ca0106 *emu = entry->private_data;
    351354        unsigned int value;
    352355        unsigned long flags;
     
    361364}
    362365
    363 static void snd_ca0106_proc_reg_read1(snd_info_entry_t *entry,
    364                                        snd_info_buffer_t * buffer)
    365 {
    366         ca0106_t *emu = entry->private_data;
     366static void snd_ca0106_proc_reg_read1(struct snd_info_entry *entry,
     367                                       struct snd_info_buffer *buffer)
     368{
     369        struct snd_ca0106 *emu = entry->private_data;
    367370        unsigned long value;
    368371        int i,j;
     
    379382}
    380383
    381 static void snd_ca0106_proc_reg_read2(snd_info_entry_t *entry,
    382                                        snd_info_buffer_t * buffer)
    383 {
    384         ca0106_t *emu = entry->private_data;
     384static void snd_ca0106_proc_reg_read2(struct snd_info_entry *entry,
     385                                       struct snd_info_buffer *buffer)
     386{
     387        struct snd_ca0106 *emu = entry->private_data;
    385388        unsigned long value;
    386389        int i,j;
     
    397400}
    398401
    399 static void snd_ca0106_proc_reg_write(snd_info_entry_t *entry,
    400                                        snd_info_buffer_t * buffer)
    401 {
    402         ca0106_t *emu = entry->private_data;
     402static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
     403                                       struct snd_info_buffer *buffer)
     404{
     405        struct snd_ca0106 *emu = entry->private_data;
    403406        char line[64];
    404407        unsigned int reg, channel_id , val;
     
    413416}
    414417
    415 
    416 int __devinit snd_ca0106_proc_init(ca0106_t * emu)
    417 {
    418         snd_info_entry_t *entry;
     418static void snd_ca0106_proc_i2c_write(struct snd_info_entry *entry,
     419                                       struct snd_info_buffer *buffer)
     420{
     421        struct snd_ca0106 *emu = entry->private_data;
     422        char line[64];
     423        unsigned int reg, val;
     424#if 0
     425        while (!snd_info_get_line(buffer, line, sizeof(line))) {
     426                if (sscanf(line, "%x %x", &reg, &val) != 2)
     427                        continue;
     428                if ((reg <= 0x7f) || (val <= 0x1ff)) {
     429                        snd_ca0106_i2c_write(emu, reg, val);
     430                }
     431        }
     432#endif
     433}
     434
     435int __devinit snd_ca0106_proc_init(struct snd_ca0106 * emu)
     436{
     437        struct snd_info_entry *entry;
    419438       
    420439        if(! snd_card_proc_new(emu->card, "iec958", &entry))
     
    424443                entry->c.text.write_size = 64;
    425444                entry->c.text.write = snd_ca0106_proc_reg_write32;
     445                entry->mode |= S_IWUSR;
    426446        }
    427447        if(! snd_card_proc_new(emu->card, "ca0106_reg16", &entry))
     
    433453                entry->c.text.write_size = 64;
    434454                entry->c.text.write = snd_ca0106_proc_reg_write;
     455                entry->mode |= S_IWUSR;
     456//              entry->private_data = emu;
     457        }
     458        if(! snd_card_proc_new(emu->card, "ca0106_i2c", &entry)) {
     459                snd_info_set_text_ops(entry, emu, 1024, snd_ca0106_proc_i2c_write);
     460                entry->c.text.write_size = 64;
     461                entry->c.text.write = snd_ca0106_proc_i2c_write;
     462                entry->mode |= S_IWUSR;
    435463//              entry->private_data = emu;
    436464        }
     
    440468}
    441469
     470#endif /* CONFIG_PROC_FS */
  • GPL/trunk/alsa-kernel/pci/ca0106/makefile.os2

    r32 r76  
    1414#===================================================================
    1515FILE1    = ca0106_main.obj ca0106_proc.obj ca0106_mixer.obj
    16 FILE2    =
     16FILE2    = ca_midi.obj
    1717FILE3    =
    1818FILE4    =
  • GPL/trunk/alsa-kernel/pci/cs4281.c

    r34 r76  
    10921092        change = 1;
    10931093    }
    1094     if (ucontrol->value.integer.value[0] != volL) {
     1094    if (ucontrol->value.integer.value[0] != volR) {
    10951095        volR = CS_VOL_MASK - (ucontrol->value.integer.value[1] & CS_VOL_MASK);
    10961096        snd_cs4281_pokeBA0(chip, regR, volR);
     
    14621462{
    14631463    unsigned int tmp;
    1464     int timeout;
     1464    unsigned long end_time;
    14651465    int retry_count = 2;
    14661466
     
    15411541     * Wait for the DLL ready signal from the clock logic.
    15421542     */
    1543 #ifdef TARGET_OS2
    1544     //  end_time = (jiffies + 1000) + 1;
    1545 #else
    1546     //  end_time = (jiffies + HZ / 4) + 1;
    1547 #endif
    1548     timeout = HZ;
     1543    end_time = jiffies + HZ;
    15491544    do {
    15501545        /*
     
    15541549        if (snd_cs4281_peekBA0(chip, BA0_CLKCR1) & BA0_CLKCR1_DLLRDY)
    15551550            goto __ok0;
    1556         snd_cs4281_delay_long();
    1557     } while (timeout-- > 0);
     1551        schedule_timeout_uninterruptible(1);
     1552    } while (time_after_eq(end_time, jiffies));
    15581553
    15591554    snd_printk(KERN_ERR "DLLRDY not seen\n");
     
    15721567     * Wait for the codec ready signal from the AC97 codec.
    15731568     */
    1574 #ifdef TARGET_OS2
    1575     //  end_time = (jiffies + 1000) + 1;
    1576 #else
    1577     //  end_time = (jiffies + (3 * HZ) / 4) + 1;
    1578 #endif
    1579     timeout = HZ;
     1569    end_time = jiffies + HZ;
    15801570    do {
    15811571        /*
     
    15851575        if (snd_cs4281_peekBA0(chip, BA0_ACSTS) & BA0_ACSTS_CRDY)
    15861576            goto __ok1;
    1587         snd_cs4281_delay_long();
    1588     } while (timeout-- > 0);
     1577        schedule_timeout_uninterruptible(1);
     1578    } while (time_after_eq(end_time, jiffies));
    15891579
    15901580    snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS));
     
    15931583__ok1:
    15941584    if (chip->dual_codec) {
    1595         timeout = HZ;
     1585        end_time = jiffies + HZ;
    15961586        do {
    15971587            if (snd_cs4281_peekBA0(chip, BA0_ACSTS2) & BA0_ACSTS_CRDY)
    15981588                goto __codec2_ok;
    1599             snd_cs4281_delay_long();
    1600         } while (timeout-- > 0);
     1589            schedule_timeout_uninterruptible(1);
     1590        } while (time_after_eq(end_time, jiffies));
    16011591        snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n");
    16021592        chip->dual_codec = 0;
     
    16151605     *  the codec is pumping ADC data across the AC-link.
    16161606     */
    1617 
    1618 #ifdef TARGET_OS2
    1619     //  end_time = (jiffies + 5000);
    1620 #else
    1621     //  end_time = (jiffies + (5 * HZ) / 4) + 1;
    1622 #endif
    1623     timeout = HZ;
     1607    end_time = jiffies + HZ;
    16241608    do {
    16251609        /*
     
    16291613        if ((snd_cs4281_peekBA0(chip, BA0_ACISV) & (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) == (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4)))
    16301614            goto __ok2;
    1631         snd_cs4281_delay_long();
    1632     } while (timeout-- > 0);
     1615        schedule_timeout_uninterruptible(1);
     1616    } while (time_after_eq(end_time, jiffies));
    16331617
    16341618    if (--retry_count > 0)
  • GPL/trunk/alsa-kernel/pci/cs46xx/cs46xx.c

    r34 r76  
    4949static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    5050static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
    51 static int external_amp[SNDRV_CARDS] = {0};
    52 static int thinkpad[SNDRV_CARDS] = {1,0,0,0,0,0,0,0};
    53 static int mmap_valid[SNDRV_CARDS] = {0};
     51static int external_amp[SNDRV_CARDS] = {0,0,0,0,0,0,0,0};
     52static int thinkpad[SNDRV_CARDS] = {0,0,0,0,0,0,0,0};
     53static int mmap_valid[SNDRV_CARDS] = {1,1,1,1,1,1,1,1};
    5454
    5555//module_param_array(index, int, NULL, 0444);
     
    167167        .id_table = snd_cs46xx_ids,
    168168        .probe = snd_card_cs46xx_probe,
    169         .remove = snd_card_cs46xx_remove,
     169        .remove = __devexit_p(snd_card_cs46xx_remove),
    170170#ifdef CONFIG_PM
    171171        .suspend = snd_cs46xx_suspend,
  • GPL/trunk/alsa-kernel/pci/cs46xx/cs46xx_lib.c

    r34 r76  
    5454#include <linux/slab.h>
    5555//#include <linux/gameport.h>
     56#include <linux/mutex.h>
     57
    5658
    5759#include <sound/core.h>
     
    316318
    317319        snd_assert(!(offset & 3) && !(len & 3), return -EINVAL);
    318         dst = (char*)chip->region.idx[bank+1].remap_addr + offset;
     320        dst = chip->region.idx[bank+1].remap_addr + offset;
    319321        len /= sizeof(u32);
    320322
     
    322324        while (len-- > 0) {
    323325                writel(*src++, dst);
    324                 (char*)dst += sizeof(u32);
     326                dst += sizeof(u32);
    325327        }
    326328        return 0;
     
    910912        snd_assert (sample_rate != 0, return -ENXIO);
    911913
    912         down (&chip->spos_mutex);
     914        mutex_lock(&chip->spos_mutex);
    913915
    914916        if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) {
    915                 up (&chip->spos_mutex);
     917                mutex_unlock(&chip->spos_mutex);
    916918                return -ENXIO;
    917919        }
    918920
    919         snd_assert (cpcm->pcm_channel != NULL);
     921        snd_assert (cpcm->pcm_channel != NULL, return -ENXIO);
    920922        if (!cpcm->pcm_channel) {
    921                 up (&chip->spos_mutex);
     923                mutex_unlock(&chip->spos_mutex);
    922924                return -ENXIO;
    923925        }
     
    925927
    926928        if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size)) {
    927                  up (&chip->spos_mutex);
     929                 mutex_unlock(&chip->spos_mutex);
    928930                 return -EINVAL;
    929931         }
     
    952954                        substream->ops = &snd_cs46xx_playback_iec958_ops;
    953955                } else {
    954                         snd_assert(0);
     956                        snd_assert(0, return -ENXIO);
    955957                }
    956958#else
     
    966968                if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) {
    967969#ifdef CONFIG_SND_CS46XX_NEW_DSP
    968                         up (&chip->spos_mutex);
     970                        mutex_unlock(&chip->spos_mutex);
    969971#endif
    970972                        return err;
     
    981983                        substream->ops = &snd_cs46xx_playback_indirect_iec958_ops;
    982984                } else {
    983                         snd_assert(0);
     985                        snd_assert(0, return -ENXIO);
    984986                }
    985987#else
     
    990992
    991993#ifdef CONFIG_SND_CS46XX_NEW_DSP
    992         up (&chip->spos_mutex);
     994        mutex_unlock(&chip->spos_mutex);
    993995#endif
    994996
     
    13051307        struct snd_pcm_runtime *runtime = substream->runtime;
    13061308
    1307         cpcm = (struct snd_cs46xx_pcm * )kzalloc(sizeof(*cpcm), GFP_KERNEL);
     1309        cpcm = kzalloc(sizeof(*cpcm), GFP_KERNEL);
    13081310        if (cpcm == NULL)
    13091311                return -ENOMEM;
     
    13201322        cpcm->substream = substream;
    13211323#ifdef CONFIG_SND_CS46XX_NEW_DSP
    1322         down (&chip->spos_mutex);
     1324        mutex_lock(&chip->spos_mutex);
    13231325        cpcm->pcm_channel = NULL;
    13241326        cpcm->pcm_channel_id = pcm_channel_id;
     
    13291331                                   &hw_constraints_period_sizes);
    13301332
    1331         up (&chip->spos_mutex);
     1333        mutex_unlock(&chip->spos_mutex);
    13321334#else
    13331335        chip->playback_pcm = cpcm; /* HACK */
     
    13681370        snd_printdd("open raw iec958 channel\n");
    13691371
    1370         down (&chip->spos_mutex);
     1372        mutex_lock(&chip->spos_mutex);
    13711373        cs46xx_iec958_pre_open (chip);
    1372         up (&chip->spos_mutex);
     1374        mutex_unlock(&chip->spos_mutex);
    13731375
    13741376        return _cs46xx_playback_open_channel(substream,DSP_IEC958_CHANNEL);
     
    13861388        err = snd_cs46xx_playback_close(substream);
    13871389
    1388         down (&chip->spos_mutex);
     1390        mutex_lock(&chip->spos_mutex);
    13891391        cs46xx_iec958_post_close (chip);
    1390         up (&chip->spos_mutex);
     1392        mutex_unlock(&chip->spos_mutex);
    13911393
    13921394        return err;
     
    14291431
    14301432#ifdef CONFIG_SND_CS46XX_NEW_DSP
    1431         down (&chip->spos_mutex);
     1433        mutex_lock(&chip->spos_mutex);
    14321434        if (cpcm->pcm_channel) {
    14331435                cs46xx_dsp_destroy_pcm_channel(chip,cpcm->pcm_channel);
    14341436                cpcm->pcm_channel = NULL;
    14351437        }
    1436         up (&chip->spos_mutex);
     1438        mutex_unlock(&chip->spos_mutex);
    14371439#else
    14381440        chip->playback_pcm = NULL;
     
    18491851        switch (kcontrol->private_value) {
    18501852        case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT:
    1851                 down (&chip->spos_mutex);
     1853                mutex_lock(&chip->spos_mutex);
    18521854                change = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED);
    18531855                if (ucontrol->value.integer.value[0] && !change)
     
    18571859
    18581860                res = (change != (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED));
    1859                 up (&chip->spos_mutex);
     1861                mutex_unlock(&chip->spos_mutex);
    18601862                break;
    18611863        case CS46XX_MIXER_SPDIF_INPUT_ELEMENT:
     
    19982000        struct dsp_spos_instance * ins = chip->dsp_spos_instance;
    19992001
    2000         down (&chip->spos_mutex);
     2002        mutex_lock(&chip->spos_mutex);
    20012003        ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_default >> 24) & 0xff);
    20022004        ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_default >> 16) & 0xff);
    20032005        ucontrol->value.iec958.status[2] = 0;
    20042006        ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_default) & 0xff);
    2005         up (&chip->spos_mutex);
     2007        mutex_unlock(&chip->spos_mutex);
    20062008
    20072009        return 0;
     
    20162018        int change;
    20172019
    2018         down (&chip->spos_mutex);
     2020        mutex_lock(&chip->spos_mutex);
    20192021        val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) |
    20202022                ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[2]) << 16) |
     
    20302032                cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val);
    20312033
    2032         up (&chip->spos_mutex);
     2034        mutex_unlock(&chip->spos_mutex);
    20332035
    20342036        return change;
     
    20512053        struct dsp_spos_instance * ins = chip->dsp_spos_instance;
    20522054
    2053         down (&chip->spos_mutex);
     2055        mutex_lock(&chip->spos_mutex);
    20542056        ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_stream >> 24) & 0xff);
    20552057        ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_stream >> 16) & 0xff);
    20562058        ucontrol->value.iec958.status[2] = 0;
    20572059        ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_stream) & 0xff);
    2058         up (&chip->spos_mutex);
     2060        mutex_unlock(&chip->spos_mutex);
    20592061
    20602062        return 0;
     
    20692071        int change;
    20702072
    2071         down (&chip->spos_mutex);
     2073        mutex_lock(&chip->spos_mutex);
    20722074        val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) |
    20732075                ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[1]) << 16) |
     
    20832085                cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val);
    20842086
    2085         up (&chip->spos_mutex);
     2087        mutex_unlock(&chip->spos_mutex);
    20862088
    20872089        return change;
     
    23432345                snd_cs46xx_ac97_write(ac97,AC97_CSR_ACMODE,0x3);
    23442346        } else {
    2345                 snd_assert(0); /* should never happen ... */
     2347                snd_assert(0, return); /* should never happen ... */
    23462348        }
    23472349
     
    27482750#endif /* CONFIG_GAMEPORT */
    27492751
     2752#ifdef CONFIG_PROC_FS
    27502753/*
    27512754 *  proc interface
     
    27632766                size = region->size - pos;
    27642767        if (size > 0) {
    2765                 if (copy_to_user_fromio(buf, (char*)region->remap_addr + pos, size))
     2768                if (copy_to_user_fromio(buf, region->remap_addr + pos, size))
    27662769                        return -EFAULT;
    27672770        }
     
    28012804        return 0;
    28022805}
     2806#else /* !CONFIG_PROC_FS */
     2807#define snd_cs46xx_proc_init(card, chip)
     2808#define snd_cs46xx_proc_done(chip)
     2809#endif
    28032810
    28042811/*
     
    30373044                if (snd_cs46xx_peekBA0(chip, BA0_ACSTS) & ACSTS_CRDY)
    30383045                        goto ok1;
    3039                 msleep(10);
     3046                //msleep(10);
     3047                set_current_state(TASK_UNINTERRUPTIBLE);
     3048                schedule_timeout((HZ+99)/100);
    30403049        }
    30413050
     
    30863095                if ((snd_cs46xx_peekBA0(chip, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4))
    30873096                        goto ok2;
    3088                 msleep(10);
     3097                //msleep(10);
     3098                set_current_state(TASK_UNINTERRUPTIBLE);
     3099                schedule_timeout((HZ+99)/100);
    30893100        }
    30903101
     
    36613672        int amp_saved;
    36623673
    3663         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    36643674        snd_pcm_suspend_all(chip->pcm);
    36653675        // chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL);
     
    36783688        pci_disable_device(pci);
    36793689        pci_save_state(pci);
     3690        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    36803691        return 0;
    36813692}
     
    37153726                chip->active_ctrl(chip, -1); /* disable CLKRUN */
    37163727        chip->amplifier = amp_saved;
    3717         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     3728        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     3729        printk("CS46XX: resume\n");
    37183730        return 0;
    37193731}
     
    37443756                return err;
    37453757
    3746         chip = (struct snd_cs46xx *)kzalloc(sizeof(*chip), GFP_KERNEL);
     3758        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    37473759        if (chip == NULL) {
    37483760                pci_disable_device(pci);
     
    37513763        spin_lock_init(&chip->reg_lock);
    37523764#ifdef CONFIG_SND_CS46XX_NEW_DSP
    3753         init_MUTEX(&chip->spos_mutex);
     3765        mutex_init(&chip->spos_mutex);
    37543766#endif
    37553767        chip->card = card;
  • GPL/trunk/alsa-kernel/pci/cs46xx/cs46xx_lib.h

    r34 r76  
    6464
    6565        /*if (bank == 0) printk("snd_cs46xx_poke: %04X - %08X\n",reg >> 2,val); */
    66         writel(val, (char*)chip->region.idx[bank+1].remap_addr + offset);
     66        writel(val, chip->region.idx[bank+1].remap_addr + offset);
    6767}
    6868
     
    7171        unsigned int bank = reg >> 16;
    7272        unsigned int offset = reg & 0xffff;
    73         return readl((char*)chip->region.idx[bank+1].remap_addr + offset);
     73        return readl(chip->region.idx[bank+1].remap_addr + offset);
    7474}
    7575
    7676static inline void snd_cs46xx_pokeBA0(struct snd_cs46xx *chip, unsigned long offset, unsigned int val)
    7777{
    78         writel(val, (char*)chip->region.name.ba0.remap_addr + offset);
     78        writel(val, chip->region.name.ba0.remap_addr + offset);
    7979}
    8080
    8181static inline unsigned int snd_cs46xx_peekBA0(struct snd_cs46xx *chip, unsigned long offset)
    8282{
    83         return readl((char*)chip->region.name.ba0.remap_addr + offset);
     83        return readl(chip->region.name.ba0.remap_addr + offset);
    8484}
    8585
     
    8989struct dsp_symbol_entry *cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name,
    9090                                                   int symbol_type);
     91#ifdef CONFIG_PROC_FS
    9192int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip);
    9293int cs46xx_dsp_proc_done (struct snd_cs46xx *chip);
     94#else
     95#define cs46xx_dsp_proc_init(card, chip)
     96#define cs46xx_dsp_proc_done(chip)
     97#endif
    9398int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip);
    9499int snd_cs46xx_download (struct snd_cs46xx *chip, u32 *src, unsigned long offset,
     
    107112struct dsp_scb_descriptor * cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name,
    108113                                                   u32 * scb_data, u32 dest);
     114#ifdef CONFIG_PROC_FS
    109115void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb);
    110116void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,
    111117                                        struct dsp_scb_descriptor * scb);
     118#else
     119#define cs46xx_dsp_proc_free_scb_desc(scb)
     120#define cs46xx_dsp_proc_register_scb_desc(chip, scb)
     121#endif
    112122struct dsp_scb_descriptor * cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip);
    113123struct dsp_scb_descriptor *
  • GPL/trunk/alsa-kernel/pci/cs46xx/dsp_spos.c

    r34 r76  
    2929#include <linux/slab.h>
    3030#include <linux/vmalloc.h>
     31#include <linux/mutex.h>
     32
    3133#include <sound/core.h>
    3234#include <sound/control.h>
     
    234236        ins->symbol_table.highest_frag_index = 0;
    235237
    236         if (ins->symbol_table.symbols == NULL) {
    237                 cs46xx_dsp_spos_destroy(chip);
    238                 return NULL;
     238        if (ins->symbol_table.symbols == NULL) {
     239            cs46xx_dsp_spos_destroy(chip);
     240            goto error;
    239241        }
    240242
     
    244246
    245247        if (ins->code.data == NULL) {
    246                 cs46xx_dsp_spos_destroy(chip);
    247                 return NULL;
     248            cs46xx_dsp_spos_destroy(chip);
     249            goto error;
    248250        }
    249251
     
    255257
    256258        if (ins->modules == NULL) {
    257                 cs46xx_dsp_spos_destroy(chip);
    258                 return NULL;
     259            cs46xx_dsp_spos_destroy(chip);
     260            goto error;
    259261        }
    260262
     
    277279         /* byte 3 */   (unsigned int)_wrap_all_bits(  (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
    278280         /* left and right validity bits */ (1 << 13) | (1 << 12);
    279 
    280         return ins;
     281        return ins;
     282    error:
     283        kfree(ins);
     284        return NULL;
    281285}
    282286
     
    288292        snd_assert(ins != NULL, return);
    289293
    290         down(&chip->spos_mutex);
     294        mutex_lock(&chip->spos_mutex);
    291295        for (i = 0; i < ins->nscb; ++i) {
    292296                if (ins->scbs[i].deleted) continue;
     
    299303        kfree(ins->modules);
    300304        kfree(ins);
    301         up(&chip->spos_mutex);
     305        mutex_unlock(&chip->spos_mutex);
    302306}
    303307
     
    440444
    441445
     446#ifdef CONFIG_PROC_FS
    442447static struct dsp_symbol_entry *
    443448cs46xx_dsp_lookup_symbol_addr (struct snd_cs46xx * chip, u32 address, int symbol_type)
     
    497502        int i,j;
    498503
    499         down(&chip->spos_mutex);
     504        mutex_lock(&chip->spos_mutex);
    500505        snd_iprintf(buffer, "MODULES:\n");
    501506        for ( i = 0; i < ins->nmodules; ++i ) {
     
    510515                }
    511516        }
    512         up(&chip->spos_mutex);
     517        mutex_unlock(&chip->spos_mutex);
    513518}
    514519
     
    521526        void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
    522527
    523         down(&chip->spos_mutex);
     528        mutex_lock(&chip->spos_mutex);
    524529        snd_iprintf(buffer, "TASK TREES:\n");
    525530        for ( i = 0; i < ins->ntask; ++i) {
     
    538543
    539544        snd_iprintf(buffer,"\n"); 
    540         up(&chip->spos_mutex);
     545        mutex_unlock(&chip->spos_mutex);
    541546}
    542547
     
    548553        int i;
    549554
    550         down(&chip->spos_mutex);
     555        mutex_lock(&chip->spos_mutex);
    551556        snd_iprintf(buffer, "SCB's:\n");
    552557        for ( i = 0; i < ins->nscb; ++i) {
     
    571576
    572577        snd_iprintf(buffer,"\n");
    573         up(&chip->spos_mutex);
     578        mutex_unlock(&chip->spos_mutex);
    574579}
    575580
     
    852857        ins->proc_scb_info_entry = entry;
    853858
    854         down(&chip->spos_mutex);
     859        mutex_lock(&chip->spos_mutex);
    855860        /* register/update SCB's entries on proc */
    856861        for (i = 0; i < ins->nscb; ++i) {
     
    859864                cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i));
    860865        }
    861         up(&chip->spos_mutex);
     866        mutex_unlock(&chip->spos_mutex);
    862867
    863868        return 0;
     
    899904        }
    900905
    901         down(&chip->spos_mutex);
     906        mutex_lock(&chip->spos_mutex);
    902907        for (i = 0; i < ins->nscb; ++i) {
    903908                if (ins->scbs[i].deleted) continue;
    904909                cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
    905910        }
    906         up(&chip->spos_mutex);
     911        mutex_unlock(&chip->spos_mutex);
    907912
    908913        if (ins->proc_dsp_dir) {
     
    913918        return 0;
    914919}
     920#endif /* CONFIG_PROC_FS */
    915921
    916922static int debug_tree;
     
    13601366        valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);
    13611367
    1362         snd_assert (chip->nr_ac97_codecs == 1 || chip->nr_ac97_codecs == 2);
     1368        snd_assert (chip->nr_ac97_codecs == 1 || chip->nr_ac97_codecs == 2, return -ENXIO);
    13631369
    13641370        if (chip->nr_ac97_codecs == 1) {
     
    15101516                        /* 8 */ 0,
    15111517                        /* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR,
    1512                         /* A */ spdifo_task->address,
     1518                        /* A */ /*spdifo_task->address*/0,
    15131519                        SPDIFO_SCB_INST + SPDIFOFIFOPointer,
    15141520                        {
     
    15191525                        /* E */ 0x0108,0x0001,                                    /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
    15201526                        /* F */ DSP_SPOS_UUUU                                     /* SPDIFOFree; */
    1521                 };
     1527                };
    15221528
    15231529                /* 0xBB0 */
     
    15331539                        /* 8 */ DSP_SPOS_UUUU,  /* TempStatus */
    15341540                        /* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR,
    1535                         /* A */ spdifi_task->address,
     1541                        /* A */ /*spdifi_task->address*/0,
    15361542                        SPDIFI_SCB_INST + SPDIFIFIFOPointer,
    15371543                        /* NOTE: The SPDIF input task write the sample in mono
     
    15441550                        /* E */ 0x01f0,0x0001,
    15451551                        /* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */
    1546                 };
     1552                };
    15471553
    15481554                /* 0xBA0 */
     
    15581564                        /* 8 */ DSP_SPOS_UUUU,
    15591565                        /* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR,
    1560                         /* A */ s16_async_codec_input_task->address,
     1566                        /* A */ /*s16_async_codec_input_task->address*/0,
    15611567                        HFG_TREE_SCB + AsyncCIOFIFOPointer,
    15621568             
     
    15961602                           the output buffer of this task */
    15971603                        /* F */ 0, /* DSP_SPOS_UUUU */
    1598                 };
     1604                };
     1605
     1606                spdifo_scb.entry_point = spdifo_task->address;
     1607                spdifi_scb.entry_point = spdifi_task->address;
     1608                async_codec_input_scb.io_entry_point =
     1609                    s16_async_codec_input_task->address;
    15991610
    16001611                spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);
     
    16931704        snd_assert (ins->spdif_in_src != NULL,return -EINVAL);
    16941705
    1695         down(&chip->spos_mutex);
     1706        mutex_lock(&chip->spos_mutex);
    16961707
    16971708        if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) {
     
    17371748        /* monitor state */
    17381749        ins->spdif_status_in = 1;
    1739         up(&chip->spos_mutex);
     1750        mutex_unlock(&chip->spos_mutex);
    17401751
    17411752        return 0;
     
    17491760        snd_assert (ins->spdif_in_src != NULL,return -EINVAL); 
    17501761
    1751         down(&chip->spos_mutex);
     1762        mutex_lock(&chip->spos_mutex);
    17521763
    17531764        /* Remove the asynchronous receiver SCB */
     
    17591770        /* monitor state */
    17601771        ins->spdif_status_in = 0;
    1761         up(&chip->spos_mutex);
     1772        mutex_unlock(&chip->spos_mutex);
    17621773
    17631774        /* restore amplifier */
     
    17751786        snd_assert (ins->ref_snoop_scb != NULL,return -EINVAL);
    17761787
    1777         down(&chip->spos_mutex);
     1788        mutex_lock(&chip->spos_mutex);
    17781789        ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
    17791790                                                  "PCMSerialInput_Wave");
    1780         up(&chip->spos_mutex);
     1791        mutex_unlock(&chip->spos_mutex);
    17811792
    17821793        return 0;
     
    17891800        snd_assert (ins->pcm_input != NULL,return -EINVAL);
    17901801
    1791         down(&chip->spos_mutex);
     1802        mutex_lock(&chip->spos_mutex);
    17921803        cs46xx_dsp_remove_scb (chip,ins->pcm_input);
    17931804        ins->pcm_input = NULL;
    1794         up(&chip->spos_mutex);
     1805        mutex_unlock(&chip->spos_mutex);
    17951806
    17961807        return 0;
     
    18041815        snd_assert (ins->codec_in_scb != NULL,return -EINVAL);
    18051816
    1806         down(&chip->spos_mutex);
     1817        mutex_lock(&chip->spos_mutex);
    18071818        ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
    18081819                                                  "PCMSerialInput_ADC");
    1809         up(&chip->spos_mutex);
     1820        mutex_unlock(&chip->spos_mutex);
    18101821
    18111822        return 0;
     
    18181829        snd_assert (ins->adc_input != NULL,return -EINVAL);
    18191830
    1820         down(&chip->spos_mutex);
     1831        mutex_lock(&chip->spos_mutex);
    18211832        cs46xx_dsp_remove_scb (chip,ins->adc_input);
    18221833        ins->adc_input = NULL;
    1823         up(&chip->spos_mutex);
     1834        mutex_unlock(&chip->spos_mutex);
    18241835
    18251836        return 0;
     
    18681879        struct dsp_scb_descriptor * scb;
    18691880
    1870         down(&chip->spos_mutex);
     1881        mutex_lock(&chip->spos_mutex);
    18711882       
    18721883        /* main output */
     
    18871898        ins->dac_volume_right = right;
    18881899
    1889         up(&chip->spos_mutex);
     1900        mutex_unlock(&chip->spos_mutex);
    18901901
    18911902        return 0;
     
    18961907        struct dsp_spos_instance * ins = chip->dsp_spos_instance;
    18971908
    1898         down(&chip->spos_mutex);
     1909        mutex_lock(&chip->spos_mutex);
    18991910
    19001911        if (ins->asynch_rx_scb != NULL)
     
    19051916        ins->spdif_input_volume_right = right;
    19061917
    1907         up(&chip->spos_mutex);
     1918        mutex_unlock(&chip->spos_mutex);
    19081919
    19091920        return 0;
  • GPL/trunk/alsa-kernel/pci/cs46xx/dsp_spos_scb_lib.c

    r34 r76  
    2929#include <linux/init.h>
    3030#include <linux/slab.h>
     31#include <linux/mutex.h>
     32
    3133#include <sound/core.h>
    3234#include <sound/control.h>
     
    6567}
    6668
     69#ifdef CONFIG_PROC_FS
    6770static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,
    6871                                           struct snd_info_buffer *buffer)
     
    7780        ins = chip->dsp_spos_instance;
    7881
    79         down(&chip->spos_mutex);
     82        mutex_lock(&chip->spos_mutex);
    8083        snd_iprintf(buffer,"%04x %s:\n",scb->address,scb->scb_name);
    8184
     
    105108
    106109        snd_iprintf(buffer,"index [%d] ref_count [%d]\n",scb->index,scb->ref_count); 
    107         up(&chip->spos_mutex);
    108 }
     110        mutex_unlock(&chip->spos_mutex);
     111}
     112#endif
    109113
    110114static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
     
    221225
    222226
     227#ifdef CONFIG_PROC_FS
    223228void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb)
    224229{
     
    276281        }
    277282}
     283#endif /* CONFIG_PROC_FS */
    278284
    279285static struct dsp_scb_descriptor *
     
    425431                0,                      /* COstrmRsConfig */
    426432                0,                      /* COstrmBufPtr */
    427                 channel_disp,fifo_addr, /* leftChanBaseIOaddr:rightChanIOdisp */
     433                /*channel_disp*/0,/*fifo_addr*/0, /* leftChanBaseIOaddr:rightChanIOdisp */
    428434                0x0000,0x0080,          /* (!AC97!) COexpVolChangeRate:COscaleShiftCount */
    429                 0,child_scb_addr        /* COreserved - need child scb to work with rom code */
    430         };
    431  
    432  
     435                0,/*child_scb_addr*/0        /* COreserved - need child scb to work with rom code */
     436        };
     437
     438        codec_out_scb.left_chan_base_IO_addr = channel_disp;
     439        codec_out_scb.right_chan_IO_disp = fifo_addr;
     440        codec_out_scb.last_sub_ptr = child_scb_addr;
     441
    433442        scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_out_scb,
    434443                                            dest,"S16_CODECOUTPUTTASK",parent_scb,
     
    468477
    469478                RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,  /* strmRsConfig */
    470                 sample_buffer_addr << 0x10,       /* strmBufPtr; defined as a dword ptr, used as a byte ptr */
    471                 channel_disp,fifo_addr,           /* (!AC97!) leftChanBaseINaddr=AC97primary
     479                /*sample_buffer_addr << 0x10*/0,       /* strmBufPtr; defined as a dword ptr, used as a byte ptr */
     480                /*channel_disp*/0,/*fifo_addr*/0,           /* (!AC97!) leftChanBaseINaddr=AC97primary
    472481                                                     link input slot 3 :rightChanINdisp=""slot 4 */
    473482                0x0000,0x0000,                    /* (!AC97!) ????:scaleShiftCount; no shift needed
     
    475484                0x80008000                        /* ??clw cwcgame.scb has 0 */
    476485        };
    477  
     486
     487        codec_input_scb.strm_buf_ptr = sample_buffer_addr << 0x10;
     488        codec_input_scb.rightChanINdisp = channel_disp;
     489        codec_input_scb.left_chan_base_IN_addr = fifo_addr;
     490
    478491        scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_input_scb,
    479492                                            dest,"S16_CODECINPUTTASK",parent_scb,
     
    546559                NULL_SCB_ADDR,NULL_SCB_ADDR,
    547560                /* Pointer to this tasks parameter block & stream function pointer */
    548                 0,NULL_SCB_ADDR,
     561                0,NULL_SCB_ADDR,
     562#ifndef TARGET_OS2
    549563                /* rsConfig register for stream buffer (rsDMA reg. is loaded from basicReq.daw */
    550564                /*   for incoming streams, or basicReq.saw, for outgoing streams) */
     
    554568                ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) + /* stream number = SCBaddr/16 */
    555569                RSCONFIG_SAMPLE_16STEREO +
    556                 RSCONFIG_MODULO_32,             /* dest buffer(PCMreaderBuf) is 32 dwords (256 bytes) */
     570                RSCONFIG_MODULO_32,             /* dest buffer(PCMreaderBuf) is 32 dwords (256 bytes) */
     571#else
     572                0,
     573#endif
    557574                /* Stream sample pointer & MAC-unit mode for this stream */
    558                 (sample_buffer_addr << 0x10),
     575                /*(sample_buffer_addr << 0x10)*/0,
    559576                /* Fractional increment per output sample in the input sample buffer */
    560577                0,
     
    565582                        0xffff,0xffff
    566583                }
    567         };
     584        };
     585
     586        pcm_reader_scb.strm_rs_config = RSCONFIG_DMA_ENABLE +
     587            (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) +
     588            ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) +
     589            RSCONFIG_SAMPLE_16STEREO +
     590            RSCONFIG_MODULO_32;
     591        pcm_reader_scb.strm_buf_ptr = sample_buffer_addr << 0x10;
    568592
    569593        if (ins->null_algorithm == NULL) {
     
    672696                        /* wont work with any other rate than
    673697                           the native DSP rate */
    674                         snd_assert (rate = 48000);
     698                        snd_assert (rate == 48000, return NULL);
    675699
    676700                        scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
     
    12431267        case DSP_PCM_S71_CHANNEL:
    12441268                /* TODO */
    1245                 snd_assert(0);
     1269                snd_assert(0, return NULL);
    12461270                break;
    12471271        case DSP_IEC958_CHANNEL:
     
    12591283                break;
    12601284        default:
    1261                 snd_assert (0);
     1285                snd_assert (0, return NULL);
    12621286                return NULL;
    12631287        }
     
    13161340                }
    13171341
    1318                 sprintf (scb_name,"SrcTask_SCB%d",src_index);
     1342                snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index);
    13191343               
    13201344                snd_printdd( "dsp_spos: creating SRC \"%s\"\n",scb_name);
     
    13401364 
    13411365 
    1342         sprintf (scb_name,"PCMReader_SCB%d",pcm_index);
     1366        snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index);
    13431367
    13441368        snd_printdd( "dsp_spos: creating PCM \"%s\" (%d)\n",scb_name,
  • GPL/trunk/alsa-kernel/pci/cs46xx/makefile.os2

    r32 r76  
    33
    44CDEFINES = -D__KERNEL__ -DMODULE -dTARGET_OS2 -dALSA_BUILD -D__ISAPNP__ -DCONFIG_ISAPNP -D__i386_
    5 #-dCONFIG_SND_CS46XX_NEW_DSP
     5#-DCONFIG_SND_CS46XX_NEW_DSP
    66
    7732BIT=1
     
    1414#
    1515#===================================================================
    16 FILE1    = cs46xx.obj cs46xx_lib.obj
    17 ##dsp_spos.obj dsp_spos_scb_lib.obj
    18 FILE2    =
     16FILE1    = cs46xx.obj cs46xx_lib.obj
     17#FILE2    = dsp_spos.obj dsp_spos_scb_lib.obj
    1918FILE3    =
    2019FILE4    =
  • GPL/trunk/alsa-kernel/pci/es1968.c

    r32 r76  
    18171817    offset &= 0xfffe;
    18181818    offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2);
    1819 
     1819#if 0 /* vladest patch baseg on r.ihle suggestion */
    18201820    t = stop_time.tv_sec - start_time.tv_sec;
    18211821    t *= 1000000;
     
    18241824    else
    18251825        t += stop_time.tv_usec - start_time.tv_usec;
     1826#else
     1827    t = 50000;
     1828#endif
    18261829    if (t == 0) {
    18271830        snd_printk("?? calculation error..\n");
  • GPL/trunk/alsa-kernel/pci/hda/hda_codec.c

    r69 r76  
    530530        bus->caddr_tbl[codec_addr] = codec;
    531531
    532         codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID);
     532        codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID);
     533        if (codec->vendor_id == -1)
     534            /* read again, hopefully the access method was corrected
     535             * in the last read...
     536             */
     537            codec->vendor_id = snd_hda_param_read(codec, AC_NODE_ROOT,
     538                                                  AC_PAR_VENDOR_ID);
    533539        codec->subsystem_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID);
    534540        codec->revision_id = snd_hda_param_read(codec, AC_NODE_ROOT, AC_PAR_REV_ID);
     
    723729 * read AMP value.  The volume is between 0 to 0x7f, 0x80 = mute bit.
    724730 */
    725 static int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, int direction, int index)
     731int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
     732                           int direction, int index)
    726733{
    727734        struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, index));
     
    734741 * update the AMP value, mask = bit mask to set, val = the value
    735742 */
    736 static int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int direction, int idx, int mask, int val)
     743int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
     744                             int direction, int idx, int mask, int val)
    737745{
    738746        struct hda_amp_info *info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
     
    863871                change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
    864872                                                   0x80, *valp ? 0 : 0x80);
    865        
     873
    866874        return change;
    867875}
     
    18901898        if (mout->hp_nid)
    18911899                /* headphone out will just decode front left/right (stereo) */
    1892                 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format);
     1900            snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format);
     1901        /* extra outputs copied from front */
     1902        for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
     1903            if (mout->extra_out_nid[i])
     1904                snd_hda_codec_setup_stream(codec,
     1905                                           mout->extra_out_nid[i],
     1906                                           stream_tag, 0, format);
     1907
    18931908        /* surrounds */
    18941909        for (i = 1; i < mout->num_dacs; i++) {
     
    19141929                snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
    19151930        if (mout->hp_nid)
    1916                 snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0);
     1931            snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0);
     1932        for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
     1933            if (mout->extra_out_nid[i])
     1934                snd_hda_codec_setup_stream(codec,
     1935                                           mout->extra_out_nid[i],
     1936                                           0, 0, 0);
    19171937        down(&codec->spdif_mutex);
    19181938        if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
     
    19361956}
    19371957
    1938 /* parse all pin widgets and store the useful pin nids to cfg */
     1958/*
     1959 * Parse all pin widgets and store the useful pin nids to cfg
     1960 *
     1961 * The number of line-outs or any primary output is stored in line_outs,
     1962 * and the corresponding output pins are assigned to line_out_pins[],
     1963 * in the order of front, rear, CLFE, side, ...
     1964 *
     1965 * If more extra outputs (speaker and headphone) are found, the pins are
     1966 * assisnged to hp_pin and speaker_pins[], respectively.  If no line-out jack
     1967 * is detected, one of speaker of HP pins is assigned as the primary
     1968 * output, i.e. to line_out_pins[0].  So, line_outs is always positive
     1969 * if any analog output exists.
     1970 *
     1971 * The analog input pins are assigned to input_pins array.
     1972 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
     1973 * respectively.
     1974 */
    19391975int snd_hda_parse_pin_def_config(struct hda_codec *codec, struct auto_pin_cfg *cfg,
    19401976                                 hda_nid_t *ignore_nids)
    19411977{
    19421978        hda_nid_t nid, nid_start;
    1943         int i, j, nodes;
    1944         short seq, sequences[4], assoc_line_out;
     1979        int i, j, nodes;
     1980        short seq, assoc_line_out, sequences[ARRAY_SIZE(cfg->line_out_pins)];
    19451981
    19461982        memset(cfg, 0, sizeof(*cfg));
     
    19832019                        cfg->line_outs++;
    19842020                        break;
    1985                 case AC_JACK_SPEAKER:
    1986                         cfg->speaker_pin = nid;
    1987                         break;
     2021                case AC_JACK_SPEAKER:
     2022                    if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
     2023                        continue;
     2024                    cfg->speaker_pins[cfg->speaker_outs] = nid;
     2025                    cfg->speaker_outs++;
     2026                    break;
    19882027                case AC_JACK_HP_OUT:
    19892028                        cfg->hp_pin = nid;
     
    20482087                break;
    20492088        }
     2089        /*
     2090         * debug prints of the parsed results
     2091         */
     2092        snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
     2093                   cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
     2094                   cfg->line_out_pins[2], cfg->line_out_pins[3],
     2095                   cfg->line_out_pins[4]);
     2096        snd_printd("   speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
     2097                   cfg->speaker_outs, cfg->speaker_pins[0],
     2098                   cfg->speaker_pins[1], cfg->speaker_pins[2],
     2099                   cfg->speaker_pins[3], cfg->speaker_pins[4]);
     2100        snd_printd("   hp=0x%x, dig_out=0x%x, din_in=0x%x\n",
     2101                   cfg->hp_pin, cfg->dig_out_pin, cfg->dig_in_pin);
     2102        snd_printd("   inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
     2103                   " cd=0x%x, aux=0x%x\n",
     2104                   cfg->input_pins[AUTO_PIN_MIC],
     2105                   cfg->input_pins[AUTO_PIN_FRONT_MIC],
     2106                   cfg->input_pins[AUTO_PIN_LINE],
     2107                   cfg->input_pins[AUTO_PIN_FRONT_LINE],
     2108                   cfg->input_pins[AUTO_PIN_CD],
     2109                   cfg->input_pins[AUTO_PIN_AUX]);
     2110
     2111        /*
     2112         * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
     2113         * as a primary output
     2114         */
     2115        if (! cfg->line_outs) {
     2116            if (cfg->speaker_outs) {
     2117                cfg->line_outs = cfg->speaker_outs;
     2118                memcpy(cfg->line_out_pins, cfg->speaker_pins,
     2119                       sizeof(cfg->speaker_pins));
     2120                cfg->speaker_outs = 0;
     2121                memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
     2122            } else if (cfg->hp_pin) {
     2123                cfg->line_outs = 1;
     2124                cfg->line_out_pins[0] = cfg->hp_pin;
     2125                cfg->hp_pin = 0;
     2126            }
     2127        }
    20502128
    20512129        return 0;
  • GPL/trunk/alsa-kernel/pci/hda/hda_generic.c

    r69 r76  
    4848/* patch-specific record */
    4949struct hda_gspec {
    50         struct hda_gnode *dac_node;     /* DAC node */
    51         struct hda_gnode *out_pin_node; /* Output pin (Line-Out) node */
    52         struct hda_gnode *pcm_vol_node; /* Node for PCM volume */
    53         unsigned int pcm_vol_index;     /* connection of PCM volume */
     50    struct hda_gnode *dac_node[2];  /* DAC node */
     51    struct hda_gnode *out_pin_node[2];      /* Output pin (Line-Out) node */
     52    struct hda_gnode *pcm_vol_node[2];      /* Node for PCM volume */
     53    unsigned int pcm_vol_index[2];  /* connection of PCM volume */
    5454
    5555        struct hda_gnode *adc_node;     /* ADC node */
     
    7070 * retrieve the default device type from the default config value
    7171 */
    72 #define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
    73 #define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
    74 
     72#define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> \
     73    AC_DEFCFG_DEVICE_SHIFT)
     74#define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> \
     75    AC_DEFCFG_LOCATION_SHIFT)
     76#define defcfg_port_conn(node) (((node)->def_cfg & AC_DEFCFG_PORT_CONN) >> \
     77    AC_DEFCFG_PORT_CONN_SHIFT)
    7578/*
    7679 * destructor
     
    262265 */
    263266static int parse_output_path(struct hda_codec *codec, struct hda_gspec *spec,
    264                              struct hda_gnode *node)
     267                             struct hda_gnode *node, int dac_idx)
    265268{
    266269        int i, err;
     
    276279                        return 0;
    277280                }
    278                 snd_printdd("AUD_OUT found %x\n", node->nid);
    279                 if (spec->dac_node) {
    280                         /* already DAC node is assigned, just unmute & connect */
    281                         return node == spec->dac_node;
    282                 }
    283                 spec->dac_node = node;
    284                 if (node->wid_caps & AC_WCAP_OUT_AMP) {
    285                         spec->pcm_vol_node = node;
    286                         spec->pcm_vol_index = 0;
     281                snd_printdd("AUD_OUT found %x\n", node->nid);
     282                if (spec->dac_node[dac_idx]) {
     283                    /* already DAC node is assigned, just unmute & connect */
     284                    return node == spec->dac_node[dac_idx];
     285                }
     286                spec->dac_node[dac_idx] = node;
     287                if (node->wid_caps & AC_WCAP_OUT_AMP) {
     288                    spec->pcm_vol_node[dac_idx] = node;
     289                    spec->pcm_vol_index[dac_idx] = 0;
    287290                }
    288291                return 1; /* found */
     
    292295                child = hda_get_node(spec, node->conn_list[i]);
    293296                if (! child)
    294                         continue;
    295                 err = parse_output_path(codec, spec, child);
     297                    continue;
     298                err = parse_output_path(codec, spec, child, dac_idx);
    296299                if (err < 0)
    297300                        return err;
     
    303306                                select_input_connection(codec, node, i);
    304307                        unmute_input(codec, node, i);
    305                         unmute_output(codec, node);
    306                         if (! spec->pcm_vol_node) {
    307                                 if (node->wid_caps & AC_WCAP_IN_AMP) {
    308                                         spec->pcm_vol_node = node;
    309                                         spec->pcm_vol_index = i;
    310                                 } else if (node->wid_caps & AC_WCAP_OUT_AMP) {
    311                                         spec->pcm_vol_node = node;
    312                                         spec->pcm_vol_index = 0;
    313                                 }
     308                        unmute_output(codec, node);
     309                        if (! spec->pcm_vol_node[dac_idx]) {
     310                            if (node->wid_caps & AC_WCAP_IN_AMP) {
     311                                spec->pcm_vol_node[dac_idx] = node;
     312                                spec->pcm_vol_index[dac_idx] = i;
     313                            } else if (node->wid_caps & AC_WCAP_OUT_AMP) {
     314                                spec->pcm_vol_node[dac_idx] = node;
     315                                spec->pcm_vol_index[dac_idx] = 0;
     316                            }
    314317                        }
    315318                        return 1;
     
    339342                /* output capable? */
    340343                if (! (node->pin_caps & AC_PINCAP_OUT))
    341                         continue;
     344                    continue;
     345                if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
     346                    continue; /* unconnected */
    342347                if (jack_type >= 0) {
    343348                        if (jack_type != defcfg_type(node))
     
    350355                                continue;
    351356                }
    352                 clear_check_flags(spec);
    353                 err = parse_output_path(codec, spec, node);
     357                clear_check_flags(spec);
     358                err = parse_output_path(codec, spec, node, 0);
    354359                if (err < 0)
    355                         return NULL;
    356                 else if (err > 0) {
     360                    return NULL;
     361                if (! err && spec->out_pin_node[0]) {
     362                    err = parse_output_path(codec, spec, node, 1);
     363                    if (err < 0)
     364                        return NULL;
     365                }
     366                if (err > 0) {
    357367                        /* unmute the PIN output */
    358368                        unmute_output(codec, node);
     
    381391        /* first, look for the line-out pin */
    382392        node = parse_output_jack(codec, spec, AC_JACK_LINE_OUT);
    383         if (node) /* found, remember the PIN node */
    384                 spec->out_pin_node = node;
     393        if (node) /* found, remember the PIN node */
     394            spec->out_pin_node[0] = node;
     395        else {
     396            /* if no line-out is found, try speaker out */
     397            node = parse_output_jack(codec, spec, AC_JACK_SPEAKER);
     398            if (node)
     399                spec->out_pin_node[0] = node;
     400        }
    385401        /* look for the HP-out pin */
    386402        node = parse_output_jack(codec, spec, AC_JACK_HP_OUT);
    387         if (node) {
    388                 if (! spec->out_pin_node)
    389                         spec->out_pin_node = node;
    390         }
    391 
    392         if (! spec->out_pin_node) {
     403        if (node) {
     404            if (! spec->out_pin_node[0])
     405                spec->out_pin_node[0] = node;
     406            else
     407                spec->out_pin_node[1] = node;
     408        }
     409
     410        if (! spec->out_pin_node[0]) {
    393411                /* no line-out or HP pins found,
    394412                 * then choose for the first output pin
    395                 */
    396                 spec->out_pin_node = parse_output_jack(codec, spec, -1);
    397                 if (! spec->out_pin_node)
    398                         snd_printd("hda_generic: no proper output path found\n");
     413                */
     414            spec->out_pin_node[0] = parse_output_jack(codec, spec, -1);
     415            if (! spec->out_pin_node[0])
     416                snd_printd("hda_generic: no proper output path found\n");
    399417        }
    400418
     
    506524                return 0;
    507525
    508         if (node->wid_caps & AC_WCAP_DIGITAL)
     526        if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
     527            return 0; /* unconnected */
     528
     529        if (node->wid_caps & AC_WCAP_DIGITAL)
    509530                return 0; /* skip SPDIF */
    510531
     
    549570        // awk added - fixed no recording due to muted widget
    550571        unmute_input(codec, adc_node, 0);
    551        
     572
    552573        /*
    553574         * check each connection of the ADC
     
    732753{
    733754        struct hda_gspec *spec = codec->spec;
    734         int err;
    735 
    736         err = create_mixer(codec, spec->pcm_vol_node, spec->pcm_vol_index,
    737                            "PCM", "Playback");
    738         if (err < 0)
    739                 return err;
     755        static const char *types[2] = { "Master", "Headphone" };
     756        int i, err;
     757
     758        for (i = 0; i < 2 && spec->pcm_vol_node[i]; i++) {
     759            err = create_mixer(codec, spec->pcm_vol_node[i],
     760                               spec->pcm_vol_index[i],
     761                               types[i], "Playback");
     762            if (err < 0)
     763                return err;
     764        }
    740765        return 0;
    741766}
     
    834859        const char *type;
    835860
    836         if (! spec->out_pin_node)
     861        if (! spec->out_pin_node[0])
    837862                return 0;
    838863
     
    848873                        if (check_existing_control(codec, type, "Playback"))
    849874                                continue;
    850                         clear_check_flags(spec);
    851                         err = parse_loopback_path(codec, spec, spec->out_pin_node,
     875                        clear_check_flags(spec);
     876                        err = parse_loopback_path(codec, spec,
     877                                                  spec->out_pin_node[0],
    852878                                                  node, type);
    853879                        if (err < 0)
     
    884910};
    885911
     912static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo,
     913                                struct hda_codec *codec,
     914                                unsigned int stream_tag,
     915                                unsigned int format,
     916                                struct snd_pcm_substream *substream)
     917{
     918    struct hda_gspec *spec = codec->spec;
     919
     920    snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
     921    snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid,
     922                               stream_tag, 0, format);
     923    return 0;
     924}
     925
     926static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
     927                                struct hda_codec *codec,
     928                                struct snd_pcm_substream *substream)
     929{
     930    struct hda_gspec *spec = codec->spec;
     931
     932    snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0);
     933    snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0);
     934    return 0;
     935}
     936
    886937static int build_generic_pcms(struct hda_codec *codec)
    887938{
     
    889940        struct hda_pcm *info = &spec->pcm_rec;
    890941
    891         if (! spec->dac_node && ! spec->adc_node) {
     942        if (! spec->dac_node[0] && ! spec->adc_node) {
    892943                snd_printd("hda_generic: no PCM found\n");
    893944                return 0;
     
    897948        codec->pcm_info = info;
    898949
    899         info->name = "HDA Generic";
    900         if (spec->dac_node) {
    901                 info->stream[0] = generic_pcm_playback;
    902                 info->stream[0].nid = spec->dac_node->nid;
     950        info->name = "HDA Generic";
     951        if (spec->dac_node[0]) {
     952            info->stream[0] = generic_pcm_playback;
     953            info->stream[0].nid = spec->dac_node[0]->nid;
     954            if (spec->dac_node[1]) {
     955                info->stream[0].ops.prepare = generic_pcm2_prepare;
     956                info->stream[0].ops.cleanup = generic_pcm2_cleanup;
     957            }
    903958        }
    904959        if (spec->adc_node) {
  • GPL/trunk/alsa-kernel/pci/hda/hda_intel.c

    r69 r76  
    3131 *
    3232 *  2004.12.01  Major rewrite by tiwai, merged the work of pshou
    33  * 
     33 *
    3434 */
    3535
     
    104104#define ICH6_REG_INTSTS                 0x24
    105105#define ICH6_REG_WALCLK                 0x30
    106 #define ICH6_REG_SYNC                   0x34   
     106#define ICH6_REG_SYNC                   0x34
    107107#define ICH6_REG_CORBLBASE              0x40
    108108#define ICH6_REG_CORBUBASE              0x44
     
    250250        unsigned int frags;             /* number for period in the play buffer */
    251251        unsigned int fifo_size;         /* FIFO size */
    252         unsigned int last_pos;          /* last updated period position */
    253252
    254253        void __iomem *sd_addr;          /* stream descriptor pointer */
     
    260259        unsigned int format_val;        /* format value to be set in the controller and the codec */
    261260        unsigned char stream_tag;       /* assigned stream */
    262         unsigned char index;            /* stream index */
     261        unsigned char index;            /* stream index */
     262        /* for sanity check of position buffer */
     263        unsigned int period_intr;
    263264
    264265        unsigned int opened: 1;
    265266        unsigned int running: 1;
    266         unsigned int period_updating: 1;
    267267};
    268268
     
    446446
    447447/* send a command */
    448 static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
     448static int azx_corb_send_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
    449449                        unsigned int verb, unsigned int para)
    450450{
     
    485485                return;
    486486        chip->rirb.wp = wp;
    487                
     487
    488488        while (chip->rirb.rp != wp) {
    489489                chip->rirb.rp++;
     
    503503
    504504/* receive a response */
    505 static unsigned int azx_get_response(struct hda_codec *codec)
     505static unsigned int azx_rirb_get_response(struct hda_codec *codec)
    506506{
    507507        struct azx *chip = codec->bus->private_data;
     
    509509
    510510        while (chip->rirb.cmds) {
    511                 if (! --timeout) {
    512                         if (printk_ratelimit())
    513                                 snd_printk(KERN_ERR
    514                                         "azx_get_response timeout\n");
    515                         chip->rirb.rp = azx_readb(chip, RIRBWP);
    516                         chip->rirb.cmds = 0;
    517                         return -1;
    518                 }
    519                 msleep(1);
     511            if (! --timeout) {
     512                snd_printk(KERN_ERR
     513                           "hda_intel: azx_get_response timeout, "
     514                           "switching to single_cmd mode...\n");
     515                chip->rirb.rp = azx_readb(chip, RIRBWP);
     516                chip->rirb.cmds = 0;
     517                /* switch to single_cmd mode */
     518                chip->single_cmd = 1;
     519                azx_free_cmd_io(chip);
     520                return -1;
     521            }
     522            msleep(1);
    520523        }
    521524        return chip->rirb.res; /* the last value */
     
    578581}
    579582
     583/*
     584 * The below are the main callbacks from hda_codec.
     585 *
     586 * They are just the skeleton to call sub-callbacks according to the
     587 * current setting of chip->single_cmd.
     588 */
     589
     590/* send a command */
     591static int azx_send_cmd(struct hda_codec *codec, hda_nid_t nid,
     592                        int direct, unsigned int verb,
     593                        unsigned int para)
     594{
     595    struct azx *chip = codec->bus->private_data;
     596    if (chip->single_cmd)
     597        return azx_single_send_cmd(codec, nid, direct, verb, para);
     598    else
     599        return azx_corb_send_cmd(codec, nid, direct, verb, para);
     600}
     601
     602/* get a response */
     603static unsigned int azx_get_response(struct hda_codec *codec)
     604{
     605    struct azx *chip = codec->bus->private_data;
     606    if (chip->single_cmd)
     607        return azx_single_get_response(codec);
     608    else
     609        return azx_rirb_get_response(codec);
     610}
     611
     612
    580613/* reset codec link */
    581614static int azx_reset(struct azx *chip)
     
    626659/*
    627660 * Lowlevel interface
    628  */ 
     661 */
    629662
    630663/* enable interrupts */
     
    733766        case AZX_DRIVER_ATI:
    734767                /* For ATI SB450 azalia HD audio, we need to enable snoop */
    735                 pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 
     768                pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
    736769                                     &reg);
    737                 pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 
     770                pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
    738771                                      (reg & 0xf8) | ATI_SB450_HDAUDIO_ENABLE_SNOOP);
    739772                break;
     
    765798                return IRQ_NONE;
    766799        }
    767        
     800
    768801        for (i = 0; i < chip->num_streams; i++) {
    769802                azx_dev = &chip->azx_dev[i];
    770803                if (status & azx_dev->sd_int_sta_mask) {
    771804                        azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
    772                         if (azx_dev->substream && azx_dev->running) {
    773                                 azx_dev->period_updating = 1;
     805                        if (azx_dev->substream && azx_dev->running) {
     806                            azx_dev->period_intr++;
    774807                                spin_unlock(&chip->reg_lock);
    775808                                snd_pcm_period_elapsed(azx_dev->substream);
    776809                                spin_lock(&chip->reg_lock);
    777                                 azx_dev->period_updating = 0;
    778810                        }
    779811                }
     
    794826#endif
    795827        spin_unlock(&chip->reg_lock);
    796        
     828
    797829        return IRQ_HANDLED;
    798830}
     
    899931        bus_temp.private_data = chip;
    900932        bus_temp.modelname = model;
    901         bus_temp.pci = chip->pci;
    902         if (chip->single_cmd) {
    903                 bus_temp.ops.command = azx_single_send_cmd;
    904                 bus_temp.ops.get_response = azx_single_get_response;
    905         } else {
    906                 bus_temp.ops.command = azx_send_cmd;
    907                 bus_temp.ops.get_response = azx_get_response;
    908         }
     933        bus_temp.pci = chip->pci;
     934        bus_temp.ops.command = azx_send_cmd;
     935        bus_temp.ops.get_response = azx_get_response;
    909936
    910937        if ((err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus)) < 0)
     
    10911118        else
    10921119                azx_dev->fifo_size = 0;
    1093         azx_dev->last_pos = 0;
    10941120
    10951121        return hinfo->ops.prepare(hinfo, apcm->codec, azx_dev->stream_tag,
     
    11391165        unsigned int pos;
    11401166
    1141         if (chip->position_fix == POS_FIX_POSBUF) {
     1167        if (chip->position_fix == POS_FIX_POSBUF ||
     1168            chip->position_fix == POS_FIX_AUTO) {
    11421169                /* use the position buffer */
    1143                 pos = *azx_dev->posbuf;
    1144         } else {
     1170            pos = *azx_dev->posbuf;
     1171            if (chip->position_fix == POS_FIX_AUTO &&
     1172                azx_dev->period_intr == 1 && ! pos) {
     1173                printk(KERN_WARNING
     1174                       "hda-intel: Invalid position buffer, "
     1175                       "using LPIB read method instead.\n");
     1176                chip->position_fix = POS_FIX_NONE;
     1177                goto read_lpib;
     1178            }
     1179        } else {
     1180        read_lpib:
    11451181                /* read LPIB */
    11461182                pos = azx_sd_readl(azx_dev, SD_LPIB);
     
    13071343        for (i = 0; i < chip->pcm_devs; i++)
    13081344                snd_pcm_suspend_all(chip->pcm[i]);
    1309         snd_hda_suspend(chip->bus, state);
    1310         if (! chip->single_cmd)
    1311                 azx_free_cmd_io(chip);
     1345        snd_hda_suspend(chip->bus, state);
     1346        azx_free_cmd_io(chip);
    13121347        pci_disable_device(pci);
    13131348        pci_save_state(pci);
     
    13461381                azx_int_clear(chip);
    13471382
    1348                 /* disable CORB/RIRB */
    1349                 if (! chip->single_cmd)
    1350                         azx_free_cmd_io(chip);
     1383                /* disable CORB/RIRB */
     1384                azx_free_cmd_io(chip);
    13511385
    13521386                /* disable position buffer */
     
    13961430
    13971431        *rchip = NULL;
    1398        
     1432
    13991433        if ((err = pci_enable_device(pci)) < 0)
    14001434                return err;
    14011435
    14021436        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    1403        
     1437
    14041438        if (NULL == chip) {
    14051439                snd_printk(KERN_ERR SFX "cannot allocate chip\n");
     
    14151449        chip->driver_type = driver_type;
    14161450
    1417         chip->position_fix = position_fix ? position_fix : POS_FIX_POSBUF;
     1451        chip->position_fix = position_fix;
    14181452        chip->single_cmd = single_cmd;
    14191453
  • GPL/trunk/alsa-kernel/pci/hda/hda_local.h

    r69 r76  
    6767int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
    6868int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
     69/* lowlevel accessor with caching; use carefully */
     70int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
     71                           int direction, int index);
     72int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
     73                             int direction, int idx, int mask, int val);
    6974
    7075/* mono switch binding multiple inputs */
     
    130135        int num_dacs;           /* # of DACs, must be more than 1 */
    131136        hda_nid_t *dac_nids;    /* DAC list */
    132         hda_nid_t hp_nid;       /* optional DAC for HP, 0 when not exists */
     137        hda_nid_t hp_nid;       /* optional DAC for HP, 0 when not exists */
     138        hda_nid_t extra_out_nid[3];     /* optional DACs, 0 when not exists */
    133139        hda_nid_t dig_out_nid;  /* digital out audio widget */
    134140        int max_channels;       /* currently supported analog channels */
     
    216222struct auto_pin_cfg {
    217223        int line_outs;
    218         hda_nid_t line_out_pins[5]; /* sorted in the order of Front/Surr/CLFE/Side */
    219         hda_nid_t speaker_pin;
     224        hda_nid_t line_out_pins[5]; /* sorted in the order of Front/Surr/CLFE/Side */
     225        int speaker_outs;
     226        hda_nid_t speaker_pins[5];
    220227        hda_nid_t hp_pin;
    221228        hda_nid_t input_pins[AUTO_PIN_LAST];
  • GPL/trunk/alsa-kernel/pci/hda/patch_analog.c

    r69 r76  
    132132                if (err < 0)
    133133                        return err;
    134         } 
     134        }
    135135        if (spec->dig_in_nid) {
    136136                err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
     
    309309        int i;
    310310
    311         ad198x_init(codec);
     311        codec->patch_ops.init(codec);
    312312        for (i = 0; i < spec->num_mixers; i++)
    313313                snd_hda_resume_ctls(codec, spec->mixers[i]);
     
    332332
    333333/*
     334 * EAPD control
     335 * the private value = nid | (invert << 8)
     336 */
     337static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
     338                            struct snd_ctl_elem_info *uinfo)
     339{
     340    uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     341    uinfo->count = 1;
     342    uinfo->value.integer.min = 0;
     343    uinfo->value.integer.max = 1;
     344    return 0;
     345}
     346
     347static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
     348                           struct snd_ctl_elem_value *ucontrol)
     349{
     350    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     351    struct ad198x_spec *spec = codec->spec;
     352    int invert = (kcontrol->private_value >> 8) & 1;
     353    if (invert)
     354        ucontrol->value.integer.value[0] = ! spec->cur_eapd;
     355    else
     356        ucontrol->value.integer.value[0] = spec->cur_eapd;
     357    return 0;
     358}
     359
     360static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
     361                           struct snd_ctl_elem_value *ucontrol)
     362{
     363    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     364    struct ad198x_spec *spec = codec->spec;
     365    int invert = (kcontrol->private_value >> 8) & 1;
     366    hda_nid_t nid = kcontrol->private_value & 0xff;
     367    unsigned int eapd;
     368    eapd = ucontrol->value.integer.value[0];
     369    if (invert)
     370        eapd = !eapd;
     371    if (eapd == spec->cur_eapd && ! codec->in_resume)
     372        return 0;
     373    spec->cur_eapd = eapd;
     374    snd_hda_codec_write(codec, nid,
     375                        0, AC_VERB_SET_EAPD_BTLENABLE,
     376                        eapd ? 0x02 : 0x00);
     377    return 1;
     378}
     379
     380static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
     381                               struct snd_ctl_elem_info *uinfo);
     382static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
     383                              struct snd_ctl_elem_value *ucontrol);
     384static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
     385                              struct snd_ctl_elem_value *ucontrol);
     386
     387/*
    334388 * AD1986A specific
    335389 */
     
    345399};
    346400static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
     401static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
    347402
    348403static struct hda_input_mux ad1986a_capture_source = {
     
    476531        HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
    477532        {0} /* end */
     533};
     534
     535/* additional mixers for 3stack mode */
     536static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
     537    {
     538        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     539        .name = "Channel Mode",
     540        .info = ad198x_ch_mode_info,
     541        .get = ad198x_ch_mode_get,
     542        .put = ad198x_ch_mode_put,
     543    },
     544    {0} /* end */
     545};
     546
     547/* laptop model - 2ch only */
     548static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
     549
     550static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
     551    HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
     552    HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
     553    HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
     554    HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
     555    /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
     556     HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
     557    HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
     558    HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
     559    HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
     560    HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
     561    HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
     562    HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
     563    HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
     564    HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
     565    /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
     566     HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
     567     HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
     568     HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
     569    HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
     570    HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
     571    {
     572        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     573        .name = "Capture Source",
     574        .info = ad198x_mux_enum_info,
     575        .get = ad198x_mux_enum_get,
     576        .put = ad198x_mux_enum_put,
     577    },
     578    {0} /* end */
     579};
     580
     581/* laptop-eapd model - 2ch only */
     582
     583/* master controls both pins 0x1a and 0x1b */
     584static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
     585                                         struct snd_ctl_elem_value *ucontrol)
     586{
     587    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     588    long *valp = ucontrol->value.integer.value;
     589    int change;
     590
     591    change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
     592                                      0x7f, valp[0] & 0x7f);
     593    change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
     594                                       0x7f, valp[1] & 0x7f);
     595    snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
     596                             0x7f, valp[0] & 0x7f);
     597    snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
     598                             0x7f, valp[1] & 0x7f);
     599    return change;
     600}
     601
     602static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
     603                                        struct snd_ctl_elem_value *ucontrol)
     604{
     605    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     606    long *valp = ucontrol->value.integer.value;
     607    int change;
     608
     609    change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
     610                                      0x80, valp[0] ? 0 : 0x80);
     611    change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
     612                                       0x80, valp[1] ? 0 : 0x80);
     613    snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
     614                             0x80, valp[0] ? 0 : 0x80);
     615    snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
     616                             0x80, valp[1] ? 0 : 0x80);
     617    return change;
     618}
     619
     620static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
     621    .num_items = 3,
     622    .items = {
     623        { "Mic", 0x0 },
     624        { "Internal Mic", 0x4 },
     625        { "Mix", 0x5 },
     626    },
     627};
     628
     629static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
     630    {
     631        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     632        .name = "Master Playback Volume",
     633        .info = snd_hda_mixer_amp_volume_info,
     634        .get = snd_hda_mixer_amp_volume_get,
     635        .put = ad1986a_laptop_master_vol_put,
     636        .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
     637    },
     638    {
     639        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     640        .name = "Master Playback Switch",
     641        .info = snd_hda_mixer_amp_switch_info,
     642        .get = snd_hda_mixer_amp_switch_get,
     643        .put = ad1986a_laptop_master_sw_put,
     644        .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
     645    },
     646    HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
     647    HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
     648    HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
     649    HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
     650    HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
     651    HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
     652    HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
     653    HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
     654    {
     655        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     656        .name = "Capture Source",
     657        .info = ad198x_mux_enum_info,
     658        .get = ad198x_mux_enum_get,
     659        .put = ad198x_mux_enum_put,
     660    },
     661    {
     662        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     663        .name = "External Amplifier",
     664        .info = ad198x_eapd_info,
     665        .get = ad198x_eapd_get,
     666        .put = ad198x_eapd_put,
     667        .private_value = 0x1b | (1 << 8), /* port-D, inversed */
     668    },
     669    {0} /* end */
    478670};
    479671
     
    536728};
    537729
     730/* additional verbs for 3-stack model */
     731static struct hda_verb ad1986a_3st_init_verbs[] = {
     732    /* Mic and line-in selectors */
     733    {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
     734    {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
     735    {0} /* end */
     736};
     737
     738static struct hda_verb ad1986a_ch2_init[] = {
     739    /* Surround out -> Line In */
     740    { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
     741    { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
     742    /* CLFE -> Mic in */
     743    { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
     744    { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
     745    {0} /* end */
     746};
     747
     748static struct hda_verb ad1986a_ch4_init[] = {
     749    /* Surround out -> Surround */
     750    { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
     751    { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
     752    /* CLFE -> Mic in */
     753    { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
     754    { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
     755    {0} /* end */
     756};
     757
     758static struct hda_verb ad1986a_ch6_init[] = {
     759    /* Surround out -> Surround out */
     760    { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
     761    { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
     762    /* CLFE -> CLFE */
     763    { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
     764    { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
     765    {0} /* end */
     766};
     767
     768static struct hda_channel_mode ad1986a_modes[3] = {
     769    { 2, ad1986a_ch2_init },
     770    { 4, ad1986a_ch4_init },
     771    { 6, ad1986a_ch6_init },
     772};
     773
     774/* eapd initialization */
     775static struct hda_verb ad1986a_eapd_init_verbs[] = {
     776    {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00},
     777    {0}
     778};
     779
     780/* models */
     781enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP, AD1986A_LAPTOP_EAPD };
     782
     783static struct hda_board_config ad1986a_cfg_tbl[] = {
     784    { .modelname = "6stack",        .config = AD1986A_6STACK },
     785    { .modelname = "3stack",        .config = AD1986A_3STACK },
     786    { .pci_subvendor = 0x10de, .pci_subdevice = 0xcb84,
     787    .config = AD1986A_3STACK }, /* ASUS A8N-VM CSM */
     788    { .modelname = "laptop",        .config = AD1986A_LAPTOP },
     789    { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
     790    .config = AD1986A_LAPTOP }, /* FSC V2060 */
     791    { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
     792    .config = AD1986A_LAPTOP }, /* Samsung M50 */
     793    { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
     794    .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
     795    { .modelname = "laptop-eapd",   .config = AD1986A_LAPTOP_EAPD },
     796    { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
     797    .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
     798    { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
     799                   .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
     800    {0}
     801};
    538802
    539803static int patch_ad1986a(struct hda_codec *codec)
    540804{
    541         struct ad198x_spec *spec;
     805    struct ad198x_spec *spec;
     806    int board_config;
    542807
    543808        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
     
    553818        spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
    554819        spec->num_adc_nids = 1;
    555         spec->adc_nids = ad1986a_adc_nids;
    556         spec->capsrc_nids = ad1986a_adc_nids;
     820        spec->adc_nids = ad1986a_adc_nids;
     821        spec->capsrc_nids = ad1986a_capsrc_nids;
    557822        spec->input_mux = &ad1986a_capture_source;
    558823        spec->num_mixers = 1;
     
    562827
    563828        codec->patch_ops = ad198x_patch_ops;
     829        /* override some parameters */
     830        board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
     831        switch (board_config) {
     832        case AD1986A_3STACK:
     833            spec->num_mixers = 2;
     834            spec->mixers[1] = ad1986a_3st_mixers;
     835            spec->num_init_verbs = 2;
     836            spec->init_verbs[1] = ad1986a_3st_init_verbs;
     837            spec->channel_mode = ad1986a_modes;
     838            spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
     839            break;
     840        case AD1986A_LAPTOP:
     841            spec->mixers[0] = ad1986a_laptop_mixers;
     842            spec->multiout.max_channels = 2;
     843            spec->multiout.num_dacs = 1;
     844            spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
     845            break;
     846        case AD1986A_LAPTOP_EAPD:
     847            spec->mixers[0] = ad1986a_laptop_eapd_mixers;
     848            spec->num_init_verbs = 2;
     849            spec->init_verbs[1] = ad1986a_eapd_init_verbs;
     850            spec->multiout.max_channels = 2;
     851            spec->multiout.num_dacs = 1;
     852            spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
     853            spec->multiout.dig_out_nid = 0;
     854            spec->input_mux = &ad1986a_laptop_eapd_capture_source;
     855                         break;
     856        }
    564857
    565858        return 0;
     
    576869static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
    577870static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
     871static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
    578872
    579873static struct hda_input_mux ad1983_capture_source = {
     
    7171011        spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
    7181012        spec->num_adc_nids = 1;
    719         spec->adc_nids = ad1983_adc_nids;
    720         spec->capsrc_nids = ad1983_adc_nids;
     1013        spec->adc_nids = ad1983_adc_nids;
     1014        spec->capsrc_nids = ad1983_capsrc_nids;
    7211015        spec->input_mux = &ad1983_capture_source;
    7221016        spec->num_mixers = 1;
     
    7421036static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
    7431037static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
     1038static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
    7441039
    7451040/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
     
    8471142};
    8481143
     1144/*
     1145 * Patch for HP nx6320
     1146 *
     1147 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
     1148 * speaker output enabled _and_ mute-LED off.
     1149 */
     1150
     1151#define AD1981_HP_EVENT         0x37
     1152#define AD1981_MIC_EVENT        0x38
     1153
     1154static struct hda_verb ad1981_hp_init_verbs[] = {
     1155    {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
     1156    /* pin sensing on HP and Mic jacks */
     1157    {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
     1158    {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
     1159    {0}
     1160};
     1161
     1162/* turn on/off EAPD (+ mute HP) as a master switch */
     1163static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
     1164                                   struct snd_ctl_elem_value *ucontrol)
     1165{
     1166    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     1167    struct ad198x_spec *spec = codec->spec;
     1168
     1169    if (! ad198x_eapd_put(kcontrol, ucontrol))
     1170        return 0;
     1171
     1172    /* toggle HP mute appropriately */
     1173    snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
     1174                             0x80, spec->cur_eapd ? 0 : 0x80);
     1175    snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
     1176                             0x80, spec->cur_eapd ? 0 : 0x80);
     1177    return 1;
     1178}
     1179
     1180/* bind volumes of both NID 0x05 and 0x06 */
     1181static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
     1182                                    struct snd_ctl_elem_value *ucontrol)
     1183{
     1184    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     1185    long *valp = ucontrol->value.integer.value;
     1186    int change;
     1187
     1188    change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
     1189                                      0x7f, valp[0] & 0x7f);
     1190    change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
     1191                                       0x7f, valp[1] & 0x7f);
     1192    snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
     1193                             0x7f, valp[0] & 0x7f);
     1194    snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
     1195                             0x7f, valp[1] & 0x7f);
     1196    return change;
     1197}
     1198
     1199/* mute internal speaker if HP is plugged */
     1200static void ad1981_hp_automute(struct hda_codec *codec)
     1201{
     1202    unsigned int present;
     1203
     1204    present = snd_hda_codec_read(codec, 0x06, 0,
     1205                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1206    snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
     1207                             0x80, present ? 0x80 : 0);
     1208    snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
     1209                             0x80, present ? 0x80 : 0);
     1210}
     1211
     1212/* toggle input of built-in and mic jack appropriately */
     1213static void ad1981_hp_automic(struct hda_codec *codec)
     1214{
     1215    static struct hda_verb mic_jack_on[] = {
     1216        {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
     1217        {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
     1218        {0}
     1219    };
     1220    static struct hda_verb mic_jack_off[] = {
     1221        {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
     1222        {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
     1223        {0}
     1224    };
     1225    unsigned int present;
     1226
     1227    present = snd_hda_codec_read(codec, 0x08, 0,
     1228                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1229    if (present)
     1230        snd_hda_sequence_write(codec, mic_jack_on);
     1231    else
     1232        snd_hda_sequence_write(codec, mic_jack_off);
     1233}
     1234
     1235/* unsolicited event for HP jack sensing */
     1236static void ad1981_hp_unsol_event(struct hda_codec *codec,
     1237                                  unsigned int res)
     1238{
     1239    res >>= 26;
     1240    switch (res) {
     1241    case AD1981_HP_EVENT:
     1242        ad1981_hp_automute(codec);
     1243        break;
     1244    case AD1981_MIC_EVENT:
     1245        ad1981_hp_automic(codec);
     1246        break;
     1247    }
     1248}
     1249
     1250static struct hda_input_mux ad1981_hp_capture_source = {
     1251    .num_items = 3,
     1252    .items = {
     1253        { "Mic", 0x0 },
     1254        { "Docking-Station", 0x1 },
     1255        { "Mix", 0x2 },
     1256    },
     1257};
     1258
     1259static struct snd_kcontrol_new ad1981_hp_mixers[] = {
     1260    {
     1261        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1262        .name = "Master Playback Volume",
     1263        .info = snd_hda_mixer_amp_volume_info,
     1264        .get = snd_hda_mixer_amp_volume_get,
     1265        .put = ad1981_hp_master_vol_put,
     1266        .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
     1267    },
     1268    {
     1269        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1270        .name = "Master Playback Switch",
     1271        .info = ad198x_eapd_info,
     1272        .get = ad198x_eapd_get,
     1273        .put = ad1981_hp_master_sw_put,
     1274        .private_value = 0x05,
     1275    },
     1276    HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
     1277    HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
     1278#if 0
     1279    /* FIXME: analog mic/line loopback doesn't work with my tests...
     1280     *        (although recording is OK)
     1281     */
     1282    HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
     1283    HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
     1284    HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
     1285    HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
     1286    HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
     1287    HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
     1288    /* FIXME: does this laptop have analog CD connection? */
     1289    HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
     1290    HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
     1291#endif
     1292    HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
     1293    HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
     1294    HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
     1295    HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
     1296    {
     1297        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1298        .name = "Capture Source",
     1299        .info = ad198x_mux_enum_info,
     1300        .get = ad198x_mux_enum_get,
     1301        .put = ad198x_mux_enum_put,
     1302    },
     1303    {0} /* end */
     1304};
     1305
     1306/* initialize jack-sensing, too */
     1307static int ad1981_hp_init(struct hda_codec *codec)
     1308{
     1309    ad198x_init(codec);
     1310    ad1981_hp_automute(codec);
     1311    ad1981_hp_automic(codec);
     1312    return 0;
     1313}
     1314
     1315/* models */
     1316enum { AD1981_BASIC, AD1981_HP };
     1317
     1318static struct hda_board_config ad1981_cfg_tbl[] = {
     1319    { .modelname = "hp", .config = AD1981_HP },
     1320    { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
     1321    .config = AD1981_HP }, /* HP nx6320 */
     1322    { .pci_subvendor = 0x103c, .pci_subdevice = 0x309f,
     1323    .config = AD1981_HP }, /* HP nx9420 AngelFire */
     1324    { .modelname = "basic", .config = AD1981_BASIC },
     1325    {0}
     1326};
     1327
    8491328static int patch_ad1981(struct hda_codec *codec)
    8501329{
    851         struct ad198x_spec *spec;
     1330    struct ad198x_spec *spec;
     1331    int board_config;
    8521332
    8531333        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
     
    8641344        spec->num_adc_nids = 1;
    8651345        spec->adc_nids = ad1981_adc_nids;
    866         spec->capsrc_nids = ad1981_adc_nids;
     1346        spec->capsrc_nids = ad1981_capsrc_nids;
    8671347        spec->input_mux = &ad1981_capture_source;
    8681348        spec->num_mixers = 1;
     
    8731353
    8741354        codec->patch_ops = ad198x_patch_ops;
     1355
     1356        /* override some parameters */
     1357        board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
     1358        switch (board_config) {
     1359        case AD1981_HP:
     1360            spec->mixers[0] = ad1981_hp_mixers;
     1361            spec->num_init_verbs = 2;
     1362            spec->init_verbs[1] = ad1981_hp_init_verbs;
     1363            spec->multiout.dig_out_nid = 0;
     1364            spec->input_mux = &ad1981_hp_capture_source;
     1365
     1366            codec->patch_ops.init = ad1981_hp_init;
     1367            codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
     1368            break;
     1369        }
    8751370
    8761371        return 0;
     
    10611556}
    10621557
    1063 /*
    1064  * EAPD control
    1065  */
    1066 static int ad1988_eapd_info(struct snd_kcontrol *kcontrol,
    1067                             struct snd_ctl_elem_info *uinfo)
    1068 {
    1069         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
    1070         uinfo->count = 1;
    1071         uinfo->value.integer.min = 0;
    1072         uinfo->value.integer.max = 1;
    1073         return 0;
    1074 }
    1075 
    1076 static int ad1988_eapd_get(struct snd_kcontrol *kcontrol,
    1077                            struct snd_ctl_elem_value *ucontrol)
    1078 {
    1079         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    1080         struct ad198x_spec *spec = codec->spec;
    1081         ucontrol->value.enumerated.item[0] = ! spec->cur_eapd;
    1082         return 0;
    1083 }
    1084 
    1085 static int ad1988_eapd_put(struct snd_kcontrol *kcontrol,
    1086                            struct snd_ctl_elem_value *ucontrol)
    1087 {
    1088         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    1089         struct ad198x_spec *spec = codec->spec;
    1090         unsigned int eapd;
    1091         eapd = ! ucontrol->value.enumerated.item[0];
    1092         if (eapd == spec->cur_eapd && ! codec->in_resume)
    1093                 return 0;
    1094         spec->cur_eapd = eapd;
    1095         snd_hda_codec_write(codec, 0x12 /* port-D */,
    1096                             0, AC_VERB_SET_EAPD_BTLENABLE,
    1097                             eapd ? 0x02 : 0x00);
    1098         return 0;
    1099 }
    1100 
    11011558/* 6-stack mode */
    11021559static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
     
    12201677        {
    12211678                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    1222                 .name = "External Amplifier",
    1223                 .info = ad1988_eapd_info,
    1224                 .get = ad1988_eapd_get,
    1225                 .put = ad1988_eapd_put,
     1679                .name = "External Amplifier",
     1680                .info = ad198x_eapd_info,
     1681                .get = ad198x_eapd_get,
     1682                .put = ad198x_eapd_put,
     1683                .private_value = 0x12 | (1 << 8), /* port-D, inversed */
    12261684        },
    12271685
     
    15952053        else
    15962054                snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
    1597 } 
     2055}
    15982056
    15992057
     
    17962254        idx = ad1988_pin_idx(pin);
    17972255        nid = ad1988_idx_to_dac(codec, idx);
    1798         if (! spec->multiout.dac_nids[0]) {
    1799                 /* use this as the primary output */
    1800                 spec->multiout.dac_nids[0] = nid;
    1801                 if (! spec->multiout.num_dacs)
    1802                         spec->multiout.num_dacs = 1;
    1803         } else
    1804                 /* specify the DAC as the extra output */
    1805                 spec->multiout.hp_nid = nid;
     2256        /* specify the DAC as the extra output */
     2257        if (! spec->multiout.hp_nid)
     2258            spec->multiout.hp_nid = nid;
     2259        else
     2260            spec->multiout.extra_out_nid[0] = nid;
    18062261        /* control HP volume/switch on the output mixer amp */
    18072262        sprintf(name, "%s Playback Volume", pfx);
     
    19222377        hda_nid_t pin;
    19232378
    1924         pin = spec->autocfg.speaker_pin;
     2379        pin = spec->autocfg.speaker_pins[0];
    19252380        if (pin) /* connect to front */
    19262381                ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
     
    19702425                return err;
    19712426        if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
    1972                 return err;
    1973         if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
    1974             ! spec->autocfg.hp_pin)
     2427            return err;
     2428        if (! spec->autocfg.line_outs)
    19752429                return 0; /* can't find valid BIOS pin config */
    1976         if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
    1977             (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
    1978                                                 "Speaker")) < 0 ||
    1979             (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
     2430        if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
     2431            (err = ad1988_auto_create_extra_out(codec,
     2432                                                spec->autocfg.speaker_pins[0],
     2433                                                "Speaker")) < 0 ||
     2434            (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pin,
    19802435                                                "Headphone")) < 0 ||
    19812436            (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  • GPL/trunk/alsa-kernel/pci/hda/patch_realtek.c

    r74 r76  
    77 *                    PeiSen Hou <pshou@realtek.com.tw>
    88 *                    Takashi Iwai <tiwai@suse.de>
     9 *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
    910 *
    1011 *  This driver is free software; you can redistribute it and/or modify
     
    5051        ALC880_UNIWILL_DIG,
    5152        ALC880_CLEVO,
    52         ALC880_TCL_S700,
     53        ALC880_TCL_S700,
     54        ALC880_LG,
     55        ALC880_LG_LW,
    5356#ifdef CONFIG_SND_DEBUG
    5457        ALC880_TEST,
     
    6467        ALC260_HP_3013,
    6568        ALC260_FUJITSU_S702X,
     69        ALC260_ACER,
     70#ifdef CONFIG_SND_DEBUG
     71        ALC260_TEST,
     72#endif
    6673        ALC260_AUTO,
    6774        ALC260_MODEL_LAST /* last tag */
     
    7178enum {
    7279        ALC262_BASIC,
     80        ALC262_FUJITSU,
    7381        ALC262_AUTO,
    7482        ALC262_MODEL_LAST /* last tag */
     
    109117        struct hda_pcm_stream *stream_analog_capture;
    110118
    111         char *stream_name_digital;      /* digital PCM stream */ 
     119        char *stream_name_digital;      /* digital PCM stream */
    112120        struct hda_pcm_stream *stream_digital_playback;
    113121        struct hda_pcm_stream *stream_digital_capture;
     
    133141
    134142        /* PCM information */
    135         struct hda_pcm pcm_rec[2];      /* used in alc_build_pcms() */
     143        struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
    136144
    137145        /* dynamic controls, init_verbs and input_mux */
     
    141149        struct hda_input_mux private_imux;
    142150        hda_nid_t private_dac_nids[5];
     151
     152        /* hooks */
     153        void (*init_hook)(struct hda_codec *codec);
     154        void (*unsol_event)(struct hda_codec *codec, unsigned int res);
     155
     156        /* for pin sensing */
     157        unsigned int sense_updated: 1;
     158        unsigned int jack_present: 1;
    143159};
    144160
     
    158174        unsigned int num_channel_mode;
    159175        const struct hda_channel_mode *channel_mode;
    160         const struct hda_input_mux *input_mux;
     176        const struct hda_input_mux *input_mux;
     177        void (*unsol_event)(struct hda_codec *, unsigned int);
     178        void (*init_hook)(struct hda_codec *);
    161179};
    162180
     
    219237}
    220238
    221 
    222 /*
    223  * Control of pin widget settings via the mixer.  Only boolean settings are
    224  * supported, so VrefEn can't be controlled using these functions as they
    225  * stand.
    226  */
    227 static int alc_pinctl_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     239/*
     240 * Control the mode of pin widget settings via the mixer.  "pc" is used
     241 * instead of "%" to avoid consequences of accidently treating the % as
     242 * being part of a format specifier.  Maximum allowed length of a value is
     243 * 63 characters plus NULL terminator.
     244 *
     245 * Note: some retasking pin complexes seem to ignore requests for input
     246 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
     247 * are requested.  Therefore order this list so that this behaviour will not
     248 * cause problems when mixer clients move through the enum sequentially.
     249 * NIDs 0x0f and 0x10 have been observed to have this behaviour.
     250 */
     251static char *alc_pin_mode_names[] = {
     252        "Mic 50pc bias", "Mic 80pc bias",
     253        "Line in", "Line out", "Headphone out",
     254};
     255static unsigned char alc_pin_mode_values[] = {
     256        PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
     257};
     258/* The control can present all 5 options, or it can limit the options based
     259 * in the pin being assumed to be exclusively an input or an output pin.
     260 */
     261#define ALC_PIN_DIR_IN    0x00
     262#define ALC_PIN_DIR_OUT   0x01
     263#define ALC_PIN_DIR_INOUT 0x02
     264
     265/* Info about the pin modes supported by the three different pin directions.
     266 * For each direction the minimum and maximum values are given.
     267 */
     268static signed char alc_pin_mode_dir_info[3][2] = {
     269        { 0, 2 },    /* ALC_PIN_DIR_IN */
     270        { 3, 4 },    /* ALC_PIN_DIR_OUT */
     271        { 0, 4 },    /* ALC_PIN_DIR_INOUT */
     272};
     273#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
     274#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
     275#define alc_pin_mode_n_items(_dir) \
     276        (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
     277
     278static int alc_pin_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     279{
     280        unsigned int item_num = uinfo->value.enumerated.item;
     281        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
     282
     283        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     284        uinfo->count = 1;
     285        uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
     286
     287        if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
     288                item_num = alc_pin_mode_min(dir);
     289        strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
     290        return 0;
     291}
     292
     293static int alc_pin_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     294{
     295        unsigned int i;
     296        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     297        hda_nid_t nid = kcontrol->private_value & 0xffff;
     298        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
     299        long *valp = ucontrol->value.integer.value;
     300        unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
     301
     302        /* Find enumerated value for current pinctl setting */
     303        i = alc_pin_mode_min(dir);
     304        while (alc_pin_mode_values[i]!=pinctl && i<=alc_pin_mode_max(dir))
     305                i++;
     306        *valp = i<=alc_pin_mode_max(dir)?i:alc_pin_mode_min(dir);
     307        return 0;
     308}
     309
     310static int alc_pin_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     311{
     312        signed int change;
     313        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     314        hda_nid_t nid = kcontrol->private_value & 0xffff;
     315        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
     316        long val = *ucontrol->value.integer.value;
     317        unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
     318
     319        if (val<alc_pin_mode_min(dir) || val>alc_pin_mode_max(dir))
     320                val = alc_pin_mode_min(dir);
     321
     322        change = pinctl != alc_pin_mode_values[val];
     323        if (change) {
     324                /* Set pin mode to that requested */
     325                snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
     326                        alc_pin_mode_values[val]);
     327
     328                /* Also enable the retasking pin's input/output as required
     329                 * for the requested pin mode.  Enum values of 2 or less are
     330                 * input modes.
     331                 *
     332                 * Dynamically switching the input/output buffers probably
     333                 * reduces noise slightly, particularly on input.  However,
     334                 * havingboth input and output buffers enabled
     335                 * simultaneously doesn't seem to be problematic.
     336                 */
     337                if (val <= 2) {
     338                        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
     339                                AMP_OUT_MUTE);
     340                        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
     341                                AMP_IN_UNMUTE(0));
     342                } else {
     343                        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
     344                                AMP_IN_MUTE(0));
     345                        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
     346                                AMP_OUT_UNMUTE);
     347                }
     348        }
     349        return change;
     350}
     351
     352#define ALC_PIN_MODE(xname, nid, dir) \
     353        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
     354          .info = alc_pin_mode_info, \
     355          .get = alc_pin_mode_get, \
     356          .put = alc_pin_mode_put, \
     357          .private_value = nid | (dir<<16) }
     358
     359/* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
     360 * together using a mask with more than one bit set.  This control is
     361 * currently used only by the ALC260 test model.  At this stage they are not
     362 * needed for any "production" models.
     363 */
     364#ifdef CONFIG_SND_DEBUG
     365static int alc_gpio_data_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    228366{
    229367        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     
    233371        return 0;
    234372}
    235 
    236 static int alc_pinctl_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     373static int alc_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    237374{
    238375        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    239376        hda_nid_t nid = kcontrol->private_value & 0xffff;
    240         long mask = (kcontrol->private_value >> 16) & 0xff;
     377        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
    241378        long *valp = ucontrol->value.integer.value;
    242 
    243         *valp = 0;
    244         if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)
    245                 *valp = 1;
     379        unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
     380
     381        *valp = (val & mask) != 0;
    246382        return 0;
    247383}
    248 
    249 static int alc_pinctl_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    250 {
     384static int alc_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     385{
     386        signed int change;
    251387        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    252388        hda_nid_t nid = kcontrol->private_value & 0xffff;
    253         long mask = (kcontrol->private_value >> 16) & 0xff;
     389        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
     390        long val = *ucontrol->value.integer.value;
     391        unsigned int gpio_data = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
     392
     393        /* Set/unset the masked GPIO bit(s) as needed */
     394        change = (val==0?0:mask) != (gpio_data & mask);
     395        if (val==0)
     396                gpio_data &= ~mask;
     397        else
     398                gpio_data |= mask;
     399        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_GPIO_DATA,gpio_data);
     400
     401        return change;
     402}
     403#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
     404        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
     405          .info = alc_gpio_data_info, \
     406          .get = alc_gpio_data_get, \
     407          .put = alc_gpio_data_put, \
     408          .private_value = nid | (mask<<16) }
     409#endif   /* CONFIG_SND_DEBUG */
     410
     411/* A switch control to allow the enabling of the digital IO pins on the
     412 * ALC260.  This is incredibly simplistic; the intention of this control is
     413 * to provide something in the test model allowing digital outputs to be
     414 * identified if present.  If models are found which can utilise these
     415 * outputs a more complete mixer control can be devised for those models if
     416 * necessary.
     417 */
     418#ifdef CONFIG_SND_DEBUG
     419static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     420{
     421        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     422        uinfo->count = 1;
     423        uinfo->value.integer.min = 0;
     424        uinfo->value.integer.max = 1;
     425        return 0;
     426}
     427static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     428{
     429        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     430        hda_nid_t nid = kcontrol->private_value & 0xffff;
     431        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
    254432        long *valp = ucontrol->value.integer.value;
    255         unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
    256         int change = ((pinctl & mask)!=0) != *valp;
    257 
    258         if (change)
    259                 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
    260                         *valp?(pinctl|mask):(pinctl&~mask));
     433        unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_DIGI_CONVERT,0x00);
     434
     435        *valp = (val & mask) != 0;
     436        return 0;
     437}
     438static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     439{
     440        signed int change;
     441        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     442        hda_nid_t nid = kcontrol->private_value & 0xffff;
     443        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
     444        long val = *ucontrol->value.integer.value;
     445        unsigned int ctrl_data = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_DIGI_CONVERT,0x00);
     446
     447        /* Set/unset the masked control bit(s) as needed */
     448        change = (val==0?0:mask) != (ctrl_data & mask);
     449        if (val==0)
     450                ctrl_data &= ~mask;
     451        else
     452                ctrl_data |= mask;
     453        snd_hda_codec_write(codec,nid,0,AC_VERB_SET_DIGI_CONVERT_1,ctrl_data);
     454
    261455        return change;
    262456}
    263 
    264 #define ALC_PINCTL_SWITCH(xname, nid, mask) \
     457#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
    265458        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
    266           .info = alc_pinctl_switch_info, \
    267           .get = alc_pinctl_switch_get, \
    268           .put = alc_pinctl_switch_put, \
    269           .private_value = (nid) | (mask<<16) }
    270 
     459          .info = alc_spdif_ctrl_info, \
     460          .get = alc_spdif_ctrl_get, \
     461          .put = alc_spdif_ctrl_put, \
     462          .private_value = nid | (mask<<16) }
     463#endif   /* CONFIG_SND_DEBUG */
    271464
    272465/*
     
    281474        for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i]; i++)
    282475                spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
    283        
     476
    284477        spec->channel_mode = preset->channel_mode;
    285478        spec->num_channel_mode = preset->num_channel_mode;
     
    291484        spec->multiout.dig_out_nid = preset->dig_out_nid;
    292485        spec->multiout.hp_nid = preset->hp_nid;
    293        
     486
    294487        spec->input_mux = preset->input_mux;
    295488
    296489        spec->num_adc_nids = preset->num_adc_nids;
    297490        spec->adc_nids = preset->adc_nids;
    298         spec->dig_in_nid = preset->dig_in_nid;
     491        spec->dig_in_nid = preset->dig_in_nid;
     492        spec->unsol_event = preset->unsol_event;
     493        spec->init_hook = preset->init_hook;
    299494}
    300495
     
    494689        /* front, rear, clfe, rear_surr */
    495690        0x02, 0x03, 0x04, 0x05
    496 };     
     691};
    497692
    498693static struct hda_input_mux alc880_6stack_capture_source = {
     
    554749 * The system also has a pair of internal speakers, and a headphone jack.
    555750 * These are both connected to Line2 on the codec, hence to DAC 02.
    556  * 
     751 *
    557752 * There is a variable resistor to control the speaker or headphone
    558753 * volume. This is a hardware-only device without a software API.
     
    9641159        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    9651160        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
    966        
     1161
    9671162        {0}
    9681163};
     
    10261221        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    10271222        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
    1028        
     1223
    10291224        {0}
    10301225};
     
    10991294
    11001295/*
     1296 * LG m1 express dual
     1297 *
     1298 * Pin assignment:
     1299 *   Rear Line-In/Out (blue): 0x14
     1300 *   Build-in Mic-In: 0x15
     1301 *   Speaker-out: 0x17
     1302 *   HP-Out (green): 0x1b
     1303 *   Mic-In/Out (red): 0x19
     1304 *   SPDIF-Out: 0x1e
     1305 */
     1306
     1307/* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
     1308static hda_nid_t alc880_lg_dac_nids[3] = {
     1309    0x05, 0x02, 0x03
     1310};
     1311
     1312/* seems analog CD is not working */
     1313static struct hda_input_mux alc880_lg_capture_source = {
     1314    .num_items = 3,
     1315    .items = {
     1316        { "Mic", 0x1 },
     1317        { "Line", 0x5 },
     1318        { "Internal Mic", 0x6 },
     1319    },
     1320};
     1321
     1322/* 2,4,6 channel modes */
     1323static struct hda_verb alc880_lg_ch2_init[] = {
     1324    /* set line-in and mic-in to input */
     1325    { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
     1326    { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
     1327    {0}
     1328};
     1329
     1330static struct hda_verb alc880_lg_ch4_init[] = {
     1331    /* set line-in to out and mic-in to input */
     1332    { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1333    { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
     1334    {0}
     1335};
     1336
     1337static struct hda_verb alc880_lg_ch6_init[] = {
     1338    /* set line-in and mic-in to output */
     1339    { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1340    { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
     1341    {0}
     1342};
     1343
     1344static struct hda_channel_mode alc880_lg_ch_modes[3] = {
     1345    { 2, alc880_lg_ch2_init },
     1346    { 4, alc880_lg_ch4_init },
     1347    { 6, alc880_lg_ch6_init },
     1348};
     1349
     1350static struct snd_kcontrol_new alc880_lg_mixer[] = {
     1351    /* FIXME: it's not really "master" but front channels */
     1352    HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
     1353    HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
     1354    HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1355    HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
     1356    HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
     1357    HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
     1358    HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
     1359    HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
     1360    HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
     1361    HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
     1362    HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
     1363    HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
     1364    HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
     1365    HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
     1366    {
     1367        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1368        .name = "Channel Mode",
     1369        .info = alc_ch_mode_info,
     1370        .get = alc_ch_mode_get,
     1371        .put = alc_ch_mode_put,
     1372    },
     1373    {0} /* end */
     1374};
     1375
     1376static struct hda_verb alc880_lg_init_verbs[] = {
     1377    /* set capture source to mic-in */
     1378    {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1379    {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1380    {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
     1381    /* mute all amp mixer inputs */
     1382    {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
     1383    {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
     1384    {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
     1385    /* line-in to input */
     1386    {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     1387    {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1388    /* built-in mic */
     1389    {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1390    {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1391    /* speaker-out */
     1392    {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1393    {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1394    /* mic-in to input */
     1395    {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
     1396    {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1397    {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1398    /* HP-out */
     1399    {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
     1400    {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1401    {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1402    /* jack sense */
     1403    {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
     1404    {0}
     1405};
     1406
     1407/* toggle speaker-output according to the hp-jack state */
     1408static void alc880_lg_automute(struct hda_codec *codec)
     1409{
     1410    unsigned int present;
     1411
     1412    present = snd_hda_codec_read(codec, 0x1b, 0,
     1413                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1414    snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
     1415                             0x80, present ? 0x80 : 0);
     1416    snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
     1417                             0x80, present ? 0x80 : 0);
     1418}
     1419
     1420static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
     1421{
     1422    /* Looks like the unsol event is incompatible with the standard
     1423     * definition.  4bit tag is placed at 28 bit!
     1424     */
     1425    if ((res >> 28) == 0x01)
     1426        alc880_lg_automute(codec);
     1427}
     1428
     1429/*
     1430 * LG LW20
     1431 *
     1432 * Pin assignment:
     1433 *   Speaker-out: 0x14
     1434 *   Mic-In: 0x18
     1435 *   Built-in Mic-In: 0x19 (?)
     1436 *   HP-Out: 0x1b
     1437 *   SPDIF-Out: 0x1e
     1438 */
     1439
     1440/* seems analog CD is not working */
     1441static struct hda_input_mux alc880_lg_lw_capture_source = {
     1442    .num_items = 2,
     1443    .items = {
     1444        { "Mic", 0x0 },
     1445        { "Internal Mic", 0x1 },
     1446    },
     1447};
     1448
     1449static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
     1450    HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
     1451    HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
     1452    HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     1453    HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     1454    HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
     1455    HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
     1456    {0} /* end */
     1457};
     1458
     1459static struct hda_verb alc880_lg_lw_init_verbs[] = {
     1460    /* set capture source to mic-in */
     1461    {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1462    {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1463    {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     1464    {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
     1465    /* speaker-out */
     1466    {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1467    {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1468    /* HP-out */
     1469    {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
     1470    {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     1471    {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1472    /* mic-in to input */
     1473    {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1474    {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1475    /* built-in mic */
     1476    {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
     1477    {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     1478    /* jack sense */
     1479    {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
     1480    {0}
     1481};
     1482
     1483/* toggle speaker-output according to the hp-jack state */
     1484static void alc880_lg_lw_automute(struct hda_codec *codec)
     1485{
     1486    unsigned int present;
     1487
     1488    present = snd_hda_codec_read(codec, 0x1b, 0,
     1489                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
     1490    snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
     1491                             0x80, present ? 0x80 : 0);
     1492    snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
     1493                             0x80, present ? 0x80 : 0);
     1494}
     1495
     1496static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
     1497{
     1498    /* Looks like the unsol event is incompatible with the standard
     1499     * definition.  4bit tag is placed at 28 bit!
     1500     */
     1501    if ((res >> 28) == 0x01)
     1502        alc880_lg_lw_automute(codec);
     1503}
     1504
     1505/*
     1506 * Common callbacks
    11011507 */
    11021508
     
    11071513
    11081514        for (i = 0; i < spec->num_init_verbs; i++)
    1109                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
     1515            snd_hda_sequence_write(codec, spec->init_verbs[i]);
     1516        if (spec->init_hook)
     1517            spec->init_hook(codec);
    11101518        return 0;
     1519}
     1520
     1521static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
     1522{
     1523    struct alc_spec *spec = codec->spec;
     1524
     1525    if (spec->unsol_event)
     1526        spec->unsol_event(codec, res);
    11111527}
    11121528
     
    12491665        .channels_max = 2,
    12501666        /* NID is set in alc_build_pcms */
     1667};
     1668
     1669/* Used by alc_build_pcms to flag that a PCM has no playback stream */
     1670static struct hda_pcm_stream alc_pcm_null_playback = {
     1671        .substreams = 0,
     1672        .channels_min = 0,
     1673        .channels_max = 0,
    12511674};
    12521675
     
    12781701                                info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
    12791702                        }
     1703                }
     1704        }
     1705
     1706        /* If the use of more than one ADC is requested for the current
     1707         * model, configure a second analog capture-only PCM.
     1708         */
     1709        if (spec->num_adc_nids > 1) {
     1710                codec->num_pcms++;
     1711                info++;
     1712                info->name = spec->stream_name_analog;
     1713                /* No playback stream for second PCM */
     1714                info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
     1715                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
     1716                if (spec->stream_analog_capture) {
     1717                        snd_assert(spec->adc_nids, return -EINVAL);
     1718                        info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
     1719                        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
    12801720                }
    12811721        }
     
    13221762        .build_pcms = alc_build_pcms,
    13231763        .init = alc_init,
    1324         .free = alc_free,
     1764        .free = alc_free,
     1765        .unsol_event = alc_unsol_event,
    13251766#ifdef CONFIG_PM
    13261767        .resume = alc_resume,
     
    13411782
    13421783static struct hda_input_mux alc880_test_capture_source = {
    1343         .num_items = 5,
     1784        .num_items = 7,
    13441785        .items = {
    13451786                { "In-1", 0x0 },
     
    13471788                { "In-3", 0x2 },
    13481789                { "In-4", 0x3 },
    1349                 { "CD", 0x4 },
     1790                { "CD", 0x4 },
     1791                { "Front", 0x5 },
     1792                { "Surround", 0x6 },
    13501793        },
    13511794};
     
    16202063        /* Back 3 jack, front 2 jack (Internal add Aux-In) */
    16212064        { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
    1622         { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST }, 
     2065        { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST },
    16232066        { .pci_subvendor = 0x104d, .pci_subdevice = 0x81a0, .config = ALC880_3ST },
    16242067
     
    16532096        { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
    16542097        { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
    1655         { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
     2098        { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
     2099        { .pci_subvendor = 0xa0a0, .pci_subdevice = 0x0560, .config = ALC880_5ST_DIG }, /* Aopen i915GMm-HFS */
    16562100        /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
    16572101        { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
     
    16692113        { .pci_subvendor = 0x1043, .pci_subdevice = 0x81b4, .config = ALC880_6ST },
    16702114        { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
     2115        { .pci_subvendor = 0x1458, .pci_subdevice = 0xa102, .config = ALC880_6ST }, /* Gigabyte K8N51 */
    16712116
    16722117        { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
     
    16792124        { .pci_subvendor = 0x1025, .pci_subdevice = 0x0078, .config = ALC880_6ST_DIG },
    16802125        { .pci_subvendor = 0x1025, .pci_subdevice = 0x0087, .config = ALC880_6ST_DIG },
    1681         { .pci_subvendor = 0x1297, .pci_subdevice = 0xc790, .config = ALC880_6ST_DIG }, /* Shuttle ST20G5 */
     2126        { .pci_subvendor = 0x1297, .pci_subdevice = 0xc790, .config = ALC880_6ST_DIG }, /* Shuttle ST20G5 */
     2127        { .pci_subvendor = 0x1509, .pci_subdevice = 0x925d, .config = ALC880_6ST_DIG }, /* FIC P4M-915GD1 */
    16822128
    16832129        { .modelname = "asus", .config = ALC880_ASUS },
     
    16922138        { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
    16932139        { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
    1694         { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
     2140        { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
     2141        { .pci_subvendor = 0x1043, .pci_subdevice = 0x8181, .config = ALC880_ASUS_DIG }, /* ASUS P4GPL-X */
    16952142        { .pci_subvendor = 0x1558, .pci_subdevice = 0x5401, .config = ALC880_ASUS_DIG2 },
    16962143
    16972144        { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
    1698         { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },     
     2145        { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },
    16992146
    17002147        { .modelname = "F1734", .config = ALC880_F1734 },
    17012148        { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
    17022149        { .pci_subvendor = 0x1584, .pci_subdevice = 0x9054, .config = ALC880_F1734 },
     2150
     2151        { .modelname = "lg", .config = ALC880_LG },
     2152        { .pci_subvendor = 0x1854, .pci_subdevice = 0x003b, .config = ALC880_LG },
     2153        { .modelname = "lg-lw", .config = ALC880_LG_LW },
     2154        { .pci_subvendor = 0x1854, .pci_subdevice = 0x0018, .config = ALC880_LG_LW },
    17032155
    17042156#ifdef CONFIG_SND_DEBUG
     
    18782330                .channel_mode = alc880_threestack_modes,
    18792331                .input_mux = &alc880_capture_source,
    1880         },
     2332        },
     2333        [ALC880_LG] = {
     2334            .mixers = { alc880_lg_mixer },
     2335            .init_verbs = { alc880_volume_init_verbs,
     2336            alc880_lg_init_verbs },
     2337            .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
     2338            .dac_nids = alc880_lg_dac_nids,
     2339            .dig_out_nid = ALC880_DIGOUT_NID,
     2340            .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
     2341            .channel_mode = alc880_lg_ch_modes,
     2342            .input_mux = &alc880_lg_capture_source,
     2343            .unsol_event = alc880_lg_unsol_event,
     2344            .init_hook = alc880_lg_automute,
     2345        },
     2346        [ALC880_LG_LW] = {
     2347            .mixers = { alc880_lg_lw_mixer },
     2348            .init_verbs = { alc880_volume_init_verbs,
     2349            alc880_lg_lw_init_verbs },
     2350            .num_dacs = 1,
     2351            .dac_nids = alc880_dac_nids,
     2352            .dig_out_nid = ALC880_DIGOUT_NID,
     2353            .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
     2354            .channel_mode = alc880_2_jack_modes,
     2355            .input_mux = &alc880_lg_lw_capture_source,
     2356            .unsol_event = alc880_lg_lw_unsol_event,
     2357            .init_hook = alc880_lg_lw_automute,
     2358        },
    18812359#ifdef CONFIG_SND_DEBUG
    18822360        [ALC880_TEST] = {
     
    20432521        if (alc880_is_fixed_pin(pin)) {
    20442522                nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
    2045                 if (! spec->multiout.dac_nids[0]) {
    2046                         /* use this as the primary output */
    2047                         spec->multiout.dac_nids[0] = nid;
    2048                         if (! spec->multiout.num_dacs)
    2049                                 spec->multiout.num_dacs = 1;
    2050                 } else
    2051                         /* specify the DAC as the extra output */
    2052                         spec->multiout.hp_nid = nid;
     2523                /* specify the DAC as the extra output */
     2524                if (! spec->multiout.hp_nid)
     2525                    spec->multiout.hp_nid = nid;
     2526                else
     2527                    spec->multiout.extra_out_nid[0] = nid;
    20532528                /* control HP volume/switch on the output mixer amp */
    20542529                nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
     
    20632538        } else if (alc880_is_multi_pin(pin)) {
    20642539                /* set manual connection */
    2065                 if (! spec->multiout.dac_nids[0]) {
    2066                         /* use this as the primary output */
    2067                         spec->multiout.dac_nids[0] = alc880_idx_to_dac(alc880_multi_pin_idx(pin));
    2068                         if (! spec->multiout.num_dacs)
    2069                                 spec->multiout.num_dacs = 1;
    2070                 }
    20712540                /* we have only a switch on HP-out PIN */
    20722541                sprintf(name, "%s Playback Switch", pfx);
     
    21522621        hda_nid_t pin;
    21532622
    2154         pin = spec->autocfg.speaker_pin;
     2623        pin = spec->autocfg.speaker_pins[0];
    21552624        if (pin) /* connect to front */
    21562625                alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
     
    21872656        if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
    21882657                                                alc880_ignore)) < 0)
    2189                 return err;
    2190         if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
    2191             ! spec->autocfg.hp_pin)
    2192                 return 0; /* can't find valid BIOS pin config */
     2658            return err;
     2659        if (! spec->autocfg.line_outs)
     2660            return 0; /* can't find valid BIOS pin config */
    21932661
    21942662        if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
    2195             (err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
    2196             (err = alc880_auto_create_extra_out(spec, spec->autocfg.speaker_pin,
    2197                                                 "Speaker")) < 0 ||
    2198             (err = alc880_auto_create_extra_out(spec, spec->autocfg.speaker_pin,
     2663            (err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
     2664            (err = alc880_auto_create_extra_out(spec,
     2665                                                spec->autocfg.speaker_pins[0],
     2666                                                "Speaker")) < 0 ||
     2667            (err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pin,
    21992668                                                "Headphone")) < 0 ||
    22002669            (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
     
    22182687}
    22192688
    2220 /* init callback for auto-configuration model -- overriding the default init */
    2221 static int alc880_auto_init(struct hda_codec *codec)
    2222 {
    2223         alc_init(codec);
    2224         alc880_auto_init_multi_out(codec);
    2225         alc880_auto_init_extra_out(codec);
    2226         alc880_auto_init_analog_input(codec);
    2227         return 0;
     2689/* additional initialization for auto-configuration model */
     2690static void alc880_auto_init(struct hda_codec *codec)
     2691{
     2692    alc880_auto_init_multi_out(codec);
     2693    alc880_auto_init_extra_out(codec);
     2694    alc880_auto_init_analog_input(codec);
    22282695}
    22292696
     
    22912758
    22922759        codec->patch_ops = alc_patch_ops;
    2293         if (board_config == ALC880_AUTO)
    2294                 codec->patch_ops.init = alc880_auto_init;
     2760        if (board_config == ALC880_AUTO)
     2761            spec->init_hook = alc880_auto_init;
    22952762
    22962763        return 0;
     
    23202787        /* ADC1, 0 */
    23212788        0x05, 0x04
     2789};
     2790
     2791/* NIDs used when simultaneous access to both ADCs makes sense.  Note that
     2792 * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
     2793 */
     2794static hda_nid_t alc260_dual_adc_nids[2] = {
     2795        /* ADC0, ADC1 */
     2796        0x04, 0x05
    23222797};
    23232798
     
    23352810};
    23362811
    2337 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack
    2338  * and the internal CD lines.
     2812/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
     2813 * headphone jack and the internal CD lines.
    23392814 */
    23402815static struct hda_input_mux alc260_fujitsu_capture_source = {
    2341         .num_items = 2,
     2816        .num_items = 3,
    23422817        .items = {
    23432818                { "Mic/Line", 0x0 },
     2819                { "CD", 0x4 },
     2820                { "Headphone", 0x2 },
     2821        },
     2822};
     2823
     2824/* Acer TravelMate(/Extensa/Aspire) notebooks have similar configutation to
     2825 * the Fujitsu S702x, but jacks are marked differently. We won't allow
     2826 * retasking the Headphone jack, so it won't be available here.
     2827 */
     2828static struct hda_input_mux alc260_acer_capture_source = {
     2829        .num_items = 3,
     2830        .items = {
     2831                { "Mic", 0x0 },
     2832                { "Line", 0x2 },
    23442833                { "CD", 0x4 },
    23452834        },
     
    23632852 * HP_3013: hp_3013 + input + capture
    23642853 * fujitsu: fujitsu + capture
     2854 * acer: acer + capture
    23652855 */
    23662856
     
    23732863        HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
    23742864        {0} /* end */
    2375 };     
     2865};
    23762866
    23772867static struct snd_kcontrol_new alc260_input_mixer[] = {
     
    24082898        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
    24092899        HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
    2410         ALC_PINCTL_SWITCH("Headphone Amp Switch", 0x14, PIN_HP_AMP),
     2900        ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
    24112901        HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
    24122902        HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
    24132903        HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
    24142904        HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
     2905        ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
    24152906        HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
    24162907        HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
    24172908        HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
    24182909        HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
     2910        {0} /* end */
     2911};
     2912
     2913static struct snd_kcontrol_new alc260_acer_mixer[] = {
     2914        HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     2915        HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
     2916        HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     2917        HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     2918        HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
     2919        HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
     2920        ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
     2921        HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
     2922        HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
     2923        ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
     2924        HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
     2925        HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
    24192926        {0} /* end */
    24202927};
     
    24762983        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
    24772984        /* select line-out */
    2478         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
     2985        {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
    24792986        /* LINE-OUT pin */
    24802987        {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     
    26293136        /* Headphone/Line-out jack connects to Line1 pin; make it an output */
    26303137        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
    2631         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
    2632         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
    2633         /* Ensure all other unused pins are disabled and muted.
    2634          * Note: trying to set widget 0x15 to anything blocks all audio
    2635          * output for some reason, so just leave that at the default.
     3138        /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
     3139        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     3140        /* Ensure all other unused pins are disabled and muted. */
     3141        {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3142        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3143        {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3144        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3145        {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3146        {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3147        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3148        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3149
     3150        /* Disable digital (SPDIF) pins */
     3151        {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3152        {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3153
     3154        /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
     3155         * when acting as an output.
    26363156         */
    2637         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
    2638         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3157        {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
     3158
     3159        /* Start with output sum widgets muted and their output gains at min */
     3160        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3161        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3162        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3163        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3164        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3165        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3166        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3167        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3168        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3169
     3170        /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
     3171        {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3172        /* Unmute Line1 pin widget output buffer since it starts as an output.
     3173         * If the pin mode is changed by the user the pin mode control will
     3174         * take care of enabling the pin's input/output buffers as needed.
     3175         * Therefore there's no need to enable the input buffer at this
     3176         * stage.
     3177         */
     3178        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3179        /* Unmute input buffer of pin widget used for Line-in (no equiv
     3180         * mixer ctrl)
     3181         */
     3182        {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     3183
     3184        /* Mute capture amp left and right */
     3185        {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3186        /* Set ADC connection select to match default mixer setting - line
     3187         * in (on mic1 pin)
     3188         */
     3189        {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
     3190
     3191        /* Do the same for the second ADC: mute capture input amp and
     3192         * set ADC connection to line in (on mic1 pin)
     3193         */
     3194        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3195        {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
     3196
     3197        /* Mute all inputs to mixer widget (even unconnected ones) */
     3198        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
     3199        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
     3200        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
     3201        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
     3202        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
     3203        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
     3204        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
     3205        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
     3206
     3207        {0}
     3208};
     3209
     3210/* Initialisation sequence for ALC260 as configured in Acer TravelMate and
     3211 * similar laptops (adapted from Fujitsu init verbs).
     3212 */
     3213static struct hda_verb alc260_acer_init_verbs[] = {
     3214        /* On TravelMate laptops, GPIO 0 enables the internal speaker and
     3215         * the headphone jack.  Turn this on and rely on the standard mute
     3216         * methods whenever the user wants to turn these outputs off.
     3217         */
     3218        {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
     3219        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
     3220        {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
     3221        /* Internal speaker/Headphone jack is connected to Line-out pin */
     3222        {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     3223        /* Internal microphone/Mic jack is connected to Mic1 pin */
     3224        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
     3225        /* Line In jack is connected to Line1 pin */
     3226        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
     3227        /* Ensure all other unused pins are disabled and muted. */
     3228        {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3229        {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    26393230        {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
    2640         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3231        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    26413232        {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
    2642         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    2643         /* Disable digital (SPDIF) pins */
    2644         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
    2645         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
    2646 
    2647         /* Start with mixer outputs muted */
    2648         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
    2649         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
    2650         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
    2651 
    2652         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
    2653         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    2654         /* Unmute Line1 pin widget amp left and right (no equiv mixer ctrl) */
    2655         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    2656         /* Unmute pin widget used for Line-in (no equiv mixer ctrl) */
    2657         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    2658 
    2659         /* Mute capture amp left and right */
    2660         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    2661         /* Set ADC connection select to line in (on mic1 pin) */
    2662         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
    2663 
    2664         /* Mute all inputs to mixer widget (even unconnected ones) */
    2665         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
    2666         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
    2667         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
    2668         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
    2669         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
    2670         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
    2671         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
    2672         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
     3233        {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3234        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
     3235        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3236        /* Disable digital (SPDIF) pins */
     3237        {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3238        {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3239
     3240        /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
     3241         * bus when acting as outputs.
     3242         */
     3243        {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
     3244        {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
     3245
     3246        /* Start with output sum widgets muted and their output gains at min */
     3247        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3248        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3249        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3250        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3251        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3252        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3253        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3254        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3255        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3256
     3257        /* Unmute Line-out pin widget amp left and right (no equiv mixer ctrl) */
     3258        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3259        /* Unmute Mic1 and Line1 pin widget input buffers since they start as
     3260         * inputs. If the pin mode is changed by the user the pin mode control
     3261         * will take care of enabling the pin's input/output buffers as needed.
     3262         * Therefore there's no need to enable the input buffer at this
     3263         * stage.
     3264         */
     3265        {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     3266        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     3267
     3268        /* Mute capture amp left and right */
     3269        {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3270        /* Set ADC connection select to match default mixer setting - mic
     3271         * (on mic1 pin)
     3272         */
     3273        {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
     3274
     3275        /* Do similar with the second ADC: mute capture input amp and
     3276         * set ADC connection to line (on line1 pin)
     3277         */
     3278        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3279        {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
     3280
     3281        /* Mute all inputs to mixer widget (even unconnected ones) */
     3282        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
     3283        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
     3284        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
     3285        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
     3286        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
     3287        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
     3288        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
     3289        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
    26733290
    26743291        {0}
    26753292};
     3293
     3294/* Test configuration for debugging, modelled after the ALC880 test
     3295 * configuration.
     3296 */
     3297#ifdef CONFIG_SND_DEBUG
     3298static hda_nid_t alc260_test_dac_nids[1] = {
     3299        0x02,
     3300};
     3301static hda_nid_t alc260_test_adc_nids[2] = {
     3302        0x04, 0x05,
     3303};
     3304/* This is a bit messy since the two input muxes in the ALC260 have slight
     3305 * variations in their signal assignments.  The ideal way to deal with this
     3306 * is to extend alc_spec.input_mux to allow a different input MUX for each
     3307 * ADC.  For the purposes of the test model it's sufficient to just list
     3308 * both options for affected signal indices.  The separate input mux
     3309 * functionality only needs to be considered if a model comes along which
     3310 * actually uses signals 0x5, 0x6 and 0x7 for something which makes sense to
     3311 * record.
     3312 */
     3313static struct hda_input_mux alc260_test_capture_source = {
     3314        .num_items = 8,
     3315        .items = {
     3316                { "MIC1 pin", 0x0 },
     3317                { "MIC2 pin", 0x1 },
     3318                { "LINE1 pin", 0x2 },
     3319                { "LINE2 pin", 0x3 },
     3320                { "CD pin", 0x4 },
     3321                { "LINE-OUT pin (cap1), Mixer (cap2)", 0x5 },
     3322                { "HP-OUT pin (cap1), LINE-OUT pin (cap2)", 0x6 },
     3323                { "HP-OUT pin (cap2 only)", 0x7 },
     3324        },
     3325};
     3326static struct snd_kcontrol_new alc260_test_mixer[] = {
     3327        /* Output driver widgets */
     3328        HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
     3329        HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
     3330        HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
     3331        HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
     3332        HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
     3333        HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
     3334
     3335        /* Modes for retasking pin widgets */
     3336        ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
     3337        ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
     3338        ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
     3339        ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
     3340        ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
     3341        ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
     3342
     3343        /* Loopback mixer controls */
     3344        HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
     3345        HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
     3346        HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
     3347        HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
     3348        HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
     3349        HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
     3350        HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
     3351        HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
     3352        HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
     3353        HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
     3354        HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
     3355        HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
     3356        HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
     3357        HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
     3358        HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
     3359        HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
     3360
     3361        /* Controls for GPIO pins, assuming they are configured as outputs */
     3362        ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
     3363        ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
     3364        ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
     3365        ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
     3366
     3367        /* Switches to allow the digital IO pins to be enabled.  The datasheet
     3368         * is ambigious as to which NID is which; testing on laptops which
     3369         * make this output available should provide clarification.
     3370         */
     3371        ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
     3372        ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
     3373
     3374        {0} /* end */
     3375};
     3376static struct hda_verb alc260_test_init_verbs[] = {
     3377        /* Enable all GPIOs as outputs with an initial value of 0 */
     3378        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
     3379        {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
     3380        {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
     3381
     3382        /* Enable retasking pins as output, initially without power amp */
     3383        {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3384        {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3385        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3386        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3387        {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3388        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
     3389
     3390        /* Disable digital (SPDIF) pins initially, but users can enable
     3391         * them via a mixer switch.  In the case of SPDIF-out, this initverb
     3392         * payload also sets the generation to 0, output to be in "consumer"
     3393         * PCM format, copyright asserted, no pre-emphasis and no validity
     3394         * control.
     3395         */
     3396        {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3397        {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
     3398
     3399        /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
     3400         * OUT1 sum bus when acting as an output.
     3401         */
     3402        {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
     3403        {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
     3404        {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
     3405        {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
     3406
     3407        /* Start with output sum widgets muted and their output gains at min */
     3408        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3409        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3410        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3411        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3412        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3413        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3414        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3415        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
     3416        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
     3417
     3418        /* Unmute retasking pin widget output buffers since the default
     3419         * state appears to be output.  As the pin mode is changed by the
     3420         * user the pin mode control will take care of enabling the pin's
     3421         * input/output buffers as needed.
     3422         */
     3423        {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3424        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3425        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3426        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3427        {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3428        {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3429        /* Also unmute the mono-out pin widget */
     3430        {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     3431
     3432        /* Mute capture amp left and right */
     3433        {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3434        /* Set ADC connection select to match default mixer setting (mic1
     3435         * pin)
     3436         */
     3437        {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
     3438
     3439        /* Do the same for the second ADC: mute capture input amp and
     3440         * set ADC connection to mic1 pin
     3441         */
     3442        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
     3443        {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
     3444
     3445        /* Mute all inputs to mixer widget (even unconnected ones) */
     3446        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
     3447        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
     3448        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
     3449        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
     3450        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
     3451        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
     3452        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
     3453        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
     3454
     3455        {0}
     3456};
     3457#endif
    26763458
    26773459static struct hda_pcm_stream alc260_pcm_analog_playback = {
     
    27163498        } else
    27173499                return 0; /* N/A */
    2718        
    2719         sprintf(name, "%s Playback Volume", pfx);
     3500
     3501        sprintf(name, /*sizeof(name), */"%s Playback Volume", pfx);
    27203502        if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val)) < 0)
    27213503                return err;
    2722         sprintf(name, "%s Playback Switch", pfx);
     3504        sprintf(name, /*sizeof(name), */"%s Playback Switch", pfx);
    27233505        if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val)) < 0)
    27243506                return err;
     
    27443526        }
    27453527
    2746         nid = cfg->speaker_pin;
     3528        nid = cfg->speaker_pins[0];
    27473529        if (nid) {
    27483530                err = alc260_add_playback_controls(spec, nid, "Speaker");
     
    27573539                        return err;
    27583540        }
    2759         return 0;       
     3541        return 0;
    27603542}
    27613543
     
    28043586                snd_hda_codec_write(codec, idx + 0x0b, 0,
    28053587                                    AC_VERB_SET_CONNECT_SEL, sel_idx);
    2806                                    
     3588
    28073589        }
    28083590}
     
    28133595        hda_nid_t nid;
    28143596
    2815         nid = spec->autocfg.line_out_pins[0];   
     3597        nid = spec->autocfg.line_out_pins[0];
    28163598        if (nid)
    28173599                alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
    2818        
    2819         nid = spec->autocfg.speaker_pin;
     3600
     3601        nid = spec->autocfg.speaker_pins[0];
    28203602        if (nid)
    28213603                alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
     
    28243606        if (nid)
    28253607                alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
    2826 }       
     3608}
    28273609
    28283610#define ALC260_PIN_CD_NID               0x16
     
    28553637        {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
    28563638        {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    2857        
     3639
    28583640        /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
    28593641         * mixer widget
     
    28833665        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    28843666        {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
    2885        
     3667
    28863668        {0}
    28873669};
     
    29323714}
    29333715
    2934 /* init callback for auto-configuration model -- overriding the default init */
    2935 static int alc260_auto_init(struct hda_codec *codec)
    2936 {
    2937         alc_init(codec);
    2938         alc260_auto_init_multi_out(codec);
    2939         alc260_auto_init_analog_input(codec);
    2940         return 0;
     3716/* additional initialization for auto-configuration model */
     3717static void alc260_auto_init(struct hda_codec *codec)
     3718{
     3719    alc260_auto_init_multi_out(codec);
     3720    alc260_auto_init_analog_input(codec);
    29413721}
    29423722
     
    29473727        { .modelname = "basic", .config = ALC260_BASIC },
    29483728        { .pci_subvendor = 0x104d, .pci_subdevice = 0x81bb,
    2949           .config = ALC260_BASIC }, /* Sony VAIO */
     3729        .config = ALC260_BASIC }, /* Sony VAIO */
     3730        { .pci_subvendor = 0x152d, .pci_subdevice = 0x0729,
     3731        .config = ALC260_BASIC }, /* CTL Travel Master U553W */
    29503732        { .modelname = "hp", .config = ALC260_HP },
    29513733        { .pci_subvendor = 0x103c, .pci_subdevice = 0x3010, .config = ALC260_HP },
     
    29583740        { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702X },
    29593741        { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702X },
     3742        { .modelname = "acer", .config = ALC260_ACER },
     3743        { .pci_subvendor = 0x1025, .pci_subdevice = 0x008f, .config = ALC260_ACER },
     3744#ifdef CONFIG_SND_DEBUG
     3745        { .modelname = "test", .config = ALC260_TEST },
     3746#endif
    29603747        { .modelname = "auto", .config = ALC260_AUTO },
    2961         {0}
     3748        {0}
    29623749};
    29633750
     
    30093796                .num_dacs = ARRAY_SIZE(alc260_dac_nids),
    30103797                .dac_nids = alc260_dac_nids,
    3011                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
    3012                 .adc_nids = alc260_adc_nids,
     3798                .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
     3799                .adc_nids = alc260_dual_adc_nids,
    30133800                .num_channel_mode = ARRAY_SIZE(alc260_modes),
    30143801                .channel_mode = alc260_modes,
    30153802                .input_mux = &alc260_fujitsu_capture_source,
    30163803        },
     3804        [ALC260_ACER] = {
     3805                .mixers = { alc260_acer_mixer,
     3806                            alc260_capture_mixer },
     3807                .init_verbs = { alc260_acer_init_verbs },
     3808                .num_dacs = ARRAY_SIZE(alc260_dac_nids),
     3809                .dac_nids = alc260_dac_nids,
     3810                .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
     3811                .adc_nids = alc260_dual_adc_nids,
     3812                .num_channel_mode = ARRAY_SIZE(alc260_modes),
     3813                .channel_mode = alc260_modes,
     3814                .input_mux = &alc260_acer_capture_source,
     3815        },
     3816#ifdef CONFIG_SND_DEBUG
     3817        [ALC260_TEST] = {
     3818                .mixers = { alc260_test_mixer,
     3819                            alc260_capture_mixer },
     3820                .init_verbs = { alc260_test_init_verbs },
     3821                .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
     3822                .dac_nids = alc260_test_dac_nids,
     3823                .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
     3824                .adc_nids = alc260_test_adc_nids,
     3825                .num_channel_mode = ARRAY_SIZE(alc260_modes),
     3826                .channel_mode = alc260_modes,
     3827                .input_mux = &alc260_test_capture_source,
     3828        },
     3829#endif
    30173830};
    30183831
     
    30583871
    30593872        codec->patch_ops = alc_patch_ops;
    3060         if (board_config == ALC260_AUTO)
    3061                 codec->patch_ops.init = alc260_auto_init;
     3873        if (board_config == ALC260_AUTO)
     3874            spec->init_hook = alc260_auto_init;
    30623875
    30633876        return 0;
     
    34174230 */
    34184231static struct hda_board_config alc882_cfg_tbl[] = {
    3419         { .modelname = "3stack-dig", .config = ALC861_3ST_DIG },
    3420         { .modelname = "6stack-dig", .config = ALC861_6ST_DIG },
     4232        { .modelname = "3stack-dig", .config = ALC882_3ST_DIG },
     4233        { .modelname = "6stack-dig", .config = ALC882_6ST_DIG },
    34214234        { .pci_subvendor = 0x1462, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* MSI  */
    34224235        { .pci_subvendor = 0x105b, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* Foxconn */
    34234236        { .pci_subvendor = 0x1019, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* ECS */
    3424         { .modelname = "auto", .config = ALC861_AUTO },
     4237        { .modelname = "auto", .config = ALC882_AUTO },
    34254238        {0}
    34264239};
     
    34654278        /* set as output */
    34664279        struct alc_spec *spec = codec->spec;
    3467         int idx; 
    3468        
     4280        int idx;
     4281
    34694282        if (spec->multiout.dac_nids[dac_idx] == 0x25)
    34704283                idx = 4;
     
    34844297
    34854298        for (i = 0; i <= HDA_SIDE; i++) {
    3486                 hda_nid_t nid = spec->autocfg.line_out_pins[i]; 
     4299                hda_nid_t nid = spec->autocfg.line_out_pins[i];
    34874300                if (nid)
    34884301                        alc882_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
     
    35344347}
    35354348
    3536 /* init callback for auto-configuration model -- overriding the default init */
    3537 static int alc882_auto_init(struct hda_codec *codec)
    3538 {
    3539         alc_init(codec);
    3540         alc882_auto_init_multi_out(codec);
    3541         alc882_auto_init_hp_out(codec);
    3542         alc882_auto_init_analog_input(codec);
    3543         return 0;
     4349/* additional initialization for auto-configuration model */
     4350static void alc882_auto_init(struct hda_codec *codec)
     4351{
     4352    alc882_auto_init_multi_out(codec);
     4353    alc882_auto_init_hp_out(codec);
     4354    alc882_auto_init_analog_input(codec);
    35444355}
    35454356
     
    36074418
    36084419        codec->patch_ops = alc_patch_ops;
    3609         if (board_config == ALC882_AUTO)
    3610                 codec->patch_ops.init = alc882_auto_init;
     4420        if (board_config == ALC882_AUTO)
     4421            spec->init_hook = alc882_auto_init;
    36114422
    36124423        return 0;
     
    36444455        HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
    36454456        HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
    3646         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
    3647         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
    3648         {
    3649                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    3650                 .name = "Capture Source",
    3651                 .count = 1,
    3652                 .info = alc882_mux_enum_info,
    3653                 .get = alc882_mux_enum_get,
    3654                 .put = alc882_mux_enum_put,
    3655         },
    36564457        {0} /* end */
    3657 };                     
    3658        
     4458};
     4459
    36594460#define alc262_capture_mixer            alc882_capture_mixer
    36604461#define alc262_capture_alt_mixer        alc882_capture_alt_mixer
     
    37144515        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
    37154516        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
    3716        
     4517
    37174518        {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
    37184519        {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
    3719        
     4520
    37204521        /* FIXME: use matrix-type input source selection */
    37214522        /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
     
    37344535        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
    37354536        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
    3736         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},     
     4537        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
    37374538
    37384539        {0}
     4540};
     4541
     4542/*
     4543 * fujitsu model
     4544 *  0x14 = headphone/spdif-out, 0x15 = internal speaker
     4545 */
     4546
     4547#define ALC_HP_EVENT    0x37
     4548
     4549static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
     4550        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
     4551        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
     4552        {0}
     4553};
     4554
     4555static struct hda_input_mux alc262_fujitsu_capture_source = {
     4556        .num_items = 2,
     4557        .items = {
     4558                { "Mic", 0x0 },
     4559                { "CD", 0x4 },
     4560        },
     4561};
     4562
     4563/* mute/unmute internal speaker according to the hp jack and mute state */
     4564static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
     4565{
     4566        struct alc_spec *spec = codec->spec;
     4567        unsigned int mute;
     4568
     4569        if (force || ! spec->sense_updated) {
     4570                unsigned int present;
     4571                /* need to execute and sync at first */
     4572                snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
     4573                present = snd_hda_codec_read(codec, 0x14, 0,
     4574                                         AC_VERB_GET_PIN_SENSE, 0);
     4575                spec->jack_present = (present & 0x80000000) != 0;
     4576                spec->sense_updated = 1;
     4577        }
     4578        if (spec->jack_present) {
     4579                /* mute internal speaker */
     4580                snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
     4581                                         0x80, 0x80);
     4582                snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
     4583                                         0x80, 0x80);
     4584        } else {
     4585                /* unmute internal speaker if necessary */
     4586                mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
     4587                snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
     4588                                         0x80, mute & 0x80);
     4589                mute = snd_hda_codec_amp_read(codec, 0x14, 1, HDA_OUTPUT, 0);
     4590                snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
     4591                                         0x80, mute & 0x80);
     4592        }
     4593}
     4594
     4595/* unsolicited event for HP jack sensing */
     4596static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
     4597                                       unsigned int res)
     4598{
     4599        if ((res >> 26) != ALC_HP_EVENT)
     4600                return;
     4601        alc262_fujitsu_automute(codec, 1);
     4602}
     4603
     4604/* bind volumes of both NID 0x0c and 0x0d */
     4605static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
     4606                                         struct snd_ctl_elem_value *ucontrol)
     4607{
     4608        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     4609        long *valp = ucontrol->value.integer.value;
     4610        int change;
     4611
     4612        change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
     4613                                          0x7f, valp[0] & 0x7f);
     4614        change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
     4615                                           0x7f, valp[1] & 0x7f);
     4616        snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
     4617                                 0x7f, valp[0] & 0x7f);
     4618        snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
     4619                                 0x7f, valp[1] & 0x7f);
     4620        return change;
     4621}
     4622
     4623/* bind hp and internal speaker mute (with plug check) */
     4624static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
     4625                                         struct snd_ctl_elem_value *ucontrol)
     4626{
     4627        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     4628        long *valp = ucontrol->value.integer.value;
     4629        int change;
     4630
     4631        change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
     4632                                          0x80, valp[0] ? 0 : 0x80);
     4633        change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
     4634                                           0x80, valp[1] ? 0 : 0x80);
     4635        if (change || codec->in_resume)
     4636                alc262_fujitsu_automute(codec, codec->in_resume);
     4637        return change;
     4638}
     4639
     4640static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
     4641        {
     4642                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     4643                .name = "Master Playback Volume",
     4644                .info = snd_hda_mixer_amp_volume_info,
     4645                .get = snd_hda_mixer_amp_volume_get,
     4646                .put = alc262_fujitsu_master_vol_put,
     4647                .private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
     4648        },
     4649        {
     4650                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     4651                .name = "Master Playback Switch",
     4652                .info = snd_hda_mixer_amp_switch_info,
     4653                .get = snd_hda_mixer_amp_switch_get,
     4654                .put = alc262_fujitsu_master_sw_put,
     4655                .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
     4656        },
     4657        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
     4658        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
     4659        HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
     4660        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
     4661        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
     4662        {0} /* end */
    37394663};
    37404664
     
    37594683        }
    37604684
    3761         nid = cfg->speaker_pin;
     4685        nid = cfg->speaker_pins[0];
    37624686        if (nid) {
    37634687                if (nid == 0x16) {
    3764                         if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Speaker Playback Volume",
    3765                                                HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
    3766                                 return err;
    37674688                        if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
    37684689                                               HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
     
    37894710                                return err;
    37904711                } else {
    3791                         if (! cfg->line_out_pins[0])
    3792                                 if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
    3793                                                HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
    3794                                         return err;
    37954712                        if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
    37964713                                               HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
     
    37984715                }
    37994716        }
    3800         return 0;       
     4717        return 0;
    38014718}
    38024719
     
    38374754        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
    38384755        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
    3839        
     4756
    38404757        /* set up input amps for analog loopback */
    38414758        /* Amp Indices: DAC = 0, mixer = 1 */
     
    38854802        if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
    38864803                                                alc262_ignore)) < 0)
    3887                 return err;
    3888         if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
    3889             ! spec->autocfg.hp_pin)
     4804            return err;
     4805        if (! spec->autocfg.line_outs)
    38904806                return 0; /* can't find valid BIOS pin config */
    38914807        if ((err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
     
    39154831
    39164832/* init callback for auto-configuration model -- overriding the default init */
    3917 static int alc262_auto_init(struct hda_codec *codec)
    3918 {
    3919         alc_init(codec);
    3920         alc262_auto_init_multi_out(codec);
    3921         alc262_auto_init_hp_out(codec);
    3922         alc262_auto_init_analog_input(codec);
    3923         return 0;
     4833static void alc262_auto_init(struct hda_codec *codec)
     4834{
     4835    alc262_auto_init_multi_out(codec);
     4836    alc262_auto_init_hp_out(codec);
     4837    alc262_auto_init_analog_input(codec);
    39244838}
    39254839
     
    39294843static struct hda_board_config alc262_cfg_tbl[] = {
    39304844        { .modelname = "basic", .config = ALC262_BASIC },
     4845        { .modelname = "fujitsu", .config = ALC262_FUJITSU },
     4846        { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1397, .config = ALC262_FUJITSU },
    39314847        { .modelname = "auto", .config = ALC262_AUTO },
    3932         {0}
     4848        {0}
    39334849};
    39344850
     
    39434859                .channel_mode = alc262_modes,
    39444860                .input_mux = &alc262_capture_source,
     4861        },
     4862        [ALC262_FUJITSU] = {
     4863                .mixers = { alc262_fujitsu_mixer },
     4864                .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
     4865                .num_dacs = ARRAY_SIZE(alc262_dac_nids),
     4866                .dac_nids = alc262_dac_nids,
     4867                .hp_nid = 0x03,
     4868                .dig_out_nid = ALC262_DIGOUT_NID,
     4869                .num_channel_mode = ARRAY_SIZE(alc262_modes),
     4870                .channel_mode = alc262_modes,
     4871                .input_mux = &alc262_fujitsu_capture_source,
     4872                .unsol_event = alc262_fujitsu_unsol_event,
    39454873        },
    39464874};
     
    39924920        spec->stream_analog_playback = &alc262_pcm_analog_playback;
    39934921        spec->stream_analog_capture = &alc262_pcm_analog_capture;
    3994                
     4922
    39954923        spec->stream_name_digital = "ALC262 Digital";
    39964924        spec->stream_digital_playback = &alc262_pcm_digital_playback;
     
    40164944
    40174945        codec->patch_ops = alc_patch_ops;
    4018         if (board_config == ALC262_AUTO)
    4019                 codec->patch_ops.init = alc262_auto_init;
    4020        
     4946        if (board_config == ALC262_AUTO)
     4947            spec->init_hook = alc262_auto_init;
     4948
    40214949        return 0;
    40224950}
     
    40875015        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
    40885016        HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
    4089  
     5017
    40905018        /* Capture mixer control */
    40915019        HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
     
    41215049        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
    41225050        HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
    4123  
     5051
    41245052        /* Capture mixer control */
    41255053        HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
     
    41425070        },
    41435071        {0} /* end */
    4144 };                     
    4145        
     5072};
     5073
    41465074/*
    41475075 * generic initialization of ADC, input mixers and output mixers
     
    41785106        {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
    41795107        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    4180        
     5108
    41815109        /* Unmute DAC0~3 & spdif out*/
    41825110        {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
     
    41855113        {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    41865114        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    4187        
     5115
    41885116        /* Unmute Mixer 14 (mic) 1c (Line in)*/
    41895117        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    41915119        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    41925120        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
    4193        
     5121
    41945122        /* Unmute Stereo Mixer 15 */
    41955123        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    42465174        {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    42475175        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    4248        
     5176
    42495177        /* Unmute Mixer 14 (mic) 1c (Line in)*/
    42505178        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    42525180        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    42535181        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
    4254        
     5182
    42555183        /* Unmute Stereo Mixer 15 */
    42565184        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    42805208//      {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
    42815209        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    4282        
     5210
    42835211        /* Unmute DAC0~3 & spdif out*/
    42845212        {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
     
    42875215        {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
    42885216        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
    4289        
     5217
    42905218        /* Unmute Mixer 14 (mic) 1c (Line in)*/
    42915219        {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    42935221        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
    42945222        {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
    4295        
     5223
    42965224        /* Unmute Stereo Mixer 15 */
    42975225        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
     
    43115239        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    43125240        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
    4313         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},   
    4314         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},           
     5241        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
     5242        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
    43155243        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
    43165244        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
    4317         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},   
    4318         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},   
     5245        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
     5246        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
    43195247
    43205248        {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  // set Mic 1
     
    44465374                case 0x0d:
    44475375                        idx1 = 0;
    4448                         idx = 1;        // Mic In 
     5376                        idx = 1;        // Mic In
    44495377                        break;
    4450                 case 0x10:     
     5378                case 0x10:
    44515379                        idx1 = 3;
    4452                         idx = 1;        // Mic In 
     5380                        idx = 1;        // Mic In
    44535381                        break;
    44545382                case 0x11:
     
    44675395                imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
    44685396                imux->items[imux->num_items].index = idx1;
    4469                 imux->num_items++;     
     5397                imux->num_items++;
    44705398        }
    44715399        return 0;
     
    45485476        if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
    45495477                                                alc861_ignore)) < 0)
    4550                 return err;
    4551         if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
    4552             ! spec->autocfg.hp_pin)
    4553                 return 0; /* can't find valid BIOS pin config */
     5478            return err;
     5479        if (! spec->autocfg.line_outs)
     5480            return 0; /* can't find valid BIOS pin config */
    45545481
    45555482        if ((err = alc861_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
     
    45795506}
    45805507
    4581 /* init callback for auto-configuration model -- overriding the default init */
    4582 static int alc861_auto_init(struct hda_codec *codec)
    4583 {
    4584         alc_init(codec);
    4585         alc861_auto_init_multi_out(codec);
    4586         alc861_auto_init_hp_out(codec);
    4587         alc861_auto_init_analog_input(codec);
    4588 
    4589         return 0;
     5508/* additional initialization for auto-configuration model */
     5509static void alc861_auto_init(struct hda_codec *codec)
     5510{
     5511    alc861_auto_init_multi_out(codec);
     5512    alc861_auto_init_hp_out(codec);
     5513    alc861_auto_init_analog_input(codec);
     5514
    45905515}
    45915516
     
    46395564                .input_mux = &alc861_capture_source,
    46405565        },
    4641 };     
     5566};
    46425567
    46435568
     
    46525577                return -ENOMEM;
    46535578
    4654         codec->spec = spec;     
     5579        codec->spec = spec;
    46555580
    46565581        board_config = snd_hda_check_board_config(codec, alc861_cfg_tbl);
     
    46845609
    46855610        codec->patch_ops = alc_patch_ops;
    4686         if (board_config == ALC861_AUTO)
    4687                 codec->patch_ops.init = alc861_auto_init;
    4688                
     5611        if (board_config == ALC861_AUTO)
     5612            spec->init_hook = alc861_auto_init;
     5613
    46895614        return 0;
    46905615}
  • GPL/trunk/alsa-kernel/pci/hda/patch_si3054.c

    r69 r76  
    297297struct hda_codec_preset snd_hda_preset_si3054[] = {
    298298        { .id = 0x163c3055, .name = "Si3054", .patch = patch_si3054 },
    299         { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 },
     299        { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 },
     300        { .id = 0x11c13026, .name = "Si3054", .patch = patch_si3054 },
    300301        {0}
    301302};
  • GPL/trunk/alsa-kernel/pci/hda/patch_sigmatel.c

    r69 r76  
    5050        unsigned int surr_switch: 1;
    5151        unsigned int line_switch: 1;
    52         unsigned int mic_switch: 1;
     52        unsigned int mic_switch: 1;
     53        unsigned int alt_switch: 1;
     54        unsigned int hp_detect: 1;
    5355
    5456        /* playback */
    55         struct hda_multi_out multiout;
    56         hda_nid_t dac_nids[4];
     57        struct hda_multi_out multiout;
     58        hda_nid_t dac_nids[5];
    5759
    5860        /* capture */
     
    7375
    7476        /* capture source */
    75         struct hda_input_mux *input_mux;
    76         unsigned int cur_mux[2];
     77        struct hda_input_mux *input_mux;
     78        unsigned int cur_mux[3];
    7779
    7880        /* i/o switches */
     
    108110};
    109111
     112static hda_nid_t stac927x_adc_nids[3] = {
     113    0x07, 0x08, 0x09
     114};
     115
     116static hda_nid_t stac927x_mux_nids[3] = {
     117    0x15, 0x16, 0x17
     118};
     119
    110120static hda_nid_t stac9200_pin_nids[8] = {
    111121        0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
     
    115125        0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
    116126        0x0f, 0x10, 0x11, 0x15, 0x1b,
     127};
     128
     129static hda_nid_t stac927x_pin_nids[14] = {
     130    0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
     131    0x0f, 0x10, 0x11, 0x12, 0x13,
     132    0x14, 0x21, 0x22, 0x23,
    117133};
    118134
     
    151167
    152168static struct hda_verb stac922x_core_init[] = {
    153         /* set master volume and direct control */     
     169        /* set master volume and direct control */
    154170        { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
    155171        {0}
     172};
     173
     174static struct hda_verb stac927x_core_init[] = {
     175    /* set master volume and direct control */
     176    { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
     177    {0}
    156178};
    157179
     
    189211};
    190212
     213static snd_kcontrol_new_t stac927x_mixer[] = {
     214    {
     215        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     216        .name = "Input Source",
     217        .count = 1,
     218        .info = stac92xx_mux_enum_info,
     219        .get = stac92xx_mux_enum_get,
     220        .put = stac92xx_mux_enum_put,
     221    },
     222    HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
     223    HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
     224    HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
     225    {0} /* end */
     226};
     227
    191228static int stac92xx_build_controls(struct hda_codec *codec)
    192229{
     
    215252                        return err;
    216253        }
    217         return 0;       
     254        return 0;
    218255}
    219256
     
    242279
    243280static unsigned int d945gtp3_pin_configs[10] = {
    244         0x0221401f, 0x01a19022, 0x01813021, 0x01114010,
    245         0x40000100, 0x40000100, 0x40000100, 0x40000100,
    246         0x02a19120, 0x40000100,
     281    0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
     282    0x40000100, 0x40000100, 0x40000100, 0x40000100,
     283    0x02a19120, 0x40000100,
    247284};
    248285
    249286static unsigned int d945gtp5_pin_configs[10] = {
    250         0x0221401f, 0x01111012, 0x01813024, 0x01114010,
    251         0x01a19021, 0x01116011, 0x01452130, 0x40000100,
    252         0x02a19320, 0x40000100,
     287    0x0221401f, 0x01011012, 0x01813024, 0x01014010,
     288    0x01a19021, 0x01016011, 0x01452130, 0x40000100,
     289    0x02a19320, 0x40000100,
    253290};
    254291
     
    267304          .pci_subdevice = 0x0101,
    268305          .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
    269         { .pci_subvendor = PCI_VENDOR_ID_INTEL,
     306          { .pci_subvendor = PCI_VENDOR_ID_INTEL,
     307          .pci_subdevice = 0x0202,
     308          .config = STAC_D945GTP3 },    /* Intel D945GNT - 3 Stack, 9221 A1 */
     309          { .pci_subvendor = PCI_VENDOR_ID_INTEL,
     310          .pci_subdevice = 0x0b0b,
     311          .config = STAC_D945GTP3 },    /* Intel D945PSN - 3 Stack, 9221 A1 */
     312          { .pci_subvendor = PCI_VENDOR_ID_INTEL,
    270313          .pci_subdevice = 0x0404,
    271314          .config = STAC_D945GTP5 },    /* Intel D945GTP - 5 Stack */
     
    275318        { .pci_subvendor = PCI_VENDOR_ID_INTEL,
    276319          .pci_subdevice = 0x0013,
    277           .config = STAC_D945GTP5 },    /* Intel D955XBK - 5 Stack */
     320          .config = STAC_D945GTP5 },    /* Intel D955XBK - 5 Stack */
     321        { .pci_subvendor = PCI_VENDOR_ID_INTEL,
     322          .pci_subdevice = 0x0417,
     323          .config = STAC_D945GTP5 },    /* Intel D975XBK - 5 Stack */
    278324        {0} /* terminator */
     325};
     326
     327static unsigned int ref927x_pin_configs[14] = {
     328    0x01813122, 0x01a19021, 0x01014010, 0x01016011,
     329    0x01012012, 0x01011014, 0x40000100, 0x40000100,
     330    0x40000100, 0x40000100, 0x40000100, 0x01441030,
     331    0x01c41030, 0x40000100,
     332};
     333
     334static unsigned int *stac927x_brd_tbl[] = {
     335    ref927x_pin_configs,
     336};
     337
     338static struct hda_board_config stac927x_cfg_tbl[] = {
     339    { .modelname = "ref",
     340    .pci_subvendor = PCI_VENDOR_ID_INTEL,
     341    .pci_subdevice = 0x2668,      /* DFI LanParty */
     342    .config = STAC_REF },         /* SigmaTel reference board */
     343    {0} /* terminator */
    279344};
    280345
     
    300365                pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
    301366                                             AC_VERB_GET_CONFIG_DEFAULT,
    302                                              0x00);     
     367                                             0x00);
    303368                snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
    304369        }
     
    410475};
    411476
     477static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
     478    .substreams = 1,
     479    .channels_min = 2,
     480    .channels_max = 2,
     481    .nid = 0x06, /* NID to query formats and rates */
     482    .ops = {
     483        .open = stac92xx_playback_pcm_open,
     484        .prepare = stac92xx_playback_pcm_prepare,
     485        .cleanup = stac92xx_playback_pcm_cleanup
     486    },
     487};
     488
    412489static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
    413490        .substreams = 2,
    414491        .channels_min = 2,
    415         .channels_max = 2,
    416         .nid = 0x06, /* NID to query formats and rates */
     492        .channels_max = 2,
     493        /* NID is set in stac92xx_build_pcms */
    417494        .ops = {
    418495                .prepare = stac92xx_capture_pcm_prepare,
     
    432509        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
    433510        info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
    434 
     511        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
     512
     513        if (spec->alt_switch) {
     514            codec->num_pcms++;
     515            info++;
     516            info->name = "STAC92xx Analog Alt";
     517            info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
     518        }
    435519        if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
    436520                codec->num_pcms++;
     
    450534}
    451535
     536static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
     537{
     538    unsigned int pincap = snd_hda_param_read(codec, nid,
     539                                             AC_PAR_PIN_CAP);
     540    pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
     541    if (pincap & AC_PINCAP_VREF_100)
     542        return AC_PINCTL_VREF_100;
     543    if (pincap & AC_PINCAP_VREF_80)
     544        return AC_PINCTL_VREF_80;
     545    if (pincap & AC_PINCAP_VREF_50)
     546        return AC_PINCTL_VREF_50;
     547    if (pincap & AC_PINCAP_VREF_GRD)
     548        return AC_PINCTL_VREF_GRD;
     549    return 0;
     550}
     551
    452552static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
    453553
     
    486586
    487587        if (val)
    488                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
    489         else
    490                 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
     588            stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
     589        else {
     590            unsigned int pinctl = AC_PINCTL_IN_EN;
     591            if (io_idx) /* set VREF for mic */
     592                pinctl |= stac92xx_get_vref(codec, nid);
     593            stac92xx_auto_set_pinctl(codec, nid, pinctl);
     594        }
    491595
    492596        return 1;
     
    590694}
    591695
     696/*
     697 * XXX The line_out pin widget connection list may not be set to the
     698 * desired DAC nid. This is the case on 927x where ports A and B can
     699 * be routed to several DACs.
     700 *
     701 * This requires an analysis of the line-out/hp pin configuration
     702 * to provide a best fit for pin/DAC configurations that are routable.
     703 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
     704 * A and B is not supported.
     705 */
    592706/* fill in the dac_nids table from the parsed pin configuration */
    593707static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
     
    604718        }
    605719
    606         spec->multiout.num_dacs = cfg->line_outs;
     720        spec->multiout.num_dacs = cfg->line_outs;
    607721
    608722        return 0;
     
    672786                return 0;
    673787
    674         wid_caps = get_wcaps(codec, pin);
    675         if (wid_caps & AC_WCAP_UNSOL_CAP)
     788        wid_caps = get_wcaps(codec, pin);
     789        if (wid_caps & AC_WCAP_UNSOL_CAP) {
    676790                /* Enable unsolicited responses on the HP widget */
    677791                snd_hda_codec_write(codec, pin, 0,
    678792                                AC_VERB_SET_UNSOLICITED_ENABLE,
    679                                 STAC_UNSOL_ENABLE);
     793                                    STAC_UNSOL_ENABLE);
     794                spec->hp_detect = 1;
     795        }
    680796
    681797        nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
     
    711827                int index = -1;
    712828                if (cfg->input_pins[i]) {
    713                         /* Enable active pin widget as an input */
    714                         stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
    715 
    716829                        imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
    717830
     
    755868}
    756869
    757 static int stac922x_parse_auto_config(struct hda_codec *codec)
     870static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
    758871{
    759872        struct sigmatel_spec *spec = codec->spec;
     
    761874
    762875        if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
    763                 return err;
     876            return err;
     877        if (! spec->autocfg.line_outs)
     878            return 0; /* can't find valid pin config */
    764879        if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
    765880                return err;
    766881        if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
    767882                return err;
    768         if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
    769                 return 0; /* can't find valid pin config */
    770883
    771884        if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
     
    778891                spec->surr_switch = 1;
    779892
    780         if (spec->autocfg.dig_out_pin) {
    781                 spec->multiout.dig_out_nid = 0x08;
    782                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
    783         }
    784         if (spec->autocfg.dig_in_pin) {
    785                 spec->dig_in_nid = 0x09;
    786                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
    787         }
     893        if (spec->autocfg.dig_out_pin)
     894            spec->multiout.dig_out_nid = dig_out;
     895        if (spec->autocfg.dig_in_pin)
     896            spec->dig_in_nid = dig_in;
    788897
    789898        if (spec->kctl_alloc)
     
    795904}
    796905
     906/* add playback controls for HP output */
     907static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
     908                                        struct auto_pin_cfg *cfg)
     909{
     910    struct sigmatel_spec *spec = codec->spec;
     911    hda_nid_t pin = cfg->hp_pin;
     912    unsigned int wid_caps;
     913
     914    if (! pin)
     915        return 0;
     916
     917    wid_caps = get_wcaps(codec, pin);
     918    if (wid_caps & AC_WCAP_UNSOL_CAP) {
     919        /* Enable unsolicited responses on the HP widget */
     920        snd_hda_codec_write(codec, pin, 0,
     921                            AC_VERB_SET_UNSOLICITED_ENABLE,
     922                            STAC_UNSOL_ENABLE);
     923        spec->hp_detect = 1;
     924    }
     925
     926    return 0;
     927}
     928
    797929static int stac9200_parse_auto_config(struct hda_codec *codec)
    798930{
     
    806938                return err;
    807939
    808         if (spec->autocfg.dig_out_pin) {
    809                 spec->multiout.dig_out_nid = 0x05;
    810                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
    811         }
    812         if (spec->autocfg.dig_in_pin) {
    813                 spec->dig_in_nid = 0x04;
    814                 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
    815         }
     940        if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
     941            return err;
     942
     943        if (spec->autocfg.dig_out_pin)
     944            spec->multiout.dig_out_nid = 0x05;
     945        if (spec->autocfg.dig_in_pin)
     946            spec->dig_in_nid = 0x04;
    816947
    817948        if (spec->kctl_alloc)
     
    825956static int stac92xx_init(struct hda_codec *codec)
    826957{
    827         struct sigmatel_spec *spec = codec->spec;
    828 
    829         snd_hda_sequence_write(codec, spec->init);
    830 
    831         stac92xx_auto_init_multi_out(codec);
    832         stac92xx_auto_init_hp_out(codec);
    833 
    834         return 0;
     958    struct sigmatel_spec *spec = codec->spec;
     959    struct auto_pin_cfg *cfg = &spec->autocfg;
     960    int i;
     961
     962    snd_hda_sequence_write(codec, spec->init);
     963
     964    /* set up pins */
     965    if (spec->hp_detect) {
     966        /* fake event to set up pins */
     967        codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
     968    } else {
     969        stac92xx_auto_init_multi_out(codec);
     970        stac92xx_auto_init_hp_out(codec);
     971    }
     972    for (i = 0; i < AUTO_PIN_LAST; i++) {
     973        hda_nid_t nid = cfg->input_pins[i];
     974        if (nid) {
     975            unsigned int pinctl = AC_PINCTL_IN_EN;
     976            if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
     977                pinctl |= stac92xx_get_vref(codec, nid);
     978            stac92xx_auto_set_pinctl(codec, nid, pinctl);
     979        }
     980    }
     981    if (cfg->dig_out_pin)
     982        stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
     983                                 AC_PINCTL_OUT_EN);
     984    if (cfg->dig_in_pin)
     985        stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
     986                                 AC_PINCTL_IN_EN);
     987
     988    return 0;
    835989}
    836990
     
    8971051                stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
    8981052        }
    899 } 
     1053}
    9001054
    9011055#ifdef CONFIG_PM
     
    9981152        spec->multiout.dac_nids = spec->dac_nids;
    9991153
    1000         err = stac922x_parse_auto_config(codec);
    1001         if (err < 0) {
     1154        err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
     1155        if (err < 0) {
     1156            stac92xx_free(codec);
     1157            return err;
     1158        }
     1159
     1160        codec->patch_ops = stac92xx_patch_ops;
     1161
     1162        return 0;
     1163}
     1164
     1165static int patch_stac927x(struct hda_codec *codec)
     1166{
     1167    struct sigmatel_spec *spec;
     1168    int err;
     1169
     1170    spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
     1171    if (spec == NULL)
     1172        return -ENOMEM;
     1173
     1174    codec->spec = spec;
     1175    spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
     1176    if (spec->board_config < 0)
     1177        snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
     1178    else {
     1179        spec->num_pins = 14;
     1180        spec->pin_nids = stac927x_pin_nids;
     1181        spec->pin_configs = stac927x_brd_tbl[spec->board_config];
     1182        stac92xx_set_config_regs(codec);
     1183    }
     1184
     1185    spec->adc_nids = stac927x_adc_nids;
     1186    spec->mux_nids = stac927x_mux_nids;
     1187    spec->num_muxes = 3;
     1188
     1189    spec->init = stac927x_core_init;
     1190    spec->mixer = stac927x_mixer;
     1191
     1192    spec->multiout.dac_nids = spec->dac_nids;
     1193
     1194                 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
     1195        if (err < 0) {
    10021196                stac92xx_free(codec);
    10031197                return err;
     
    10101204
    10111205/*
     1206 * STAC 7661(?) hack
     1207 */
     1208
     1209/* static config for Sony VAIO FE550G */
     1210static hda_nid_t vaio_dacs[] = { 0x2 };
     1211#define VAIO_HP_DAC     0x5
     1212static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
     1213static hda_nid_t vaio_mux_nids[] = { 0x15 };
     1214
     1215static struct hda_input_mux vaio_mux = {
     1216    .num_items = 2,
     1217    .items = {
     1218        /* { "HP", 0x0 },
     1219         { "Unknown", 0x1 }, */
     1220        { "Mic", 0x2 },
     1221        { "PCM", 0x3 },
     1222    }
     1223};
     1224
     1225static struct hda_verb vaio_init[] = {
     1226    {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
     1227    {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
     1228    {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
     1229    {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
     1230    {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
     1231    {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
     1232    {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
     1233    {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
     1234    {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
     1235    {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
     1236    {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
     1237    {0}
     1238};
     1239
     1240/* bind volumes of both NID 0x02 and 0x05 */
     1241static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
     1242                               struct snd_ctl_elem_value *ucontrol)
     1243{
     1244    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     1245    long *valp = ucontrol->value.integer.value;
     1246    int change;
     1247
     1248    change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
     1249                                      0x7f, valp[0] & 0x7f);
     1250    change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
     1251                                       0x7f, valp[1] & 0x7f);
     1252    snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
     1253                             0x7f, valp[0] & 0x7f);
     1254    snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
     1255                             0x7f, valp[1] & 0x7f);
     1256    return change;
     1257}
     1258
     1259/* bind volumes of both NID 0x02 and 0x05 */
     1260static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
     1261                              struct snd_ctl_elem_value *ucontrol)
     1262{
     1263    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
     1264    long *valp = ucontrol->value.integer.value;
     1265    int change;
     1266
     1267    change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
     1268                                      0x80, valp[0] & 0x80);
     1269    change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
     1270                                       0x80, valp[1] & 0x80);
     1271    snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
     1272                             0x80, valp[0] & 0x80);
     1273    snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
     1274                             0x80, valp[1] & 0x80);
     1275    return change;
     1276}
     1277
     1278static struct snd_kcontrol_new vaio_mixer[] = {
     1279    {
     1280        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1281        .name = "Master Playback Volume",
     1282        .info = snd_hda_mixer_amp_volume_info,
     1283        .get = snd_hda_mixer_amp_volume_get,
     1284        .put = vaio_master_vol_put,
     1285        .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
     1286    },
     1287    {
     1288        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1289        .name = "Master Playback Switch",
     1290        .info = snd_hda_mixer_amp_switch_info,
     1291        .get = snd_hda_mixer_amp_switch_get,
     1292        .put = vaio_master_sw_put,
     1293        .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
     1294    },
     1295    /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
     1296    HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
     1297    HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
     1298    {
     1299        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1300        .name = "Capture Source",
     1301        .count = 1,
     1302        .info = stac92xx_mux_enum_info,
     1303        .get = stac92xx_mux_enum_get,
     1304        .put = stac92xx_mux_enum_put,
     1305    },
     1306    {0}
     1307};
     1308
     1309static struct hda_codec_ops stac7661_patch_ops = {
     1310    .build_controls = stac92xx_build_controls,
     1311    .build_pcms = stac92xx_build_pcms,
     1312    .init = stac92xx_init,
     1313    .free = stac92xx_free,
     1314#ifdef CONFIG_PM
     1315    .resume = stac92xx_resume,
     1316#endif
     1317};
     1318
     1319enum { STAC7661_VAIO };
     1320
     1321static struct hda_board_config stac7661_cfg_tbl[] = {
     1322    { .modelname = "vaio", .config = STAC7661_VAIO },
     1323    { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
     1324    .config = STAC7661_VAIO },
     1325    { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
     1326    .config = STAC7661_VAIO },
     1327    {0}
     1328};
     1329
     1330static int patch_stac7661(struct hda_codec *codec)
     1331{
     1332    struct sigmatel_spec *spec;
     1333    int board_config;
     1334
     1335    board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
     1336    if (board_config < 0)
     1337        /* unknown config, let generic-parser do its job... */
     1338        return snd_hda_parse_generic_codec(codec);
     1339
     1340    spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
     1341    if (spec == NULL)
     1342        return -ENOMEM;
     1343
     1344    codec->spec = spec;
     1345    switch (board_config) {
     1346    case STAC7661_VAIO:
     1347        spec->mixer = vaio_mixer;
     1348        spec->init = vaio_init;
     1349        spec->multiout.max_channels = 2;
     1350        spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
     1351        spec->multiout.dac_nids = vaio_dacs;
     1352        spec->multiout.hp_nid = VAIO_HP_DAC;
     1353        spec->num_adcs = ARRAY_SIZE(vaio_adcs);
     1354        spec->adc_nids = vaio_adcs;
     1355        spec->input_mux = &vaio_mux;
     1356        spec->mux_nids = vaio_mux_nids;
     1357        break;
     1358    }
     1359
     1360    codec->patch_ops = stac7661_patch_ops;
     1361    return 0;
     1362}
     1363
     1364
     1365         /*
    10121366 * patch entries
    10131367 */
     
    10191373        { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
    10201374        { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
    1021         { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
     1375        { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
     1376        { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
     1377        { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
     1378        { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
     1379        { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
     1380        { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
     1381        { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
     1382        { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
     1383        { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
     1384        { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
     1385        { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
     1386        { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
    10221387        {0} /* terminator */
    10231388};
  • GPL/trunk/alsa-kernel/pci/intel8x0.c

    r70 r76  
    494494    { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE },    /* NFORCE3 */
    495495    { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE },        /* CK8S */
     496    { 0x10de, 0x026b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE },        /* MCP51 */
    496497    { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },     /* AMD8111 */
    497498    { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },     /* AMD768 */
     
    834835    unsigned int status;
    835836    unsigned int i;
     837#ifdef TARGET_OS2
     838    int fOurIrq = FALSE;
     839#endif
    836840
    837841    status = igetdword(chip, chip->int_sta_reg);
     
    854858#endif
    855859        }
    856         return IRQ_RETVAL(status);
    857     }
     860        return IRQ_NONE/*RETVAL(status)*/;
     861    }
     862#ifdef TARGET_OS2
     863    fOurIrq = TRUE;
     864#endif
    858865
    859866    for (i = 0; i < chip->bdbars_count; i++) {
     
    865872    /* ack them */
    866873    iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
     874#ifdef TARGET_OS2
     875    if (fOurIrq) {
     876        //eoi_irq(irq);
     877    }
     878#endif //TARGET_OS2
    867879
    868880    return IRQ_HANDLED;
     
    11611173        runtime->hw.period_bytes_max = 64*1024;
    11621174    }
     1175#if 1 /* vladest */
    11631176    if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
    11641177        return err;
     1178#endif
    11651179    runtime->private_data = ichdev;
    11661180    return 0;
     
    11751189    err = snd_intel8x0_pcm_open(substream, &chip->ichd[ICHD_PCMOUT]);
    11761190    if (err < 0)
     1191    {
     1192        printk("snd_intel8x0_pcm_open open error: %i\n", err);
    11771193        return err;
     1194    }
    11781195    if (chip->multi6) {
    11791196        runtime->hw.channels_max = 6;
     
    19882005                .name = "Fujitsu-Siemens D1522",        /* AD1981 */
    19892006                .type = AC97_TUNE_HP_ONLY
    1990         },
     2007        },
     2008        {
     2009            .subvendor = 0x8086,
     2010            .subdevice = 0x0104,
     2011            .name = "Intel D845GEBV2",              /* AD1981B */
     2012            .type = AC97_TUNE_HP_ONLY
     2013        },
    19912014        {
    19922015                .subvendor = 0x8086,
     
    23102333         */
    23112334        end_time = jiffies + HZ;
    2312         i = 0;
    23132335        do {
    2314             status = igetdword(chip, ICHREG(GLOB_STA)) & chip->codec_isr_bits;;
     2336            status = igetdword(chip, ICHREG(GLOB_STA)) &
     2337                chip->codec_isr_bits;
    23152338            if (status)
    23162339                break;
    23172340            mdelay(1);
    23182341            //do_delay(chip);
    2319             i++;
    2320         } while (i<100);/*(time_after_eq(end_time, jiffies));*/
     2342        } while (time_after_eq(end_time, jiffies));
    23212343
    23222344        if (! status) {
     
    24102432static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
    24112433{
    2412     unsigned int i;
     2434    unsigned int i, timeout;
    24132435    int err;
    24142436
     
    24282450    for (i = 0; i < chip->bdbars_count; i++)
    24292451        iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
     2452    for (i = 0; i < chip->bdbars_count; i++) {
     2453        timeout = 100000;
     2454        while (--timeout != 0) {
     2455            if ((igetbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset) & ICH_RESETREGS) == 0)
     2456                break;
     2457        }
     2458        if (timeout == 0)
     2459            printk(KERN_ERR "intel8x0: reset of registers failed?\n");
     2460    }
    24302461    /* initialize Buffer Descriptor Lists */
    24312462    for (i = 0; i < chip->bdbars_count; i++)
     
    26062637    iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
    26072638    spin_unlock_irq(&chip->reg_lock);
    2608 
     2639#if 0
    26092640    t = stop_time.tv_sec - start_time.tv_sec;
    26102641    t *= 1000000;
    26112642    t += stop_time.tv_usec - start_time.tv_usec;
     2643#else
     2644    t = 50000; /* patch, suggested by r.ihle */
     2645#endif
    26122646    printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t);
    26132647    if (t == 0) {
  • GPL/trunk/alsa-kernel/pci/maestro3.c

    r70 r76  
    830830
    831831    struct pci_dev *pci;
    832     struct m3_quirk *quirk;
    833     struct m3_hv_quirk *hv_quirk;
     832    const struct m3_quirk *quirk;
     833    const struct m3_hv_quirk *hv_quirk;
    834834
    835835    int dacs_active;
     
    918918
    919919MODULE_DEVICE_TABLE(pci, snd_m3_ids);
    920 #if 0
    921 struct m3_quirk {
    922     const char *name;   /* device name */
    923     u16 vendor, device; /* subsystem ids */
    924     int amp_gpio;               /* gpio pin #  for external amp, -1 = default */
    925     int irda_workaround;        /* non-zero if avoid to touch 0x10 on GPIO_DIRECTION
    926     (e.g. for IrDA on Dell Inspirons) */
    927 };
    928 #endif
    929 static struct m3_quirk m3_quirk_list[] = {
     920
     921static const struct m3_quirk m3_quirk_list[] = {
    930922    /* panasonic CF-28 "toughbook" */
    931923    {
    932         /*.name = */"Panasonic CF-28",
    933         /*.vendor = */0x10f7,
    934         /*.device = */0x833e,
    935         /*.amp_gpio = */0x0d,
    936         0
     924        .name = "Panasonic CF-28",
     925        .vendor = 0x10f7,
     926        .device = 0x833e,
     927        .amp_gpio = 0x0d,
    937928    },
    938929    /* panasonic CF-72 "toughbook" */
    939930    {
    940         /*.name = */"Panasonic CF-72",
    941         /*.vendor = */0x10f7,
    942         /*.device = */0x833d,
    943         /*.amp_gpio = */0x0d,
    944         0
     931        .name = "Panasonic CF-72",
     932        .vendor = 0x10f7,
     933        .device = 0x833d,
     934        .amp_gpio = 0x0d,
    945935    },
    946936    /* Dell Inspiron 4000 */
    947937    {
    948         /*.name = */"Dell Inspiron 4000",
    949         /*.vendor = */0x1028,
    950         /*.device = */0x00b0,
    951         /*.amp_gpio = */-1,
    952         /*.irda_workaround = */1,
     938        .name = "Dell Inspiron 4000",
     939        .vendor = 0x1028,
     940        .device = 0x00b0,
     941        .amp_gpio = -1,
     942        .irda_workaround = 1,
    953943    },
    954944    /* Dell Inspiron 8000 */
    955945    {
    956         /*.name = */"Dell Inspiron 8000",
    957         /*.vendor = */0x1028,
    958         /*.device = */0x00a4,
    959         /*.amp_gpio = */-1,
    960         /*.irda_workaround = */1,
     946        .name = "Dell Inspiron 8000",
     947        .vendor = 0x1028,
     948        .device = 0x00a4,
     949        .amp_gpio = -1,
     950        .irda_workaround = 1,
    961951    },
    962 #if 1
    963952    /* Dell Inspiron 8100 */
    964953    {
    965         /*.name = */"Dell Inspiron 8100",
    966         /*.vendor = */0x1028,
    967         /*.device = */0x00e6,
    968         /*.amp_gpio = */-1,
    969         /*.irda_workaround = */1,
     954        .name = "Dell Inspiron 8100",
     955        .vendor = 0x1028,
     956        .device = 0x00e6,
     957        .amp_gpio = -1,
     958        .irda_workaround = 1,
    970959    },
    971 #endif
    972960    /* NEC LM800J/7 */
    973961    {
    974         /*.name = */"NEC LM800J/7",
    975         /*.vendor = */0x1033,
    976         /*.device = */0x80f1,
    977         /*.amp_gpio = */0x03,
    978         0
     962        .name = "NEC LM800J/7",
     963        .vendor = 0x1033,
     964        .device = 0x80f1,
     965        .amp_gpio = 0x03,
    979966    },
    980967    /* LEGEND ZhaoYang 3100CF */
    981968    {
    982         "LEGEND ZhaoYang 3100CF",
    983         0x1509,
    984         0x1740,
    985         0x03,
    986         0
     969        .name = "LEGEND ZhaoYang 3100CF",
     970        .vendor = 0x1509,
     971        .device = 0x1740,
     972        .amp_gpio = 0x03,
    987973    },
    988974    /* END */
    989     { 0 }
     975    { NULL }
    990976};
    991977
    992978/* These values came from the Windows driver. */
    993 static struct m3_hv_quirk m3_hv_quirk_list[] = {
     979static const struct m3_hv_quirk m3_hv_quirk_list[] = {
    994980    /* Allegro chips */
    995981    { 0x125D, 0x1988, 0x0E11, 0x002E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
     
    13981384}
    13991385
    1400 
    1401 static struct play_vals {
     1386static const struct play_vals {
    14021387    u16 addr, val;
    14031388} pv[] = {
     
    14651450 *    Native record driver
    14661451 */
    1467 static struct rec_vals {
     1452static const struct rec_vals {
    14681453    u16 addr, val;
    14691454} rv[] = {
     
    16351620        return;
    16361621
    1637     hwptr = snd_m3_get_pointer(chip, s, subs) % s->dma_size;
    1638     diff = (s->dma_size + hwptr - s->hwptr) % s->dma_size;
     1622    hwptr = snd_m3_get_pointer(chip, s, subs);
     1623    /* try to avoid expensive modulo divisions */
     1624    if (hwptr >= s->dma_size)
     1625        hwptr %= s->dma_size;
     1626
     1627    diff = s->dma_size + hwptr - s->hwptr;
     1628    if (diff >= s->dma_size)
     1629        diff %= s->dma_size;
     1630
    16391631    s->hwptr = hwptr;
    16401632    s->count += diff;
     1633
    16411634    if (s->count >= (signed)s->period_size) {
    1642         s->count %= s->period_size;
     1635        if (s->count < 2 * (signed)s->period_size)
     1636            s->count -= (signed)s->period_size;
     1637        else
     1638            s->count %= s->period_size;
     1639
    16431640        spin_unlock(&chip->reg_lock);
    16441641        snd_pcm_period_elapsed(subs);
     
    17151712    u8 status;
    17161713    int i;
    1717 #ifdef TARGET_OS2
    1718     int fOurIrq = FALSE;
    1719 #endif
    1720 #ifdef DEBUG
    1721     dprintf(("int"));
    1722 #endif
     1714
    17231715    status = inb(chip->iobase + HOST_INT_STATUS);
    1724 #ifdef DEBUG
    1725     dprintf(("%x",status));
    1726 #endif
    17271716
    17281717    if (status == 0xff)
    17291718        return IRQ_NONE;
    17301719
    1731 #ifdef TARGET_OS2
    1732     fOurIrq = TRUE;
    1733 #endif
    17341720    if (status & HV_INT_PENDING)
    17351721        tasklet_hi_schedule(&chip->hwvol_tq);
     
    17641750    /* ack ints */
    17651751    outb(status, chip->iobase + HOST_INT_STATUS);
    1766 #ifdef TARGET_OS2
    1767     if (fOurIrq) {
    1768         eoi_irq(irq);
    1769     }
    1770 #endif //TARGET_OS2
    1771 
    17721752    return IRQ_HANDLED;
    17731753}
     
    19961976        if (! (snd_m3_inb(chip, 0x30) & 1))
    19971977            return 0;
     1978        cpu_relax();
    19981979    } while (i-- > 0);
    19991980
     
    20071988    m3_t *chip = ac97->private_data;
    20081989    unsigned long flags;
    2009     unsigned short data;
     1990    unsigned short data = 0xffff;
    20101991
    20111992    if (snd_m3_ac97_wait(chip))
    2012         return 0xffff;
     1993        goto fail;
    20131994    spin_lock_irqsave(&chip->ac97_lock, flags);
    20141995    snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
    20151996    if (snd_m3_ac97_wait(chip))
    2016         return 0xffff;
     1997        goto fail_unlock;
    20171998    data = snd_m3_inw(chip, CODEC_DATA);
     1999fail_unlock:
    20182000    spin_unlock_irqrestore(&chip->ac97_lock, flags);
     2001fail:
    20192002    return data;
    20202003}
     
    21782161 */
    21792162
    2180 static u16 assp_kernel_image[] __devinitdata = {
     2163static const u16 assp_kernel_image[] __devinitdata = {
    21812164    0x7980, 0x0030, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x00FB, 0x7980, 0x00DD, 0x7980, 0x03B4,
    21822165    0x7980, 0x0332, 0x7980, 0x0287, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4,
     
    22652248 * that is to be loaded at 0x400 on the DSP.
    22662249 */
    2267 static u16 assp_minisrc_image[] __devinitdata = {
     2250static const u16 assp_minisrc_image[] __devinitdata = {
    22682251
    22692252    0xBF80, 0x101E, 0x906E, 0x006E, 0x8B88, 0x6980, 0xEF88, 0x906F, 0x0D6F, 0x6900, 0xEB08, 0x0412,
     
    23082291
    23092292#define MINISRC_LPF_LEN 10
    2310 static u16 minisrc_lpf[MINISRC_LPF_LEN] __devinitdata = {
     2293static const u16 minisrc_lpf[MINISRC_LPF_LEN] __devinitdata = {
    23112294    0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C,
    23122295    0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F
     
    24152398
    24162399    /*
    2417      * align instance address to 256 bytes so that it's
     2400     * align instance address to 256 bytes so that its
    24182401     * shifted list address is aligned.
    24192402     * list address = (mem address >> 1) >> 7;
     
    26982681    m3_t *chip;
    26992682    int i, err;
    2700     struct m3_quirk *quirk;
    2701     struct m3_hv_quirk *hv_quirk;
    2702 #ifdef TARGET_OS2
    2703     static snd_device_ops_t ops = {
    2704         snd_m3_dev_free,0,0,0
     2683    const struct m3_quirk *quirk;
     2684    const struct m3_hv_quirk *hv_quirk;
     2685    static struct snd_device_ops ops = {
     2686        .dev_free =     snd_m3_dev_free,
    27052687    };
    2706 #else
    2707     static snd_device_ops_t ops = {
    2708     dev_free:   snd_m3_dev_free,
    2709     };
    2710 #endif
    27112688
    27122689    *chip_ret = NULL;
     
    28542831
    28552832    pci_read_config_dword(pci, PCI_CLASS_REVISION, &pci->_class);
    2856 
    2857 #ifdef DEBUG
    2858     dprintf(("m3_probe. %x",pci->_class));
    2859 #endif
    28602833
    28612834#if 0   // os/2 doesnt pickup classes
     
    29122885        return err;
    29132886    }
    2914 #ifdef DEBUG
    2915     dprintf(("m3_probe: card registered"));
    2916 #endif
    29172887
    29182888#if 0 /* TODO: not supported yet */
    2919     /* TODO enable midi irq and i/o */
     2889    /* TODO enable MIDI IRQ and I/O */
    29202890    err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
    29212891                              chip->iobase + MPU401_DATA_PORT, 1,
    29222892                              chip->irq, 0, &chip->rmidi);
    29232893    if (err < 0)
    2924         printk(KERN_WARNING "maestro3: no midi support.\n");
     2894        printk(KERN_WARNING "maestro3: no MIDI support.\n");
    29252895#endif
    29262896
  • GPL/trunk/alsa-kernel/pci/nm256/nm256.c

    r32 r76  
    1 /*
     1/* 
    22 * Driver for NeoMagic 256AV and 256ZX chipsets.
    33 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
     
    2424 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    2525 */
    26 
     26 
    2727#include <sound/driver.h>
     28#include <asm/io.h>
     29#include <linux/delay.h>
     30#include <linux/interrupt.h>
     31#include <linux/init.h>
     32#include <linux/pci.h>
     33#include <linux/slab.h>
     34#include <linux/moduleparam.h>
     35#include <linux/mutex.h>
     36
     37#include <sound/core.h>
    2838#include <sound/info.h>
    2939#include <sound/control.h>
    3040#include <sound/pcm.h>
    3141#include <sound/ac97_codec.h>
    32 #define SNDRV_GET_ID
    3342#include <sound/initval.h>
    3443
     
    3948MODULE_DESCRIPTION("NeoMagic NM256AV/ZX");
    4049MODULE_LICENSE("GPL");
    41 MODULE_CLASSES("{sound}");
    42 MODULE_DEVICES("{{NeoMagic,NM256AV},"
    43                "{NeoMagic,NM256ZX}}");
     50MODULE_SUPPORTED_DEVICE("{{NeoMagic,NM256AV},"
     51                "{NeoMagic,NM256ZX}}");
    4452
    4553/*
     
    4755 */
    4856
    49 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    50 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    51 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
    52 static int playback_bufsize[SNDRV_CARDS] = {REPEAT_SNDRV(16)};
    53 static int capture_bufsize[SNDRV_CARDS] = {REPEAT_SNDRV(16)};
    54 static int force_ac97[SNDRV_CARDS] = {REPEAT_SNDRV(0)}; /* disabled as default */
    55 static int buffer_top[SNDRV_CARDS] = {REPEAT_SNDRV(0)}; /* not specified */
    56 static int use_cache[SNDRV_CARDS] = {REPEAT_SNDRV(0)}; /* disabled */
    57 static int vaio_hack[SNDRV_CARDS] = {REPEAT_SNDRV(0)}; /* disabled */
    58 static int reset_workaround[SNDRV_CARDS];
    59 
    60 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     57static int index = SNDRV_DEFAULT_IDX1;  /* Index */
     58static char *id = SNDRV_DEFAULT_STR1;   /* ID for this card */
     59static int playback_bufsize = 16;
     60static int capture_bufsize = 16;
     61static int force_ac97;                  /* disabled as default */
     62static int buffer_top;                  /* not specified */
     63static int use_cache;                   /* disabled */
     64static int vaio_hack;                   /* disabled */
     65static int reset_workaround;
     66static int reset_workaround_2;
     67
     68//module_param(index, int, 0444);
    6169MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
    62 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
    63 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
     70//module_param(id, charp, 0444);
    6471MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
    65 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
    66 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
    67 MODULE_PARM_DESC(enable, "Enable this soundcard.");
    68 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
    69 MODULE_PARM(playback_bufsize, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     72//module_param(playback_bufsize, int, 0444);
    7073MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard.");
    71 MODULE_PARM_SYNTAX(playback_bufsize, SNDRV_ENABLED);
    72 MODULE_PARM(capture_bufsize, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     74//module_param(capture_bufsize, int, 0444);
    7375MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard.");
    74 MODULE_PARM_SYNTAX(capture_bufsize, SNDRV_ENABLED);
    75 MODULE_PARM(force_ac97, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     76//module_param(force_ac97, bool, 0444);
    7677MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
    77 MODULE_PARM_SYNTAX(force_ac97, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    78 MODULE_PARM(buffer_top, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     78//module_param(buffer_top, int, 0444);
    7979MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard.");
    80 MODULE_PARM_SYNTAX(buffer_top, SNDRV_ENABLED);
    81 MODULE_PARM(use_cache, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     80//module_param(use_cache, bool, 0444);
    8281MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access.");
    83 MODULE_PARM_SYNTAX(use_cache, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    84 MODULE_PARM(vaio_hack, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     82//module_param(vaio_hack, bool, 0444);
    8583MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks.");
    86 MODULE_PARM_SYNTAX(vaio_hack, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    87 //module_param_array(reset_workaround, bool, boot_devs, 0444);
     84//module_param(reset_workaround, bool, 0444);
    8885MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops.");
     86//module_param(reset_workaround_2, bool, 0444);
     87MODULE_PARM_DESC(reset_workaround_2, "Enable extended AC97 RESET workaround for some other laptops.");
     88
     89/* just for backward compatibility */
     90static int enable;
     91//module_param(enable, bool, 0444);
     92
     93
     94/* nm256 */
     95#ifndef PCI_VENDOR_ID_NEOMAGIC
     96#define PCI_VENDOR_ID_NEOMEGIC          0x10c8
     97#endif
     98#ifndef PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO
     99#define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
     100#endif
     101#ifndef PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO
     102#define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
     103#endif
     104#ifndef PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO
     105#define PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO 0x8016
     106#endif
     107
    89108/*
    90109 * hw definitions
     
    180199#define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
    181200
    182 /*
    183  * type definitions
    184  */
    185 
    186 typedef struct snd_nm256 nm256_t;
    187 typedef struct snd_nm256_stream nm256_stream_t;
    188 
    189 struct snd_nm256_stream {
    190 
    191     nm256_t *chip;
    192     snd_pcm_substream_t *substream;
    193     int running;
    194     int suspended;
    195 
    196     u32 buf;    /* offset from chip->buffer */
    197     int bufsize;        /* buffer size in bytes */
    198     unsigned long bufptr;       /* mapped pointer */
    199     unsigned long bufptr_addr;  /* physical address of the mapped pointer */
    200 
    201     int dma_size;               /* buffer size of the substream in bytes */
    202     int period_size;    /* period size in bytes */
    203     int periods;                /* # of periods */
    204     int shift;  /* bit shifts */
    205     int cur_period;             /* current period # */
     201struct nm256_stream {
     202
     203        struct nm256 *chip;
     204        struct snd_pcm_substream *substream;
     205        int running;
     206        int suspended;
     207       
     208        u32 buf;        /* offset from chip->buffer */
     209        int bufsize;    /* buffer size in bytes */
     210        void __iomem *bufptr;           /* mapped pointer */
     211        unsigned long bufptr_addr;      /* physical address of the mapped pointer */
     212
     213        int dma_size;           /* buffer size of the substream in bytes */
     214        int period_size;        /* period size in bytes */
     215        int periods;            /* # of periods */
     216        int shift;              /* bit shifts */
     217        int cur_period;         /* current period # */
    206218
    207219};
    208220
    209 struct snd_nm256 {
    210 
    211     snd_card_t *card;
    212 
    213     unsigned long cport;                /* control port */
    214     struct resource *res_cport; /* its resource */
    215     unsigned long cport_addr;   /* physical address */
    216 
    217     unsigned long buffer;                       /* buffer */
    218     struct resource *res_buffer;        /* its resource */
    219     unsigned long buffer_addr;  /* buffer phyiscal address */
    220 
    221     u32 buffer_start;           /* start offset from pci resource 0 */
    222     u32 buffer_end;                     /* end offset */
    223     u32 buffer_size;            /* total buffer size */
    224 
    225     u32 all_coeff_buf;          /* coefficient buffer */
    226     u32 coeff_buf[2];           /* coefficient buffer for each stream */
    227 
    228     unsigned int coeffs_current: 1;     /* coeff. table is loaded? */
    229     unsigned int use_cache: 1;  /* use one big coef. table */
    230     unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
    231 
    232     int mixer_base;                     /* register offset of ac97 mixer */
    233     int mixer_status_offset;    /* offset of mixer status reg. */
    234     int mixer_status_mask;              /* bit mask to test the mixer status */
    235 
    236     int irq;
    237     int irq_acks;
    238     irqreturn_t (*interrupt)(int, void *, struct pt_regs *);
    239     int badintrcount;           /* counter to check bogus interrupts */
    240     struct semaphore irq_mutex;
    241 
    242     nm256_stream_t streams[2];
    243 
    244     ac97_t *ac97;
    245 
    246     snd_pcm_t *pcm;
    247 
    248     struct pci_dev *pci;
    249 
    250     spinlock_t reg_lock;
     221struct nm256 {
     222       
     223        struct snd_card *card;
     224
     225        void __iomem *cport;            /* control port */
     226        struct resource *res_cport;     /* its resource */
     227        unsigned long cport_addr;       /* physical address */
     228
     229        void __iomem *buffer;           /* buffer */
     230        struct resource *res_buffer;    /* its resource */
     231        unsigned long buffer_addr;      /* buffer phyiscal address */
     232
     233        u32 buffer_start;               /* start offset from pci resource 0 */
     234        u32 buffer_end;                 /* end offset */
     235        u32 buffer_size;                /* total buffer size */
     236
     237        u32 all_coeff_buf;              /* coefficient buffer */
     238        u32 coeff_buf[2];               /* coefficient buffer for each stream */
     239
     240        unsigned int coeffs_current: 1; /* coeff. table is loaded? */
     241        unsigned int use_cache: 1;      /* use one big coef. table */
     242        unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
     243        unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */
     244        unsigned int in_resume: 1;
     245
     246        int mixer_base;                 /* register offset of ac97 mixer */
     247        int mixer_status_offset;        /* offset of mixer status reg. */
     248        int mixer_status_mask;          /* bit mask to test the mixer status */
     249
     250        int irq;
     251        int irq_acks;
     252        irqreturn_t (*interrupt)(int, void *, struct pt_regs *);
     253        int badintrcount;               /* counter to check bogus interrupts */
     254        struct mutex irq_mutex;
     255
     256        struct nm256_stream streams[2];
     257
     258        struct snd_ac97 *ac97;
     259        unsigned short *ac97_regs; /* register caches, only for valid regs */
     260
     261        struct snd_pcm *pcm;
     262
     263        struct pci_dev *pci;
     264
     265        spinlock_t reg_lock;
    251266
    252267};
     
    262277 * PCI ids
    263278 */
    264 
    265 #ifndef PCI_VENDOR_ID_NEOMAGIC
    266 #define PCI_VENDOR_ID_NEOMEGIC 0x10c8
     279static struct pci_device_id snd_nm256_ids[] = {
     280        {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
     281        {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
     282        {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
     283        {0,},
     284};
     285
     286MODULE_DEVICE_TABLE(pci, snd_nm256_ids);
     287
     288
     289/*
     290 * lowlvel stuffs
     291 */
     292
     293static inline u8
     294snd_nm256_readb(struct nm256 *chip, int offset)
     295{
     296        return readb(chip->cport + offset);
     297}
     298
     299static inline u16
     300snd_nm256_readw(struct nm256 *chip, int offset)
     301{
     302        return readw(chip->cport + offset);
     303}
     304
     305static inline u32
     306snd_nm256_readl(struct nm256 *chip, int offset)
     307{
     308        return readl(chip->cport + offset);
     309}
     310
     311static inline void
     312snd_nm256_writeb(struct nm256 *chip, int offset, u8 val)
     313{
     314        writeb(val, chip->cport + offset);
     315}
     316
     317static inline void
     318snd_nm256_writew(struct nm256 *chip, int offset, u16 val)
     319{
     320        writew(val, chip->cport + offset);
     321}
     322
     323static inline void
     324snd_nm256_writel(struct nm256 *chip, int offset, u32 val)
     325{
     326        writel(val, chip->cport + offset);
     327}
     328
     329static inline void
     330snd_nm256_write_buffer(struct nm256 *chip, void *src, int offset, int size)
     331{
     332        offset -= chip->buffer_start;
     333#ifdef CONFIG_SND_DEBUG
     334        if (offset < 0 || offset >= chip->buffer_size) {
     335                snd_printk(KERN_ERR "write_buffer invalid offset = %d size = %d\n",
     336                           offset, size);
     337                return;
     338        }
    267339#endif
    268 #ifndef PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO
    269 #define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
    270 #endif
    271 #ifndef PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO
    272 #define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
    273 #endif
    274 
    275 
    276 static struct pci_device_id snd_nm256_ids[] = {
    277     {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
    278     {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
    279     {0,},
    280 };
    281 
    282 MODULE_DEVICE_TABLE(pci, snd_nm256_ids);
    283 
    284 
    285 /*
    286  * lowlvel stuffs
    287  */
    288 
    289 inline static u8
    290     snd_nm256_readb(nm256_t *chip, int offset)
    291 {
    292     return readb(chip->cport + offset);
    293 }
    294 
    295 inline static u16
    296 snd_nm256_readw(nm256_t *chip, int offset)
    297 {
    298     return readw(chip->cport + offset);
    299 }
    300 
    301 inline static u32
    302 snd_nm256_readl(nm256_t *chip, int offset)
    303 {
    304     return readl(chip->cport + offset);
    305 }
    306 
    307 inline static void
    308 snd_nm256_writeb(nm256_t *chip, int offset, u8 val)
    309 {
    310     writeb(val, chip->cport + offset);
    311 }
    312 
    313 inline static void
    314 snd_nm256_writew(nm256_t *chip, int offset, u16 val)
    315 {
    316     writew(val, chip->cport + offset);
    317 }
    318 
    319 inline static void
    320 snd_nm256_writel(nm256_t *chip, int offset, u32 val)
    321 {
    322     writel(val, chip->cport + offset);
    323 }
    324 
    325 inline static void
    326 snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size)
    327 {
    328     offset -= chip->buffer_start;
    329 #ifdef SNDRV_CONFIG_DEBUG
    330     if (offset < 0 || offset >= chip->buffer_size) {
    331         printk("nm256: write_buffer invalid offset = %d size = %d\n", offset, size);
    332         return;
    333     }
    334 #endif
    335     memcpy_toio(chip->buffer + offset, src, size);
     340        memcpy_toio(chip->buffer + offset, src, size);
    336341}
    337342
     
    343348snd_nm256_get_start_offset(int which)
    344349{
    345     u16 offset = 0;
    346     while (which-- > 0)
    347         offset += coefficient_sizes[which];
    348     return offset;
     350        u16 offset = 0;
     351        while (which-- > 0)
     352                offset += coefficient_sizes[which];
     353        return offset;
    349354}
    350355
    351356static void
    352 snd_nm256_load_one_coefficient(nm256_t *chip, int stream, u32 port, int which)
    353 {
    354     u32 coeff_buf = chip->coeff_buf[stream];
    355     u16 offset = snd_nm256_get_start_offset(which);
    356     u16 size = coefficient_sizes[which];
    357 
    358     snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size);
    359     snd_nm256_writel(chip, port, coeff_buf);
    360     /* ???  Record seems to behave differently than playback.  */
    361     if (stream == SNDRV_PCM_STREAM_PLAYBACK)
    362         size--;
    363     snd_nm256_writel(chip, port + 4, coeff_buf + size);
     357snd_nm256_load_one_coefficient(struct nm256 *chip, int stream, u32 port, int which)
     358{
     359        u32 coeff_buf = chip->coeff_buf[stream];
     360        u16 offset = snd_nm256_get_start_offset(which);
     361        u16 size = coefficient_sizes[which];
     362
     363        snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size);
     364        snd_nm256_writel(chip, port, coeff_buf);
     365        /* ???  Record seems to behave differently than playback.  */
     366        if (stream == SNDRV_PCM_STREAM_PLAYBACK)
     367                size--;
     368        snd_nm256_writel(chip, port + 4, coeff_buf + size);
    364369}
    365370
    366371static void
    367 snd_nm256_load_coefficient(nm256_t *chip, int stream, int number)
    368 {
    369     /* The enable register for the specified engine.  */
    370     u32 poffset = (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_ENABLE_REG : NM_PLAYBACK_ENABLE_REG);
    371     u32 addr = NM_COEFF_START_OFFSET;
    372 
    373     addr += (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET);
    374 
    375     if (snd_nm256_readb(chip, poffset) & 1) {
    376         snd_printd("NM256: Engine was enabled while loading coefficients!\n");
    377         return;
    378     }
    379 
    380     /* The recording engine uses coefficient values 8-15.  */
    381     number &= 7;
    382     if (stream == SNDRV_PCM_STREAM_CAPTURE)
    383         number += 8;
    384 
    385     if (! chip->use_cache) {
    386         snd_nm256_load_one_coefficient(chip, stream, addr, number);
    387         return;
    388     }
    389     if (! chip->coeffs_current) {
    390         snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf,
    391                                NM_TOTAL_COEFF_COUNT * 4);
    392         chip->coeffs_current = 1;
    393     } else {
    394         u32 base = chip->all_coeff_buf;
    395         u32 offset = snd_nm256_get_start_offset(number);
    396         u32 end_offset = offset + coefficient_sizes[number];
    397         snd_nm256_writel(chip, addr, base + offset);
    398         if (stream == SNDRV_PCM_STREAM_PLAYBACK)
    399             end_offset--;
    400         snd_nm256_writel(chip, addr + 4, base + end_offset);
    401     }
     372snd_nm256_load_coefficient(struct nm256 *chip, int stream, int number)
     373{
     374        /* The enable register for the specified engine.  */
     375        u32 poffset = (stream == SNDRV_PCM_STREAM_CAPTURE ?
     376                       NM_RECORD_ENABLE_REG : NM_PLAYBACK_ENABLE_REG);
     377        u32 addr = NM_COEFF_START_OFFSET;
     378
     379        addr += (stream == SNDRV_PCM_STREAM_CAPTURE ?
     380                 NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET);
     381
     382        if (snd_nm256_readb(chip, poffset) & 1) {
     383                snd_printd("NM256: Engine was enabled while loading coefficients!\n");
     384                return;
     385        }
     386
     387        /* The recording engine uses coefficient values 8-15.  */
     388        number &= 7;
     389        if (stream == SNDRV_PCM_STREAM_CAPTURE)
     390                number += 8;
     391
     392        if (! chip->use_cache) {
     393                snd_nm256_load_one_coefficient(chip, stream, addr, number);
     394                return;
     395        }
     396        if (! chip->coeffs_current) {
     397                snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf,
     398                                       NM_TOTAL_COEFF_COUNT * 4);
     399                chip->coeffs_current = 1;
     400        } else {
     401                u32 base = chip->all_coeff_buf;
     402                u32 offset = snd_nm256_get_start_offset(number);
     403                u32 end_offset = offset + coefficient_sizes[number];
     404                snd_nm256_writel(chip, addr, base + offset);
     405                if (stream == SNDRV_PCM_STREAM_PLAYBACK)
     406                        end_offset--;
     407                snd_nm256_writel(chip, addr + 4, base + end_offset);
     408        }
    402409}
    403410
     
    405412/* The actual rates supported by the card. */
    406413static unsigned int samplerates[8] = {
    407     8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
     414        8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000,
    408415};
    409 #define NUM_SAMPLERATES (sizeof(samplerates) / sizeof(samplerates[0]))
    410 static snd_pcm_hw_constraint_list_t constraints_rates = {
    411     NUM_SAMPLERATES,
    412     samplerates,
    413     0,
     416static struct snd_pcm_hw_constraint_list constraints_rates = {
     417        .count = ARRAY_SIZE(samplerates),
     418        .list = samplerates,
     419        .mask = 0,
    414420};
    415421
     
    420426snd_nm256_fixed_rate(unsigned int rate)
    421427{
    422     unsigned int i;
    423     for (i = 0; i < NUM_SAMPLERATES; i++) {
    424         if (rate == samplerates[i])
    425             return i;
    426     }
    427     snd_BUG();
    428     return 0;
     428        unsigned int i;
     429        for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
     430                if (rate == samplerates[i])
     431                        return i;
     432        }
     433        snd_BUG();
     434        return 0;
    429435}
    430436
     
    433439 */
    434440static void
    435 snd_nm256_set_format(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
    436 {
    437     snd_pcm_runtime_t *runtime = substream->runtime;
    438     int rate_index = snd_nm256_fixed_rate(runtime->rate);
    439     unsigned char ratebits = (rate_index << 4) & NM_RATE_MASK;
    440 
    441     s->shift = 0;
    442     if (snd_pcm_format_width(runtime->format) == 16) {
    443         ratebits |= NM_RATE_BITS_16;
    444         s->shift++;
    445     }
    446     if (runtime->channels > 1) {
    447         ratebits |= NM_RATE_STEREO;
    448         s->shift++;
    449     }
    450 
    451     runtime->rate = samplerates[rate_index];
    452 
    453     switch (substream->stream) {
    454     case SNDRV_PCM_STREAM_PLAYBACK:
    455         snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */
    456         snd_nm256_writeb(chip,
    457                          NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
    458                          ratebits);
    459         break;
    460     case SNDRV_PCM_STREAM_CAPTURE:
    461         snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */
    462         snd_nm256_writeb(chip,
    463                          NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
    464                          ratebits);
    465         break;
    466     }
     441snd_nm256_set_format(struct nm256 *chip, struct nm256_stream *s,
     442                     struct snd_pcm_substream *substream)
     443{
     444        struct snd_pcm_runtime *runtime = substream->runtime;
     445        int rate_index = snd_nm256_fixed_rate(runtime->rate);
     446        unsigned char ratebits = (rate_index << 4) & NM_RATE_MASK;
     447
     448        s->shift = 0;
     449        if (snd_pcm_format_width(runtime->format) == 16) {
     450                ratebits |= NM_RATE_BITS_16;
     451                s->shift++;
     452        }
     453        if (runtime->channels > 1) {
     454                ratebits |= NM_RATE_STEREO;
     455                s->shift++;
     456        }
     457
     458        runtime->rate = samplerates[rate_index];
     459
     460        switch (substream->stream) {
     461        case SNDRV_PCM_STREAM_PLAYBACK:
     462                snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */
     463                snd_nm256_writeb(chip,
     464                                 NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
     465                                 ratebits);
     466                break;
     467        case SNDRV_PCM_STREAM_CAPTURE:
     468                snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */
     469                snd_nm256_writeb(chip,
     470                                 NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
     471                                 ratebits);
     472                break;
     473        }
    467474}
    468475
    469476/* acquire interrupt */
    470 static int snd_nm256_acquire_irq(nm256_t *chip)
    471 {
    472     down(&chip->irq_mutex);
    473     if (chip->irq < 0) {
    474         if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ,
    475                         chip->card->driver, (void*)chip)) {
    476             snd_printk("unable to grab IRQ %d\n", chip->pci->irq);
    477             up(&chip->irq_mutex);
    478             return -EBUSY;
    479         }
    480         chip->irq = chip->pci->irq;
    481     }
    482     chip->irq_acks++;
    483     up(&chip->irq_mutex);
    484     return 0;
     477static int snd_nm256_acquire_irq(struct nm256 *chip)
     478{
     479        mutex_lock(&chip->irq_mutex);
     480        if (chip->irq < 0) {
     481                if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ,
     482                                chip->card->driver, chip)) {
     483                        snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->pci->irq);
     484                        mutex_unlock(&chip->irq_mutex);
     485                        return -EBUSY;
     486                }
     487                chip->irq = chip->pci->irq;
     488        }
     489        chip->irq_acks++;
     490        mutex_unlock(&chip->irq_mutex);
     491        return 0;
    485492}
    486493
    487494/* release interrupt */
    488 static void snd_nm256_release_irq(nm256_t *chip)
    489 {
    490     down(&chip->irq_mutex);
    491     if (chip->irq_acks > 0)
    492         chip->irq_acks--;
    493     if (chip->irq_acks == 0 && chip->irq >= 0) {
    494         free_irq(chip->irq, (void*)chip);
    495         chip->irq = -1;
    496     }
    497     up(&chip->irq_mutex);
     495static void snd_nm256_release_irq(struct nm256 *chip)
     496{
     497        mutex_lock(&chip->irq_mutex);
     498        if (chip->irq_acks > 0)
     499                chip->irq_acks--;
     500        if (chip->irq_acks == 0 && chip->irq >= 0) {
     501                free_irq(chip->irq, chip);
     502                chip->irq = -1;
     503        }
     504        mutex_unlock(&chip->irq_mutex);
    498505}
    499506
     
    503510
    504511/* update the watermark (current period) */
    505 static void snd_nm256_pcm_mark(nm256_t *chip, nm256_stream_t *s, int reg)
    506 {
    507     s->cur_period++;
    508     s->cur_period %= s->periods;
    509     snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size);
     512static void snd_nm256_pcm_mark(struct nm256 *chip, struct nm256_stream *s, int reg)
     513{
     514        s->cur_period++;
     515        s->cur_period %= s->periods;
     516        snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size);
    510517}
    511518
     
    514521
    515522static void
    516 snd_nm256_playback_start(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
    517 {
    518     /* program buffer pointers */
    519     snd_nm256_writel(chip, NM_PBUFFER_START, s->buf);
    520     snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift));
    521     snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf);
    522     snd_nm256_playback_mark(chip, s);
    523 
    524     /* Enable playback engine and interrupts. */
    525     snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG,
    526                      NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
    527     /* Enable both channels. */
    528     snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0);
     523snd_nm256_playback_start(struct nm256 *chip, struct nm256_stream *s,
     524                         struct snd_pcm_substream *substream)
     525{
     526        /* program buffer pointers */
     527        snd_nm256_writel(chip, NM_PBUFFER_START, s->buf);
     528        snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift));
     529        snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf);
     530        snd_nm256_playback_mark(chip, s);
     531
     532        /* Enable playback engine and interrupts. */
     533        snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG,
     534                         NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
     535        /* Enable both channels. */
     536        snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0);
    529537}
    530538
    531539static void
    532 snd_nm256_capture_start(nm256_t *chip, nm256_stream_t *s, snd_pcm_substream_t *substream)
    533 {
    534     /* program buffer pointers */
    535     snd_nm256_writel(chip, NM_RBUFFER_START, s->buf);
    536     snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size);
    537     snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf);
    538     snd_nm256_capture_mark(chip, s);
    539 
    540     /* Enable playback engine and interrupts. */
    541     snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG,
    542                      NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
     540snd_nm256_capture_start(struct nm256 *chip, struct nm256_stream *s,
     541                        struct snd_pcm_substream *substream)
     542{
     543        /* program buffer pointers */
     544        snd_nm256_writel(chip, NM_RBUFFER_START, s->buf);
     545        snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size);
     546        snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf);
     547        snd_nm256_capture_mark(chip, s);
     548
     549        /* Enable playback engine and interrupts. */
     550        snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG,
     551                         NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
    543552}
    544553
    545554/* Stop the play engine. */
    546555static void
    547 snd_nm256_playback_stop(nm256_t *chip)
    548 {
    549     /* Shut off sound from both channels. */
    550     snd_nm256_writew(chip, NM_AUDIO_MUTE_REG,
    551                     NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
    552     /* Disable play engine. */
    553     snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0);
     556snd_nm256_playback_stop(struct nm256 *chip)
     557{
     558        /* Shut off sound from both channels. */
     559        snd_nm256_writew(chip, NM_AUDIO_MUTE_REG,
     560                        NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
     561        /* Disable play engine. */
     562        snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0);
    554563}
    555564
    556565static void
    557 snd_nm256_capture_stop(nm256_t *chip)
    558 {
    559     /* Disable recording engine. */
    560     snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0);
     566snd_nm256_capture_stop(struct nm256 *chip)
     567{
     568        /* Disable recording engine. */
     569        snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0);
    561570}
    562571
    563572static int
    564 snd_nm256_playback_trigger(snd_pcm_substream_t *substream, int cmd)
    565 {
    566     nm256_t *chip = snd_pcm_substream_chip(substream);
    567     nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
    568     int err = 0;
    569 
    570     snd_assert(s != NULL, return -ENXIO);
    571 
    572     spin_lock(&chip->reg_lock);
    573     switch (cmd) {
    574     case SNDRV_PCM_TRIGGER_RESUME:
    575         s->suspended = 0;
    576         /* fallthru */
    577     case SNDRV_PCM_TRIGGER_START:
    578         if (! s->running) {
    579             snd_nm256_playback_start(chip, s, substream);
    580             s->running = 1;
    581         }
    582         break;
    583     case SNDRV_PCM_TRIGGER_SUSPEND:
    584         s->suspended = 1;
    585         /* fallthru */
    586     case SNDRV_PCM_TRIGGER_STOP:
    587         if (s->running) {
    588             snd_nm256_playback_stop(chip);
    589             s->running = 0;
    590         }
    591         break;
    592     default:
    593         err = -EINVAL;
    594         break;
    595     }
    596     spin_unlock(&chip->reg_lock);
    597     return err;
     573snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd)
     574{
     575        struct nm256 *chip = snd_pcm_substream_chip(substream);
     576        struct nm256_stream *s = substream->runtime->private_data;
     577        int err = 0;
     578
     579        snd_assert(s != NULL, return -ENXIO);
     580
     581        spin_lock(&chip->reg_lock);
     582        switch (cmd) {
     583        case SNDRV_PCM_TRIGGER_RESUME:
     584                s->suspended = 0;
     585                /* fallthru */
     586        case SNDRV_PCM_TRIGGER_START:
     587                if (! s->running) {
     588                        snd_nm256_playback_start(chip, s, substream);
     589                        s->running = 1;
     590                }
     591                break;
     592        case SNDRV_PCM_TRIGGER_SUSPEND:
     593                s->suspended = 1;
     594                /* fallthru */
     595        case SNDRV_PCM_TRIGGER_STOP:
     596                if (s->running) {
     597                        snd_nm256_playback_stop(chip);
     598                        s->running = 0;
     599                }
     600                break;
     601        default:
     602                err = -EINVAL;
     603                break;
     604        }
     605        spin_unlock(&chip->reg_lock);
     606        return err;
    598607}
    599608
    600609static int
    601 snd_nm256_capture_trigger(snd_pcm_substream_t *substream, int cmd)
    602 {
    603     nm256_t *chip = snd_pcm_substream_chip(substream);
    604     nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
    605     int err = 0;
    606 
    607     snd_assert(s != NULL, return -ENXIO);
    608 
    609     spin_lock(&chip->reg_lock);
    610     switch (cmd) {
    611     case SNDRV_PCM_TRIGGER_START:
    612     case SNDRV_PCM_TRIGGER_RESUME:
    613         if (! s->running) {
    614             snd_nm256_capture_start(chip, s, substream);
    615             s->running = 1;
    616         }
    617         break;
    618     case SNDRV_PCM_TRIGGER_STOP:
    619     case SNDRV_PCM_TRIGGER_SUSPEND:
    620         if (s->running) {
    621             snd_nm256_capture_stop(chip);
    622             s->running = 0;
    623         }
    624         break;
    625     default:
    626         err = -EINVAL;
    627         break;
    628     }
    629     spin_unlock(&chip->reg_lock);
    630     return err;
     610snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd)
     611{
     612        struct nm256 *chip = snd_pcm_substream_chip(substream);
     613        struct nm256_stream *s = substream->runtime->private_data;
     614        int err = 0;
     615
     616        snd_assert(s != NULL, return -ENXIO);
     617
     618        spin_lock(&chip->reg_lock);
     619        switch (cmd) {
     620        case SNDRV_PCM_TRIGGER_START:
     621        case SNDRV_PCM_TRIGGER_RESUME:
     622                if (! s->running) {
     623                        snd_nm256_capture_start(chip, s, substream);
     624                        s->running = 1;
     625                }
     626                break;
     627        case SNDRV_PCM_TRIGGER_STOP:
     628        case SNDRV_PCM_TRIGGER_SUSPEND:
     629                if (s->running) {
     630                        snd_nm256_capture_stop(chip);
     631                        s->running = 0;
     632                }
     633                break;
     634        default:
     635                err = -EINVAL;
     636                break;
     637        }
     638        spin_unlock(&chip->reg_lock);
     639        return err;
    631640}
    632641
     
    635644 * prepare playback/capture channel
    636645 */
    637 static int snd_nm256_pcm_prepare(snd_pcm_substream_t *substream)
    638 {
    639     nm256_t *chip = snd_pcm_substream_chip(substream);
    640     snd_pcm_runtime_t *runtime = substream->runtime;
    641     nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
    642 
    643     snd_assert(s, return -ENXIO);
    644     s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size);
    645     s->period_size = frames_to_bytes(runtime, substream->runtime->period_size);
    646     s->periods = substream->runtime->periods;
    647     s->cur_period = 0;
    648 
    649     spin_lock_irq(&chip->reg_lock);
    650     s->running = 0;
    651     snd_nm256_set_format(chip, s, substream);
    652     spin_unlock_irq(&chip->reg_lock);
    653 
    654     return 0;
     646static int snd_nm256_pcm_prepare(struct snd_pcm_substream *substream)
     647{
     648        struct nm256 *chip = snd_pcm_substream_chip(substream);
     649        struct snd_pcm_runtime *runtime = substream->runtime;
     650        struct nm256_stream *s = runtime->private_data;
     651
     652        snd_assert(s, return -ENXIO);
     653        s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size);
     654        s->period_size = frames_to_bytes(runtime, substream->runtime->period_size);
     655        s->periods = substream->runtime->periods;
     656        s->cur_period = 0;
     657
     658        spin_lock_irq(&chip->reg_lock);
     659        s->running = 0;
     660        snd_nm256_set_format(chip, s, substream);
     661        spin_unlock_irq(&chip->reg_lock);
     662
     663        return 0;
    655664}
    656665
     
    660669 */
    661670static snd_pcm_uframes_t
    662 snd_nm256_playback_pointer(snd_pcm_substream_t * substream)
    663 {
    664     nm256_t *chip = snd_pcm_substream_chip(substream);
    665     nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
    666     unsigned long curp;
    667 
    668     snd_assert(s, return 0);
    669     curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf;
    670     curp %= s->dma_size;
    671     return bytes_to_frames(substream->runtime, curp);
     671snd_nm256_playback_pointer(struct snd_pcm_substream *substream)
     672{
     673        struct nm256 *chip = snd_pcm_substream_chip(substream);
     674        struct nm256_stream *s = substream->runtime->private_data;
     675        unsigned long curp;
     676
     677        snd_assert(s, return 0);
     678        curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf;
     679        curp %= s->dma_size;
     680        return bytes_to_frames(substream->runtime, curp);
    672681}
    673682
    674683static snd_pcm_uframes_t
    675 snd_nm256_capture_pointer(snd_pcm_substream_t * substream)
    676 {
    677     nm256_t *chip = snd_pcm_substream_chip(substream);
    678     nm256_stream_t *s = (nm256_stream_t*)substream->runtime->private_data;
    679     unsigned long curp;
    680 
    681     snd_assert(s != NULL, return 0);
    682     curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf;
    683     curp %= s->dma_size;
    684     return bytes_to_frames(substream->runtime, curp);
    685 }
    686 
     684snd_nm256_capture_pointer(struct snd_pcm_substream *substream)
     685{
     686        struct nm256 *chip = snd_pcm_substream_chip(substream);
     687        struct nm256_stream *s = substream->runtime->private_data;
     688        unsigned long curp;
     689
     690        snd_assert(s != NULL, return 0);
     691        curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf;
     692        curp %= s->dma_size;   
     693        return bytes_to_frames(substream->runtime, curp);
     694}
     695
     696/* Remapped I/O space can be accessible as pointer on i386 */
     697/* This might be changed in the future */
    687698#ifndef __i386__
    688 /* FIXME: I/O space is not accessible via pointers on all architectures */
    689 
    690699/*
    691700 * silence / copy for playback
    692701 */
    693702static int
    694 snd_nm256_playback_silence(snd_pcm_substream_t *substream,
    695                            int channel, /* not used (interleaved data) */
    696                            snd_pcm_uframes_t pos,
    697                            snd_pcm_uframes_t count)
    698 {
    699     snd_pcm_runtime_t *runtime = substream->runtime;
    700     nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
    701     count = frames_to_bytes(runtime, count);
    702     pos = frames_to_bytes(runtime, pos);
    703     memset_io(s->bufptr + pos, 0, count);
    704     return 0;
     703snd_nm256_playback_silence(struct snd_pcm_substream *substream,
     704                           int channel, /* not used (interleaved data) */
     705                           snd_pcm_uframes_t pos,
     706                           snd_pcm_uframes_t count)
     707{
     708        struct snd_pcm_runtime *runtime = substream->runtime;
     709        struct nm256_stream *s = runtime->private_data;
     710        count = frames_to_bytes(runtime, count);
     711        pos = frames_to_bytes(runtime, pos);
     712        memset_io(s->bufptr + pos, 0, count);
     713        return 0;
    705714}
    706715
    707716static int
    708 snd_nm256_playback_copy(snd_pcm_substream_t *substream,
    709                         int channel, /* not used (interleaved data) */
    710                         snd_pcm_uframes_t pos,
    711                         void *src,
    712                         snd_pcm_uframes_t count)
    713 {
    714     snd_pcm_runtime_t *runtime = substream->runtime;
    715     nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
    716     count = frames_to_bytes(runtime, count);
    717     pos = frames_to_bytes(runtime, pos);
    718     if (copy_from_user_toio((volatile void *)(s->bufptr + pos), src, count))
    719         return -EFAULT;
    720     return 0;
     717snd_nm256_playback_copy(struct snd_pcm_substream *substream,
     718                        int channel, /* not used (interleaved data) */
     719                        snd_pcm_uframes_t pos,
     720                        void __user *src,
     721                        snd_pcm_uframes_t count)
     722{
     723        struct snd_pcm_runtime *runtime = substream->runtime;
     724        struct nm256_stream *s = runtime->private_data;
     725        count = frames_to_bytes(runtime, count);
     726        pos = frames_to_bytes(runtime, pos);
     727        if (copy_from_user_toio(s->bufptr + pos, src, count))
     728                return -EFAULT;
     729        return 0;
    721730}
    722731
     
    725734 */
    726735static int
    727 snd_nm256_capture_copy(snd_pcm_substream_t *substream,
    728                        int channel, /* not used (interleaved data) */
    729                        snd_pcm_uframes_t pos,
    730                        void *dst,
    731                        snd_pcm_uframes_t count)
    732 {
    733     snd_pcm_runtime_t *runtime = substream->runtime;
    734     nm256_stream_t *s = (nm256_stream_t*)runtime->private_data;
    735     count = frames_to_bytes(runtime, count);
    736     pos = frames_to_bytes(runtime, pos);
    737     if (copy_to_user_fromio(dst, (volatile void *)(s->bufptr + pos), count))
    738         return -EFAULT;
    739     return 0;
     736snd_nm256_capture_copy(struct snd_pcm_substream *substream,
     737                       int channel, /* not used (interleaved data) */
     738                       snd_pcm_uframes_t pos,
     739                       void __user *dst,
     740                       snd_pcm_uframes_t count)
     741{
     742        struct snd_pcm_runtime *runtime = substream->runtime;
     743        struct nm256_stream *s = runtime->private_data;
     744        count = frames_to_bytes(runtime, count);
     745        pos = frames_to_bytes(runtime, pos);
     746        if (copy_to_user_fromio(dst, s->bufptr + pos, count))
     747                return -EFAULT;
     748        return 0;
    740749}
    741750
     
    749758/* spinlock held! */
    750759static void
    751 snd_nm256_playback_update(nm256_t *chip)
    752 {
    753     nm256_stream_t *s;
    754 
    755     s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK];
    756     if (s->running && s->substream) {
    757         spin_unlock(&chip->reg_lock);
    758         snd_pcm_period_elapsed(s->substream);
    759         spin_lock(&chip->reg_lock);
    760         snd_nm256_playback_mark(chip, s);
    761     }
     760snd_nm256_playback_update(struct nm256 *chip)
     761{
     762        struct nm256_stream *s;
     763
     764        s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK];
     765        if (s->running && s->substream) {
     766                spin_unlock(&chip->reg_lock);
     767                snd_pcm_period_elapsed(s->substream);
     768                spin_lock(&chip->reg_lock);
     769                snd_nm256_playback_mark(chip, s);
     770        }
    762771}
    763772
    764773/* spinlock held! */
    765774static void
    766 snd_nm256_capture_update(nm256_t *chip)
    767 {
    768     nm256_stream_t *s;
    769 
    770     s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE];
    771     if (s->running && s->substream) {
    772         spin_unlock(&chip->reg_lock);
    773         snd_pcm_period_elapsed(s->substream);
    774         spin_lock(&chip->reg_lock);
    775         snd_nm256_capture_mark(chip, s);
    776     }
     775snd_nm256_capture_update(struct nm256 *chip)
     776{
     777        struct nm256_stream *s;
     778
     779        s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE];
     780        if (s->running && s->substream) {
     781                spin_unlock(&chip->reg_lock);
     782                snd_pcm_period_elapsed(s->substream);
     783                spin_lock(&chip->reg_lock);
     784                snd_nm256_capture_mark(chip, s);
     785        }
    777786}
    778787
     
    780789 * hardware info
    781790 */
    782 
    783 static snd_pcm_hardware_t snd_nm256_playback =
    784 {
    785     /*  info:             */
    786 #ifdef __i386__
    787     SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID|
     791static struct snd_pcm_hardware snd_nm256_playback =
     792{
     793        .info =                 SNDRV_PCM_INFO_MMAP_IOMEM |SNDRV_PCM_INFO_MMAP_VALID |
     794                                SNDRV_PCM_INFO_INTERLEAVED |
     795                                /*SNDRV_PCM_INFO_PAUSE |*/
     796                                SNDRV_PCM_INFO_RESUME,
     797        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     798        .rates =                SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
     799        .rate_min =             8000,
     800        .rate_max =             48000,
     801        .channels_min =         1,
     802        .channels_max =         2,
     803        .periods_min =          2,
     804        .periods_max =          1024,
     805        .buffer_bytes_max =     128 * 1024,
     806        .period_bytes_min =     256,
     807        .period_bytes_max =     128 * 1024,
     808};
     809
     810static struct snd_pcm_hardware snd_nm256_capture =
     811{
     812        .info =                 SNDRV_PCM_INFO_MMAP_IOMEM | SNDRV_PCM_INFO_MMAP_VALID |
     813                                SNDRV_PCM_INFO_INTERLEAVED |
     814                                /*SNDRV_PCM_INFO_PAUSE |*/
     815                                SNDRV_PCM_INFO_RESUME,
     816        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     817        .rates =                SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
     818        .rate_min =             8000,
     819        .rate_max =             48000,
     820        .channels_min =         1,
     821        .channels_max =         2,
     822        .periods_min =          2,
     823        .periods_max =          1024,
     824        .buffer_bytes_max =     128 * 1024,
     825        .period_bytes_min =     256,
     826        .period_bytes_max =     128 * 1024,
     827};
     828
     829
     830/* set dma transfer size */
     831static int snd_nm256_pcm_hw_params(struct snd_pcm_substream *substream,
     832                                   struct snd_pcm_hw_params *hw_params)
     833{
     834        /* area and addr are already set and unchanged */
     835        substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
     836        return 0;
     837}
     838
     839/*
     840 * open
     841 */
     842static void snd_nm256_setup_stream(struct nm256 *chip, struct nm256_stream *s,
     843                                   struct snd_pcm_substream *substream,
     844                                   struct snd_pcm_hardware *hw_ptr)
     845{
     846        struct snd_pcm_runtime *runtime = substream->runtime;
     847
     848        s->running = 0;
     849        runtime->hw = *hw_ptr;
     850        runtime->hw.buffer_bytes_max = s->bufsize;
     851        runtime->hw.period_bytes_max = s->bufsize / 2;
     852        runtime->dma_area = (void __force *) s->bufptr;
     853        runtime->dma_addr = s->bufptr_addr;
     854        runtime->dma_bytes = s->bufsize;
     855        runtime->private_data = s;
     856        s->substream = substream;
     857
     858        snd_pcm_set_sync(substream);
     859        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
     860                                   &constraints_rates);
     861}
     862
     863static int
     864snd_nm256_playback_open(struct snd_pcm_substream *substream)
     865{
     866        struct nm256 *chip = snd_pcm_substream_chip(substream);
     867
     868        if (snd_nm256_acquire_irq(chip) < 0)
     869                return -EBUSY;
     870        snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK],
     871                               substream, &snd_nm256_playback);
     872        return 0;
     873}
     874
     875static int
     876snd_nm256_capture_open(struct snd_pcm_substream *substream)
     877{
     878        struct nm256 *chip = snd_pcm_substream_chip(substream);
     879
     880        if (snd_nm256_acquire_irq(chip) < 0)
     881                return -EBUSY;
     882        snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE],
     883                               substream, &snd_nm256_capture);
     884        return 0;
     885}
     886
     887/*
     888 * close - we don't have to do special..
     889 */
     890static int
     891snd_nm256_playback_close(struct snd_pcm_substream *substream)
     892{
     893        struct nm256 *chip = snd_pcm_substream_chip(substream);
     894
     895        snd_nm256_release_irq(chip);
     896        return 0;
     897}
     898
     899
     900static int
     901snd_nm256_capture_close(struct snd_pcm_substream *substream)
     902{
     903        struct nm256 *chip = snd_pcm_substream_chip(substream);
     904
     905        snd_nm256_release_irq(chip);
     906        return 0;
     907}
     908
     909/*
     910 * create a pcm instance
     911 */
     912static struct snd_pcm_ops snd_nm256_playback_ops = {
     913        .open =         snd_nm256_playback_open,
     914        .close =        snd_nm256_playback_close,
     915        .ioctl =        snd_pcm_lib_ioctl,
     916        .hw_params =    snd_nm256_pcm_hw_params,
     917        .prepare =      snd_nm256_pcm_prepare,
     918        .trigger =      snd_nm256_playback_trigger,
     919        .pointer =      snd_nm256_playback_pointer,
     920#ifndef __i386__
     921        .copy =         snd_nm256_playback_copy,
     922        .silence =      snd_nm256_playback_silence,
    788923#endif
    789         SNDRV_PCM_INFO_INTERLEAVED |
    790         /*SNDRV_PCM_INFO_PAUSE |*/
    791         SNDRV_PCM_INFO_RESUME,
    792         /*      formats:          */    SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    793         /*      rates:            */    SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
    794         /*      rate_min:         */    8000,
    795         /*      rate_max:         */    48000,
    796         /*      channels_min:     */    1,
    797         /*      channels_max:     */    2,
    798         /*      buffer_bytes_max:  */   128 * 1024,
    799         /*      period_bytes_min:  */   256,
    800         /*      period_bytes_max:  */   128 * 1024,
    801         /*      .periods_min =     */   2,
    802         /*      .periods_max =     */   1024,
    803         0
     924        .mmap =         snd_pcm_lib_mmap_iomem,
    804925};
    805926
    806 static snd_pcm_hardware_t snd_nm256_capture =
    807 {
    808     /*  info:             */
    809 #ifdef __i386__
    810     SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID|
     927static struct snd_pcm_ops snd_nm256_capture_ops = {
     928        .open =         snd_nm256_capture_open,
     929        .close =        snd_nm256_capture_close,
     930        .ioctl =        snd_pcm_lib_ioctl,
     931        .hw_params =    snd_nm256_pcm_hw_params,
     932        .prepare =      snd_nm256_pcm_prepare,
     933        .trigger =      snd_nm256_capture_trigger,
     934        .pointer =      snd_nm256_capture_pointer,
     935#ifndef __i386__
     936        .copy =         snd_nm256_capture_copy,
    811937#endif
    812         SNDRV_PCM_INFO_INTERLEAVED |
    813         /*SNDRV_PCM_INFO_PAUSE |*/
    814         SNDRV_PCM_INFO_RESUME,
    815         /*      formats:          */    SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    816         /*      rates:            */    SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000,
    817         /*      rate_min:         */    8000,
    818         /*      rate_max:         */    48000,
    819         /*      channels_min:     */    1,
    820         /*      channels_max:     */    2,
    821         /*      buffer_bytes_max:  */   128 * 1024,
    822         /*      period_bytes_min:  */   256,
    823         /*      period_bytes_max:  */   128 * 1024,
    824         /*      .periods_min =     */   2,
    825         /*      .periods_max =     */   1024,
    826         0
     938        .mmap =         snd_pcm_lib_mmap_iomem,
    827939};
    828940
    829 
    830 /* set dma transfer size */
    831 static int snd_nm256_pcm_hw_params(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *hw_params)
    832 {
    833     /* area and addr are already set and unchanged */
    834     substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
    835     return 0;
    836 }
    837 
    838 /*
    839  * open
    840  */
    841 static void snd_nm256_setup_stream(nm256_t *chip, nm256_stream_t *s,
    842                                    snd_pcm_substream_t *substream,
    843                                    snd_pcm_hardware_t *hw_ptr)
    844 {
    845     snd_pcm_runtime_t *runtime = substream->runtime;
    846 
    847     s->running = 0;
    848     runtime->hw = *hw_ptr;
    849     runtime->hw.buffer_bytes_max = s->bufsize;
    850     runtime->hw.period_bytes_max = s->bufsize / 2;
    851     runtime->dma_area = (void *)s->bufptr;
    852     runtime->dma_addr = s->bufptr_addr;
    853     runtime->dma_bytes = s->bufsize;
    854     runtime->private_data = s;
    855     s->substream = substream;
    856 
    857     snd_pcm_set_sync(substream);
    858     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
    859                                &constraints_rates);
    860 }
    861 
    862 static int
    863 snd_nm256_playback_open(snd_pcm_substream_t *substream)
    864 {
    865     nm256_t *chip = snd_pcm_substream_chip(substream);
    866 
    867     if (snd_nm256_acquire_irq(chip) < 0)
    868         return -EBUSY;
    869     snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK],
    870                            substream, &snd_nm256_playback);
    871     return 0;
    872 }
    873 
    874 static int
    875 snd_nm256_capture_open(snd_pcm_substream_t *substream)
    876 {
    877     nm256_t *chip = snd_pcm_substream_chip(substream);
    878 
    879     if (snd_nm256_acquire_irq(chip) < 0)
    880         return -EBUSY;
    881     snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE],
    882                            substream, &snd_nm256_capture);
    883     return 0;
    884 }
    885 
    886 /*
    887  * close - we don't have to do special..
    888  */
    889 static int
    890 snd_nm256_playback_close(snd_pcm_substream_t *substream)
    891 {
    892     nm256_t *chip = snd_pcm_substream_chip(substream);
    893 
    894     snd_nm256_release_irq(chip);
    895     return 0;
    896 }
    897 
    898 
    899 static int
    900 snd_nm256_capture_close(snd_pcm_substream_t *substream)
    901 {
    902     nm256_t *chip = snd_pcm_substream_chip(substream);
    903 
    904     snd_nm256_release_irq(chip);
    905     return 0;
    906 }
    907 
    908 /*
    909  * create a pcm instance
    910  */
    911 
    912 static snd_pcm_ops_t snd_nm256_playback_ops = {
    913     /*  .open =      */   snd_nm256_playback_open,
    914     /*  .close =     */   snd_nm256_playback_close,
    915     /*  .ioctl =     */   snd_pcm_lib_ioctl,
    916     /*  .hw_params = */   snd_nm256_pcm_hw_params,
    917     NULL,
    918     /*  .prepare =   */   snd_nm256_pcm_prepare,
    919     /*  .trigger =   */   snd_nm256_playback_trigger,
    920     /*  .pointer =   */   snd_nm256_playback_pointer,
    921 #ifndef __i386__
    922     /*  .copy =      */   snd_nm256_playback_copy,
    923     /*  .silence =   */   snd_nm256_playback_silence,
    924     NULL,NULL
    925 #else
    926     NULL,NULL,NULL,NULL
    927 #endif
    928 };
    929 
    930 static snd_pcm_ops_t snd_nm256_capture_ops = {
    931     /*  .open =      */   snd_nm256_capture_open,
    932     /*  .close =     */   snd_nm256_capture_close,
    933     /*  .ioctl =     */   snd_pcm_lib_ioctl,
    934     /*  .hw_params = */   snd_nm256_pcm_hw_params,
    935     NULL,
    936     /*  .prepare =   */   snd_nm256_pcm_prepare,
    937     /*  .trigger =   */   snd_nm256_capture_trigger,
    938     /*  .pointer =   */   snd_nm256_capture_pointer,
    939 #ifndef __i386__
    940     /*  .copy =      */   snd_nm256_capture_copy,
    941     NULL,NULL,NULL
    942 #else
    943     NULL,NULL,NULL,NULL
    944 #endif
    945 };
    946 
    947941static int __devinit
    948 snd_nm256_pcm(nm256_t *chip, int device)
    949 {
    950     snd_pcm_t *pcm;
    951     int i, err;
    952 
    953     for (i = 0; i < 2; i++) {
    954         nm256_stream_t *s = &chip->streams[i];
    955         s->bufptr = chip->buffer +  s->buf - chip->buffer_start;
    956         s->bufptr_addr = chip->buffer_addr + s->buf - chip->buffer_start;
    957     }
    958 
    959     err = snd_pcm_new(chip->card, chip->card->driver, device,
    960                       1, 1, &pcm);
    961     if (err < 0)
    962         return err;
    963 
    964     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_nm256_playback_ops);
    965     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_nm256_capture_ops);
    966 
    967     pcm->private_data = chip;
    968     pcm->info_flags = 0;
    969     chip->pcm = pcm;
    970 
    971     return 0;
    972 }
    973 
    974 
    975 /*
    976  * Initialize the hardware.
     942snd_nm256_pcm(struct nm256 *chip, int device)
     943{
     944        struct snd_pcm *pcm;
     945        int i, err;
     946
     947        for (i = 0; i < 2; i++) {
     948                struct nm256_stream *s = &chip->streams[i];
     949                s->bufptr = chip->buffer + (s->buf - chip->buffer_start);
     950                s->bufptr_addr = chip->buffer_addr + (s->buf - chip->buffer_start);
     951        }
     952
     953        err = snd_pcm_new(chip->card, chip->card->driver, device,
     954                          1, 1, &pcm);
     955        if (err < 0)
     956                return err;
     957
     958        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_nm256_playback_ops);
     959        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_nm256_capture_ops);
     960
     961        pcm->private_data = chip;
     962        pcm->info_flags = 0;
     963        chip->pcm = pcm;
     964
     965        return 0;
     966}
     967
     968
     969/* 
     970 * Initialize the hardware. 
    977971 */
    978972static void
    979 snd_nm256_init_chip(nm256_t *chip)
    980 {
    981     /* Reset everything. */
    982     snd_nm256_writeb(chip, 0x0, 0x11);
    983     snd_nm256_writew(chip, 0x214, 0);
    984     /* stop sounds.. */
    985     //snd_nm256_playback_stop(chip);
    986     //snd_nm256_capture_stop(chip);
    987 }
     973snd_nm256_init_chip(struct nm256 *chip)
     974{
     975        /* Reset everything. */
     976        snd_nm256_writeb(chip, 0x0, 0x11);
     977        snd_nm256_writew(chip, 0x214, 0);
     978        /* stop sounds.. */
     979        //snd_nm256_playback_stop(chip);
     980        //snd_nm256_capture_stop(chip);
     981}
     982
    988983
    989984static irqreturn_t
    990 snd_nm256_intr_check(nm256_t *chip)
    991 {
    992     if (chip->badintrcount++ > 1000) {
    993         /*
    994         * I'm not sure if the best thing is to stop the card from
    995         * playing or just release the interrupt (after all, we're in
    996         * a bad situation, so doing fancy stuff may not be such a good
    997         * idea).
    998         *
    999         * I worry about the card engine continuing to play noise
    1000         * over and over, however--that could become a very
    1001         * obnoxious problem.  And we know that when this usually
    1002         * happens things are fairly safe, it just means the user's
    1003         * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
    1004         */
    1005         if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
    1006             snd_nm256_playback_stop(chip);
    1007         if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
    1008             snd_nm256_capture_stop(chip);
    1009         chip->badintrcount = 0;
    1010         return IRQ_HANDLED;
    1011     }
    1012     return IRQ_NONE;
    1013 }
    1014 
    1015 /*
    1016  * Handle a potential interrupt for the device referred to by DEV_ID.
     985snd_nm256_intr_check(struct nm256 *chip)
     986{
     987        if (chip->badintrcount++ > 1000) {
     988                /*
     989                * I'm not sure if the best thing is to stop the card from
     990                * playing or just release the interrupt (after all, we're in
     991                * a bad situation, so doing fancy stuff may not be such a good
     992                * idea).
     993                *
     994                * I worry about the card engine continuing to play noise
     995                * over and over, however--that could become a very
     996                * obnoxious problem.  And we know that when this usually
     997                * happens things are fairly safe, it just means the user's
     998                * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
     999                */
     1000                if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
     1001                        snd_nm256_playback_stop(chip);
     1002                if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
     1003                        snd_nm256_capture_stop(chip);
     1004                chip->badintrcount = 0;
     1005                return IRQ_HANDLED;
     1006        }
     1007        return IRQ_NONE;
     1008}
     1009
     1010/* 
     1011 * Handle a potential interrupt for the device referred to by DEV_ID. 
    10171012 *
    10181013 * I don't like the cut-n-paste job here either between the two routines,
     
    10251020snd_nm256_interrupt(int irq, void *dev_id, struct pt_regs *dummy)
    10261021{
    1027     nm256_t *chip = dev_id;
    1028     u16 status;
    1029     u8 cbyte;
    1030 #ifdef TARGET_OS2
    1031     int fOurIrq = FALSE;
    1032 #endif
    1033 
    1034     status = snd_nm256_readw(chip, NM_INT_REG);
    1035 
    1036     /* Not ours. */
    1037     if (status == 0) {
    1038         snd_nm256_intr_check(chip);
    1039         return IRQ_NONE;
    1040     }
    1041 #ifdef TARGET_OS2
    1042     fOurIrq = TRUE;
    1043 #endif
    1044 
    1045     chip->badintrcount = 0;
    1046 
    1047     /* Rather boring; check for individual interrupts and process them. */
    1048 
    1049     spin_lock(&chip->reg_lock);
    1050     if (status & NM_PLAYBACK_INT) {
    1051         status &= ~NM_PLAYBACK_INT;
    1052         NM_ACK_INT(chip, NM_PLAYBACK_INT);
    1053         snd_nm256_playback_update(chip);
    1054     }
    1055 
    1056     if (status & NM_RECORD_INT) {
    1057         status &= ~NM_RECORD_INT;
    1058         NM_ACK_INT(chip, NM_RECORD_INT);
    1059         snd_nm256_capture_update(chip);
    1060     }
    1061 
    1062     if (status & NM_MISC_INT_1) {
    1063         status &= ~NM_MISC_INT_1;
    1064         NM_ACK_INT(chip, NM_MISC_INT_1);
    1065         snd_printd("NM256: Got misc interrupt #1\n");
    1066         snd_nm256_writew(chip, NM_INT_REG, 0x8000);
    1067         cbyte = snd_nm256_readb(chip, 0x400);
    1068         snd_nm256_writeb(chip, 0x400, cbyte | 2);
    1069     }
    1070 
    1071     if (status & NM_MISC_INT_2) {
    1072         status &= ~NM_MISC_INT_2;
    1073         NM_ACK_INT(chip, NM_MISC_INT_2);
    1074         snd_printd("NM256: Got misc interrupt #2\n");
    1075         cbyte = snd_nm256_readb(chip, 0x400);
    1076         snd_nm256_writeb(chip, 0x400, cbyte & ~2);
    1077     }
    1078 
    1079     /* Unknown interrupt. */
    1080     if (status) {
    1081         snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
    1082                    status);
    1083         /* Pray. */
    1084         NM_ACK_INT(chip, status);
    1085     }
    1086 
    1087     spin_unlock(&chip->reg_lock);
    1088 #ifdef TARGET_OS2
    1089     if (fOurIrq) {
    1090         eoi_irq(irq);
    1091     }
    1092 #endif //TARGET_OS2
    1093     return IRQ_HANDLED;
     1022        struct nm256 *chip = dev_id;
     1023        u16 status;
     1024        u8 cbyte;
     1025
     1026        status = snd_nm256_readw(chip, NM_INT_REG);
     1027
     1028        /* Not ours. */
     1029        if (status == 0)
     1030                return snd_nm256_intr_check(chip);
     1031
     1032        chip->badintrcount = 0;
     1033
     1034        /* Rather boring; check for individual interrupts and process them. */
     1035
     1036        spin_lock(&chip->reg_lock);
     1037        if (status & NM_PLAYBACK_INT) {
     1038                status &= ~NM_PLAYBACK_INT;
     1039                NM_ACK_INT(chip, NM_PLAYBACK_INT);
     1040                snd_nm256_playback_update(chip);
     1041        }
     1042
     1043        if (status & NM_RECORD_INT) {
     1044                status &= ~NM_RECORD_INT;
     1045                NM_ACK_INT(chip, NM_RECORD_INT);
     1046                snd_nm256_capture_update(chip);
     1047        }
     1048
     1049        if (status & NM_MISC_INT_1) {
     1050                status &= ~NM_MISC_INT_1;
     1051                NM_ACK_INT(chip, NM_MISC_INT_1);
     1052                snd_printd("NM256: Got misc interrupt #1\n");
     1053                snd_nm256_writew(chip, NM_INT_REG, 0x8000);
     1054                cbyte = snd_nm256_readb(chip, 0x400);
     1055                snd_nm256_writeb(chip, 0x400, cbyte | 2);
     1056        }
     1057
     1058        if (status & NM_MISC_INT_2) {
     1059                status &= ~NM_MISC_INT_2;
     1060                NM_ACK_INT(chip, NM_MISC_INT_2);
     1061                snd_printd("NM256: Got misc interrupt #2\n");
     1062                cbyte = snd_nm256_readb(chip, 0x400);
     1063                snd_nm256_writeb(chip, 0x400, cbyte & ~2);
     1064        }
     1065
     1066        /* Unknown interrupt. */
     1067        if (status) {
     1068                snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
     1069                           status);
     1070                /* Pray. */
     1071                NM_ACK_INT(chip, status);
     1072        }
     1073
     1074        spin_unlock(&chip->reg_lock);
     1075        return IRQ_HANDLED;
    10941076}
    10951077
     
    11031085snd_nm256_interrupt_zx(int irq, void *dev_id, struct pt_regs *dummy)
    11041086{
    1105     nm256_t *chip = dev_id;
    1106     u32 status;
    1107     u8 cbyte;
    1108 #ifdef TARGET_OS2
    1109     int fOurIrq = FALSE;
    1110 #endif
    1111 
    1112     status = snd_nm256_readl(chip, NM_INT_REG);
    1113 
    1114     /* Not ours. */
    1115     if (status == 0)
    1116     {
    1117         snd_nm256_intr_check(chip);
    1118         return IRQ_NONE;
    1119     }
    1120 #ifdef TARGET_OS2
    1121     fOurIrq = TRUE;
    1122 #endif
    1123 
    1124     chip->badintrcount = 0;
    1125 
    1126     /* Rather boring; check for individual interrupts and process them. */
    1127 
    1128     spin_lock(&chip->reg_lock);
    1129     if (status & NM2_PLAYBACK_INT) {
    1130         status &= ~NM2_PLAYBACK_INT;
    1131         NM2_ACK_INT(chip, NM2_PLAYBACK_INT);
    1132         snd_nm256_playback_update(chip);
    1133     }
    1134 
    1135     if (status & NM2_RECORD_INT) {
    1136         status &= ~NM2_RECORD_INT;
    1137         NM2_ACK_INT(chip, NM2_RECORD_INT);
    1138         snd_nm256_capture_update(chip);
    1139     }
    1140 
    1141     if (status & NM2_MISC_INT_1) {
    1142         status &= ~NM2_MISC_INT_1;
    1143         NM2_ACK_INT(chip, NM2_MISC_INT_1);
    1144         snd_printd("NM256: Got misc interrupt #1\n");
    1145         cbyte = snd_nm256_readb(chip, 0x400);
    1146         snd_nm256_writeb(chip, 0x400, cbyte | 2);
    1147     }
    1148 
    1149     if (status & NM2_MISC_INT_2) {
    1150         status &= ~NM2_MISC_INT_2;
    1151         NM2_ACK_INT(chip, NM2_MISC_INT_2);
    1152         snd_printd("NM256: Got misc interrupt #2\n");
    1153         cbyte = snd_nm256_readb(chip, 0x400);
    1154         snd_nm256_writeb(chip, 0x400, cbyte & ~2);
    1155     }
    1156 
    1157     /* Unknown interrupt. */
    1158     if (status) {
    1159         snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
    1160                    status);
    1161         /* Pray. */
    1162         NM2_ACK_INT(chip, status);
    1163     }
    1164 
    1165     spin_unlock(&chip->reg_lock);
    1166 #ifdef TARGET_OS2
    1167     if (fOurIrq) {
    1168         eoi_irq(irq);
    1169     }
    1170 #endif //TARGET_OS2
    1171     return IRQ_HANDLED;
     1087        struct nm256 *chip = dev_id;
     1088        u32 status;
     1089        u8 cbyte;
     1090
     1091        status = snd_nm256_readl(chip, NM_INT_REG);
     1092
     1093        /* Not ours. */
     1094        if (status == 0)
     1095                return snd_nm256_intr_check(chip);
     1096
     1097        chip->badintrcount = 0;
     1098
     1099        /* Rather boring; check for individual interrupts and process them. */
     1100
     1101        spin_lock(&chip->reg_lock);
     1102        if (status & NM2_PLAYBACK_INT) {
     1103                status &= ~NM2_PLAYBACK_INT;
     1104                NM2_ACK_INT(chip, NM2_PLAYBACK_INT);
     1105                snd_nm256_playback_update(chip);
     1106        }
     1107
     1108        if (status & NM2_RECORD_INT) {
     1109                status &= ~NM2_RECORD_INT;
     1110                NM2_ACK_INT(chip, NM2_RECORD_INT);
     1111                snd_nm256_capture_update(chip);
     1112        }
     1113
     1114        if (status & NM2_MISC_INT_1) {
     1115                status &= ~NM2_MISC_INT_1;
     1116                NM2_ACK_INT(chip, NM2_MISC_INT_1);
     1117                snd_printd("NM256: Got misc interrupt #1\n");
     1118                cbyte = snd_nm256_readb(chip, 0x400);
     1119                snd_nm256_writeb(chip, 0x400, cbyte | 2);
     1120        }
     1121
     1122        if (status & NM2_MISC_INT_2) {
     1123                status &= ~NM2_MISC_INT_2;
     1124                NM2_ACK_INT(chip, NM2_MISC_INT_2);
     1125                snd_printd("NM256: Got misc interrupt #2\n");
     1126                cbyte = snd_nm256_readb(chip, 0x400);
     1127                snd_nm256_writeb(chip, 0x400, cbyte & ~2);
     1128        }
     1129
     1130        /* Unknown interrupt. */
     1131        if (status) {
     1132                snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n",
     1133                           status);
     1134                /* Pray. */
     1135                NM2_ACK_INT(chip, status);
     1136        }
     1137
     1138        spin_unlock(&chip->reg_lock);
     1139        return IRQ_HANDLED;
    11721140}
    11731141
     
    11811149 */
    11821150static int
    1183 snd_nm256_ac97_ready(nm256_t *chip)
    1184 {
    1185     int timeout = 10;
    1186     u32 testaddr;
    1187     u16 testb;
    1188 
    1189     testaddr = chip->mixer_status_offset;
    1190     testb = chip->mixer_status_mask;
    1191 
    1192     /*
    1193      * Loop around waiting for the mixer to become ready.
    1194      */
    1195     while (timeout-- > 0) {
    1196         if ((snd_nm256_readw(chip, testaddr) & testb) == 0)
    1197             return 1;
    1198         udelay(100);
    1199     }
    1200     return 0;
    1201 }
    1202 
    1203 /*
     1151snd_nm256_ac97_ready(struct nm256 *chip)
     1152{
     1153        int timeout = 10;
     1154        u32 testaddr;
     1155        u16 testb;
     1156
     1157        testaddr = chip->mixer_status_offset;
     1158        testb = chip->mixer_status_mask;
     1159
     1160        /*
     1161         * Loop around waiting for the mixer to become ready.
     1162         */
     1163        while (timeout-- > 0) {
     1164                if ((snd_nm256_readw(chip, testaddr) & testb) == 0)
     1165                        return 1;
     1166                udelay(100);
     1167        }
     1168        return 0;
     1169}
     1170
     1171/*
     1172 * Initial register values to be written to the AC97 mixer.
     1173 * While most of these are identical to the reset values, we do this
     1174 * so that we have most of the register contents cached--this avoids
     1175 * reading from the mixer directly (which seems to be problematic,
     1176 * probably due to ignorance).
     1177 */
     1178
     1179struct initialValues {
     1180        unsigned short reg;
     1181        unsigned short value;
     1182};
     1183
     1184static struct initialValues nm256_ac97_init_val[] =
     1185{
     1186        { AC97_MASTER,          0x8000 },
     1187        { AC97_HEADPHONE,       0x8000 },
     1188        { AC97_MASTER_MONO,     0x8000 },
     1189        { AC97_PC_BEEP,         0x8000 },
     1190        { AC97_PHONE,           0x8008 },
     1191        { AC97_MIC,             0x8000 },
     1192        { AC97_LINE,            0x8808 },
     1193        { AC97_CD,              0x8808 },
     1194        { AC97_VIDEO,           0x8808 },
     1195        { AC97_AUX,             0x8808 },
     1196        { AC97_PCM,             0x8808 },
     1197        { AC97_REC_SEL,         0x0000 },
     1198        { AC97_REC_GAIN,        0x0B0B },
     1199        { AC97_GENERAL_PURPOSE, 0x0000 },
     1200        { AC97_3D_CONTROL,      0x8000 },
     1201        { AC97_VENDOR_ID1,      0x8384 },
     1202        { AC97_VENDOR_ID2,      0x7609 },
     1203};
     1204
     1205static int nm256_ac97_idx(unsigned short reg)
     1206{
     1207        int i;
     1208        for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++)
     1209                if (nm256_ac97_init_val[i].reg == reg)
     1210                        return i;
     1211        return -1;
     1212}
     1213
     1214/*
     1215 * some nm256 easily crash when reading from mixer registers
     1216 * thus we're treating it as a write-only mixer and cache the
     1217 * written values
    12041218 */
    12051219static unsigned short
    1206 snd_nm256_ac97_read(ac97_t *ac97, unsigned short reg)
    1207 {
    1208     nm256_t *chip = ac97->private_data;
    1209     int res;
    1210 
    1211     if (reg >= 128)
    1212         return 0;
    1213 
    1214     if (! snd_nm256_ac97_ready(chip))
    1215         return 0;
    1216     res = snd_nm256_readw(chip, chip->mixer_base + reg);
    1217     /* Magic delay.  Bleah yucky.  */
    1218     msleep(1);
    1219     return res;
    1220 }
    1221 
    1222 /*
     1220snd_nm256_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
     1221{
     1222        struct nm256 *chip = ac97->private_data;
     1223        int idx = nm256_ac97_idx(reg);
     1224
     1225        if (idx < 0)
     1226                return 0;
     1227        return chip->ac97_regs[idx];
     1228}
     1229
     1230/*
    12231231 */
    12241232static void
    1225 snd_nm256_ac97_write(ac97_t *ac97,
    1226                      unsigned short reg, unsigned short val)
    1227 {
    1228     nm256_t *chip = ac97->private_data;
    1229     int tries = 2;
    1230     u32 base;
    1231 
    1232     base = chip->mixer_base;
    1233 
    1234     snd_nm256_ac97_ready(chip);
    1235 
    1236     /* Wait for the write to take, too. */
    1237     while (tries-- > 0) {
    1238         snd_nm256_writew(chip, base + reg, val);
    1239         msleep(1);  /* a little delay here seems better.. */
    1240         if (snd_nm256_ac97_ready(chip))
    1241             return;
    1242     }
    1243     snd_printd("nm256: ac97 codec not ready..\n");
    1244 }
     1233snd_nm256_ac97_write(struct snd_ac97 *ac97,
     1234                     unsigned short reg, unsigned short val)
     1235{
     1236        struct nm256 *chip = ac97->private_data;
     1237        int tries = 2;
     1238        int idx = nm256_ac97_idx(reg);
     1239        u32 base;
     1240
     1241        if (idx < 0)
     1242                return;
     1243
     1244        base = chip->mixer_base;
     1245
     1246        snd_nm256_ac97_ready(chip);
     1247
     1248        /* Wait for the write to take, too. */
     1249        while (tries-- > 0) {
     1250                snd_nm256_writew(chip, base + reg, val);
     1251                msleep(1);  /* a little delay here seems better.. */
     1252                if (snd_nm256_ac97_ready(chip)) {
     1253                        /* successful write: set cache */
     1254                        chip->ac97_regs[idx] = val;
     1255                        return;
     1256                }
     1257        }
     1258        snd_printd("nm256: ac97 codec not ready..\n");
     1259}
     1260
     1261/* static resolution table */
     1262static struct snd_ac97_res_table nm256_res_table[] = {
     1263        { AC97_MASTER, 0x1f1f },
     1264        { AC97_HEADPHONE, 0x1f1f },
     1265        { AC97_MASTER_MONO, 0x001f },
     1266        { AC97_PC_BEEP, 0x001f },
     1267        { AC97_PHONE, 0x001f },
     1268        { AC97_MIC, 0x001f },
     1269        { AC97_LINE, 0x1f1f },
     1270        { AC97_CD, 0x1f1f },
     1271        { AC97_VIDEO, 0x1f1f },
     1272        { AC97_AUX, 0x1f1f },
     1273        { AC97_PCM, 0x1f1f },
     1274        { AC97_REC_GAIN, 0x0f0f },
     1275        {0} /* terminator */
     1276};
    12451277
    12461278/* initialize the ac97 into a known state */
    12471279static void
    1248 snd_nm256_ac97_reset(ac97_t *ac97)
    1249 {
    1250     nm256_t *chip = ac97->private_data;
    1251     /* Reset the mixer.  'Tis magic!  */
    1252     snd_nm256_writeb(chip, 0x6c0, 1);
    1253     if (! chip->reset_workaround) {
    1254         /* Dell latitude LS will lock up by this */
    1255         snd_nm256_writeb(chip, 0x6cc, 0x87);
    1256     }
    1257     snd_nm256_writeb(chip, 0x6cc, 0x80);
    1258     snd_nm256_writeb(chip, 0x6cc, 0x0);
     1280snd_nm256_ac97_reset(struct snd_ac97 *ac97)
     1281{
     1282        struct nm256 *chip = ac97->private_data;
     1283
     1284        /* Reset the mixer.  'Tis magic!  */
     1285        snd_nm256_writeb(chip, 0x6c0, 1);
     1286        if (! chip->reset_workaround) {
     1287                /* Dell latitude LS will lock up by this */
     1288                snd_nm256_writeb(chip, 0x6cc, 0x87);
     1289        }
     1290        if (! chip->reset_workaround_2) {
     1291                /* Dell latitude CSx will lock up by this */
     1292                snd_nm256_writeb(chip, 0x6cc, 0x80);
     1293                snd_nm256_writeb(chip, 0x6cc, 0x0);
     1294        }
     1295        if (! chip->in_resume) {
     1296                int i;
     1297                for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) {
     1298                        /* preload the cache, so as to avoid even a single
     1299                         * read of the mixer regs
     1300                         */
     1301                        snd_nm256_ac97_write(ac97, nm256_ac97_init_val[i].reg,
     1302                                             nm256_ac97_init_val[i].value);
     1303                }
     1304        }
    12591305}
    12601306
    12611307/* create an ac97 mixer interface */
    12621308static int __devinit
    1263 snd_nm256_mixer(nm256_t *chip)
    1264 {
    1265     ac97_bus_t *pbus;
    1266     ac97_template_t ac97;
    1267     int i, err;
    1268     static ac97_bus_ops_t ops = {
    1269         snd_nm256_ac97_reset,
    1270         snd_nm256_ac97_write,
    1271         snd_nm256_ac97_read,0,0
    1272     };
    1273     /* looks like nm256 hangs up when unexpected registers are touched... */
    1274     static int mixer_regs[] = {
    1275         AC97_MASTER, AC97_HEADPHONE, AC97_MASTER_MONO,
    1276         AC97_PC_BEEP, AC97_PHONE, AC97_MIC, AC97_LINE, AC97_CD,
    1277         AC97_VIDEO, AC97_AUX, AC97_PCM, AC97_REC_SEL,
    1278         AC97_REC_GAIN, AC97_GENERAL_PURPOSE, AC97_3D_CONTROL,
    1279         /*AC97_EXTENDED_ID,*/
    1280         AC97_VENDOR_ID1, AC97_VENDOR_ID2,
    1281         -1
    1282     };
    1283 
    1284     if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
    1285         return err;
    1286 
    1287     memset(&ac97, 0, sizeof(ac97));
    1288     ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */
    1289     ac97.limited_regs = 1;
    1290     for (i = 0; mixer_regs[i] >= 0; i++)
    1291         set_bit(mixer_regs[i], ac97.reg_accessed);
    1292     ac97.private_data = chip;
    1293     pbus->no_vra = 1;
    1294     err = snd_ac97_mixer(pbus, &ac97, &chip->ac97);
    1295     if (err < 0)
    1296         return err;
    1297     if (! (chip->ac97->id & (0xf0000000))) {
    1298         /* looks like an invalid id */
    1299         sprintf(chip->card->mixername, "%s AC97", chip->card->driver);
    1300     }
    1301     return 0;
    1302 }
    1303 
    1304 /*
     1309snd_nm256_mixer(struct nm256 *chip)
     1310{
     1311        struct snd_ac97_bus *pbus;
     1312        struct snd_ac97_template ac97;
     1313        int err;
     1314        static struct snd_ac97_bus_ops ops = {
     1315                .reset = snd_nm256_ac97_reset,
     1316                .write = snd_nm256_ac97_write,
     1317                .read = snd_nm256_ac97_read,
     1318        };
     1319
     1320        chip->ac97_regs = kcalloc(sizeof(short),
     1321                                  ARRAY_SIZE(nm256_ac97_init_val), GFP_KERNEL);
     1322        if (! chip->ac97_regs)
     1323                return -ENOMEM;
     1324
     1325        if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
     1326                return err;
     1327
     1328        memset(&ac97, 0, sizeof(ac97));
     1329        ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */
     1330        ac97.private_data = chip;
     1331        ac97.res_table = nm256_res_table;
     1332        pbus->no_vra = 1;
     1333        err = snd_ac97_mixer(pbus, &ac97, &chip->ac97);
     1334        if (err < 0)
     1335                return err;
     1336        if (! (chip->ac97->id & (0xf0000000))) {
     1337                /* looks like an invalid id */
     1338                sprintf(chip->card->mixername, "%s AC97", chip->card->driver);
     1339        }
     1340        return 0;
     1341}
     1342
     1343/*
    13051344 * See if the signature left by the NM256 BIOS is intact; if so, we use
    13061345 * the associated address as the end of our audio buffer in the video
     
    13091348
    13101349static int __devinit
    1311 snd_nm256_peek_for_sig(nm256_t *chip)
    1312 {
    1313     /* The signature is located 1K below the end of video RAM.  */
    1314     unsigned long temp;
    1315     /* Default buffer end is 5120 bytes below the top of RAM.  */
    1316     unsigned long pointer_found = chip->buffer_end - 0x1400;
    1317     u32 sig;
    1318 
    1319     temp = (unsigned long) ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
    1320     if (temp == 0) {
    1321         snd_printk("Unable to scan for card signature in video RAM\n");
    1322         return -EBUSY;
    1323     }
    1324 
    1325     sig = readl(temp);
    1326     if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
    1327         u32 pointer = readl(temp + 4);
    1328 
    1329         /*
    1330          * If it's obviously invalid, don't use it
    1331          */
    1332         if (pointer == 0xffffffff ||
    1333             pointer < chip->buffer_size ||
    1334             pointer > chip->buffer_end) {
    1335             snd_printk("invalid signature found: 0x%x\n", pointer);
    1336             iounmap((void *)temp);
    1337             return -ENODEV;
    1338         } else {
    1339             pointer_found = pointer;
    1340             printk(KERN_INFO "nm256: found card signature in video RAM: 0x%x\n", pointer);
    1341         }
    1342     }
    1343 
    1344     iounmap((void *)temp);
    1345     chip->buffer_end = pointer_found;
    1346 
    1347     return 0;
     1350snd_nm256_peek_for_sig(struct nm256 *chip)
     1351{
     1352        /* The signature is located 1K below the end of video RAM.  */
     1353        void __iomem *temp;
     1354        /* Default buffer end is 5120 bytes below the top of RAM.  */
     1355        unsigned long pointer_found = chip->buffer_end - 0x1400;
     1356        u32 sig;
     1357
     1358        temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
     1359        if (temp == NULL) {
     1360                snd_printk(KERN_ERR "Unable to scan for card signature in video RAM\n");
     1361                return -EBUSY;
     1362        }
     1363
     1364        sig = readl(temp);
     1365        if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
     1366                u32 pointer = readl(temp + 4);
     1367
     1368                /*
     1369                 * If it's obviously invalid, don't use it
     1370                 */
     1371                if (pointer == 0xffffffff ||
     1372                    pointer < chip->buffer_size ||
     1373                    pointer > chip->buffer_end) {
     1374                        snd_printk(KERN_ERR "invalid signature found: 0x%x\n", pointer);
     1375                        iounmap(temp);
     1376                        return -ENODEV;
     1377                } else {
     1378                        pointer_found = pointer;
     1379                        printk(KERN_INFO "nm256: found card signature in video RAM: 0x%x\n",
     1380                               pointer);
     1381                }
     1382        }
     1383
     1384        iounmap(temp);
     1385        chip->buffer_end = pointer_found;
     1386
     1387        return 0;
    13481388}
    13491389
     
    13531393 * event.
    13541394 */
    1355 static int nm256_suspend(snd_card_t *card, pm_message_t state)
    1356 {
    1357     nm256_t *chip = card->pm_private_data;
    1358     snd_pcm_suspend_all(chip->pcm);
    1359     snd_ac97_suspend(chip->ac97);
    1360     chip->coeffs_current = 0;
    1361     return 0;
    1362 }
    1363 
    1364 static int nm256_resume(snd_card_t *card, u32 state)
    1365 {
    1366     nm256_t *chip = card->pm_private_data;
    1367     int i;
    1368     /* Perform a full reset on the hardware */
    1369     pci_enable_device(chip->pci);
    1370     snd_nm256_init_chip(chip);
    1371 
    1372     /* restore ac97 */
    1373     snd_ac97_resume(chip->ac97);
    1374     for (i = 0; i < 2; i++) {
    1375         nm256_stream_t *s = &chip->streams[i];
    1376         if (s->substream && s->suspended) {
    1377             spin_lock_irq(&chip->reg_lock);
    1378             snd_nm256_set_format(chip, s, s->substream);
    1379             spin_unlock_irq(&chip->reg_lock);
    1380         }
    1381     }
    1382 
    1383     return 0;
     1395static int nm256_suspend(struct pci_dev *pci, pm_message_t state)
     1396{
     1397        struct snd_card *card = pci_get_drvdata(pci);
     1398        struct nm256 *chip = card->private_data;
     1399
     1400        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
     1401        snd_pcm_suspend_all(chip->pcm);
     1402        snd_ac97_suspend(chip->ac97);
     1403        chip->coeffs_current = 0;
     1404        pci_disable_device(pci);
     1405        pci_save_state(pci);
     1406        return 0;
     1407}
     1408
     1409static int nm256_resume(struct pci_dev *pci)
     1410{
     1411        struct snd_card *card = pci_get_drvdata(pci);
     1412        struct nm256 *chip = card->private_data;
     1413        int i;
     1414
     1415        /* Perform a full reset on the hardware */
     1416        chip->in_resume = 1;
     1417        pci_restore_state(pci);
     1418        pci_enable_device(pci);
     1419        snd_nm256_init_chip(chip);
     1420
     1421        /* restore ac97 */
     1422        snd_ac97_resume(chip->ac97);
     1423
     1424        for (i = 0; i < 2; i++) {
     1425                struct nm256_stream *s = &chip->streams[i];
     1426                if (s->substream && s->suspended) {
     1427                        spin_lock_irq(&chip->reg_lock);
     1428                        snd_nm256_set_format(chip, s, s->substream);
     1429                        spin_unlock_irq(&chip->reg_lock);
     1430                }
     1431        }
     1432
     1433        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     1434        chip->in_resume = 0;
     1435        return 0;
    13841436}
    13851437#endif /* CONFIG_PM */
    13861438
    1387 static int snd_nm256_free(nm256_t *chip)
    1388 {
    1389     if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
    1390         snd_nm256_playback_stop(chip);
    1391     if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
    1392         snd_nm256_capture_stop(chip);
    1393 
    1394     if (chip->irq >= 0)
    1395         synchronize_irq(chip->irq);
    1396 
    1397     if (chip->cport)
    1398         iounmap((void *) chip->cport);
    1399     if (chip->buffer)
    1400         iounmap((void *) chip->buffer);
    1401     if (chip->res_cport) {
    1402         release_resource(chip->res_cport);
    1403         kfree_nocheck(chip->res_cport);
    1404     }
    1405     if (chip->res_buffer) {
    1406         release_resource(chip->res_buffer);
    1407         kfree_nocheck(chip->res_buffer);
    1408     }
    1409     if (chip->irq >= 0)
    1410         free_irq(chip->irq, (void*)chip);
    1411 
    1412     kfree(chip);
    1413     return 0;
    1414 }
    1415 
    1416 static int snd_nm256_dev_free(snd_device_t *device)
    1417 {
    1418     nm256_t *chip = device->device_data;
    1419     return snd_nm256_free(chip);
     1439static int snd_nm256_free(struct nm256 *chip)
     1440{
     1441        if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running)
     1442                snd_nm256_playback_stop(chip);
     1443        if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running)
     1444                snd_nm256_capture_stop(chip);
     1445
     1446        if (chip->irq >= 0)
     1447                synchronize_irq(chip->irq);
     1448
     1449        if (chip->cport)
     1450                iounmap(chip->cport);
     1451        if (chip->buffer)
     1452                iounmap(chip->buffer);
     1453        release_and_free_resource(chip->res_cport);
     1454        release_and_free_resource(chip->res_buffer);
     1455        if (chip->irq >= 0)
     1456                free_irq(chip->irq, chip);
     1457
     1458        pci_disable_device(chip->pci);
     1459        kfree(chip->ac97_regs);
     1460        kfree(chip);
     1461        return 0;
     1462}
     1463
     1464static int snd_nm256_dev_free(struct snd_device *device)
     1465{
     1466        struct nm256 *chip = device->device_data;
     1467        return snd_nm256_free(chip);
    14201468}
    14211469
    14221470static int __devinit
    1423 snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
    1424                  int play_bufsize, int capt_bufsize,
    1425                  int force_load,
    1426                  u32 buffertop,
    1427                  int usecache,
    1428                  nm256_t **chip_ret)
    1429 {
    1430     nm256_t *chip;
    1431     int err, pval;
    1432 #ifdef TARGET_OS2
    1433     static snd_device_ops_t ops = {
    1434         snd_nm256_dev_free,0,0,0
    1435     };
    1436 #else
    1437     static snd_device_ops_t ops = {
    1438     dev_free:   snd_nm256_dev_free,
    1439     };
    1440 #endif
    1441     u32 addr;
    1442 
    1443     *chip_ret = NULL;
    1444 
    1445     chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
    1446     if (chip == NULL)
    1447         return -ENOMEM;
    1448 
    1449     chip->card = card;
    1450     chip->pci = pci;
    1451     chip->use_cache = usecache;
    1452     spin_lock_init(&chip->reg_lock);
    1453     chip->irq = -1;
    1454     init_MUTEX(&chip->irq_mutex);
    1455 
    1456     chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = play_bufsize;
    1457     chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capt_bufsize;
    1458 
    1459     /*
    1460      * The NM256 has two memory ports.  The first port is nothing
    1461      * more than a chunk of video RAM, which is used as the I/O ring
    1462      * buffer.  The second port has the actual juicy stuff (like the
    1463      * mixer and the playback engine control registers).
    1464      */
    1465 
    1466     chip->buffer_addr = pci_resource_start(pci, 0);
    1467     chip->cport_addr = pci_resource_start(pci, 1);
    1468 
    1469     /* Init the memory port info.  */
    1470     /* remap control port (#2) */
    1471     chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
    1472                                          card->driver);
    1473     if (chip->res_cport == NULL) {
    1474         snd_printk("memory region 0x%lx (size 0x%x) busy\n",
    1475                    chip->cport_addr, NM_PORT2_SIZE);
    1476         err = -EBUSY;
    1477         goto __error;
    1478     }
    1479     chip->cport = (unsigned long) ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
    1480     if (chip->cport == 0) {
    1481         snd_printk("unable to map control port %lx\n", chip->cport_addr);
    1482         err = -ENOMEM;
    1483         goto __error;
    1484     }
    1485 
    1486     if (!strcmp(card->driver, "NM256AV")) {
    1487         /* Ok, try to see if this is a non-AC97 version of the hardware. */
    1488         pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE);
    1489         if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
    1490             if (! force_load) {
    1491                 printk(KERN_ERR "nm256: no ac97 is found!\n");
    1492                 printk(KERN_ERR "  force the driver to load by passing in the module parameter\n");
    1493                 printk(KERN_ERR "    force_ac97=1\n");
    1494                 printk(KERN_ERR "  or try sb16 or cs423x drivers instead.\n");
    1495                 err = -ENXIO;
    1496                 goto __error;
    1497             }
    1498         }
    1499         chip->buffer_end = 2560 * 1024;
    1500         chip->interrupt = snd_nm256_interrupt;
    1501         chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
    1502         chip->mixer_status_mask = NM_MIXER_READY_MASK;
    1503     } else {
    1504         /* Not sure if there is any relevant detect for the ZX or not.  */
    1505         if (snd_nm256_readb(chip, 0xa0b) != 0)
    1506             chip->buffer_end = 6144 * 1024;
    1507         else
    1508             chip->buffer_end = 4096 * 1024;
    1509 
    1510         chip->interrupt = snd_nm256_interrupt_zx;
    1511         chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
    1512         chip->mixer_status_mask = NM2_MIXER_READY_MASK;
    1513     }
    1514 
    1515     chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize + chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
    1516     if (chip->use_cache)
    1517         chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4;
    1518     else
    1519         chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE;
    1520 
    1521     if (buffertop >= chip->buffer_size && buffertop < chip->buffer_end)
    1522         chip->buffer_end = buffertop;
    1523     else {
    1524         /* get buffer end pointer from signature */
    1525         if ((err = snd_nm256_peek_for_sig(chip)) < 0)
    1526             goto __error;
    1527     }
    1528 
    1529     chip->buffer_start = chip->buffer_end - chip->buffer_size;
    1530     chip->buffer_addr += chip->buffer_start;
    1531 
    1532     printk(KERN_INFO "nm256: Mapping port 1 from 0x%x - 0x%x\n",
    1533            chip->buffer_start, chip->buffer_end);
    1534 
    1535     chip->res_buffer = request_mem_region(chip->buffer_addr,
    1536                                           chip->buffer_size,
    1537                                           card->driver);
    1538     if (chip->res_buffer == NULL) {
    1539         snd_printk("nm256: buffer 0x%lx (size 0x%x) busy\n",
    1540                    chip->buffer_addr, chip->buffer_size);
    1541         err = -EBUSY;
    1542         goto __error;
    1543     }
    1544     chip->buffer = (unsigned long) ioremap_nocache(chip->buffer_addr, chip->buffer_size);
    1545     if (chip->buffer == 0) {
    1546         err = -ENOMEM;
    1547         snd_printk("unable to map ring buffer at %lx\n", chip->buffer_addr);
    1548         goto __error;
    1549     }
    1550 
    1551     /* set offsets */
    1552     addr = chip->buffer_start;
    1553     chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr;
    1554     addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize;
    1555     chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr;
    1556     addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
    1557     if (chip->use_cache) {
    1558         chip->all_coeff_buf = addr;
    1559     } else {
    1560         chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr;
    1561         addr += NM_MAX_PLAYBACK_COEF_SIZE;
    1562         chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr;
    1563     }
    1564 
    1565     /* Fixed setting. */
    1566     chip->mixer_base = NM_MIXER_OFFSET;
    1567 
    1568     chip->coeffs_current = 0;
    1569 
    1570     snd_nm256_init_chip(chip);
    1571 
    1572     // pci_set_master(pci); /* needed? */
    1573 
    1574     snd_card_set_pm_callback(card, nm256_suspend, nm256_resume, chip);
    1575     if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
    1576         goto __error;
    1577 
    1578     *chip_ret = chip;
    1579     return 0;
     1471snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
     1472                 struct nm256 **chip_ret)
     1473{
     1474        struct nm256 *chip;
     1475        int err, pval;
     1476        static struct snd_device_ops ops = {
     1477                .dev_free =     snd_nm256_dev_free,
     1478        };
     1479        u32 addr;
     1480
     1481        *chip_ret = NULL;
     1482
     1483        if ((err = pci_enable_device(pci)) < 0)
     1484                return err;
     1485
     1486        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
     1487        if (chip == NULL) {
     1488                pci_disable_device(pci);
     1489                return -ENOMEM;
     1490        }
     1491
     1492        chip->card = card;
     1493        chip->pci = pci;
     1494        chip->use_cache = use_cache;
     1495        spin_lock_init(&chip->reg_lock);
     1496        chip->irq = -1;
     1497        mutex_init(&chip->irq_mutex);
     1498
     1499        /* store buffer sizes in bytes */
     1500        chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = playback_bufsize * 1024;
     1501        chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capture_bufsize * 1024;
     1502
     1503        /*
     1504         * The NM256 has two memory ports.  The first port is nothing
     1505         * more than a chunk of video RAM, which is used as the I/O ring
     1506         * buffer.  The second port has the actual juicy stuff (like the
     1507         * mixer and the playback engine control registers).
     1508         */
     1509
     1510        chip->buffer_addr = pci_resource_start(pci, 0);
     1511        chip->cport_addr = pci_resource_start(pci, 1);
     1512
     1513        /* Init the memory port info.  */
     1514        /* remap control port (#2) */
     1515        chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
     1516                                             card->driver);
     1517        if (chip->res_cport == NULL) {
     1518                snd_printk(KERN_ERR "memory region 0x%lx (size 0x%x) busy\n",
     1519                           chip->cport_addr, NM_PORT2_SIZE);
     1520                err = -EBUSY;
     1521                goto __error;
     1522        }
     1523        chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
     1524        if (chip->cport == NULL) {
     1525                snd_printk(KERN_ERR "unable to map control port %lx\n", chip->cport_addr);
     1526                err = -ENOMEM;
     1527                goto __error;
     1528        }
     1529
     1530        if (!strcmp(card->driver, "NM256AV")) {
     1531                /* Ok, try to see if this is a non-AC97 version of the hardware. */
     1532                pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE);
     1533                if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
     1534                        if (! force_ac97) {
     1535                                printk(KERN_ERR "nm256: no ac97 is found!\n");
     1536                                printk(KERN_ERR "  force the driver to load by "
     1537                                       "passing in the module parameter\n");
     1538                                printk(KERN_ERR "    force_ac97=1\n");
     1539                                printk(KERN_ERR "  or try sb16 or cs423x drivers instead.\n");
     1540                                err = -ENXIO;
     1541                                goto __error;
     1542                        }
     1543                }
     1544                chip->buffer_end = 2560 * 1024;
     1545                chip->interrupt = snd_nm256_interrupt;
     1546                chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
     1547                chip->mixer_status_mask = NM_MIXER_READY_MASK;
     1548        } else {
     1549                /* Not sure if there is any relevant detect for the ZX or not.  */
     1550                if (snd_nm256_readb(chip, 0xa0b) != 0)
     1551                        chip->buffer_end = 6144 * 1024;
     1552                else
     1553                        chip->buffer_end = 4096 * 1024;
     1554
     1555                chip->interrupt = snd_nm256_interrupt_zx;
     1556                chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
     1557                chip->mixer_status_mask = NM2_MIXER_READY_MASK;
     1558        }
     1559       
     1560        chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize +
     1561                chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
     1562        if (chip->use_cache)
     1563                chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4;
     1564        else
     1565                chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE;
     1566
     1567        if (buffer_top >= chip->buffer_size && buffer_top < chip->buffer_end)
     1568                chip->buffer_end = buffer_top;
     1569        else {
     1570                /* get buffer end pointer from signature */
     1571                if ((err = snd_nm256_peek_for_sig(chip)) < 0)
     1572                        goto __error;
     1573        }
     1574
     1575        chip->buffer_start = chip->buffer_end - chip->buffer_size;
     1576        chip->buffer_addr += chip->buffer_start;
     1577
     1578        printk(KERN_INFO "nm256: Mapping port 1 from 0x%x - 0x%x\n",
     1579               chip->buffer_start, chip->buffer_end);
     1580
     1581        chip->res_buffer = request_mem_region(chip->buffer_addr,
     1582                                              chip->buffer_size,
     1583                                              card->driver);
     1584        if (chip->res_buffer == NULL) {
     1585                snd_printk(KERN_ERR "nm256: buffer 0x%lx (size 0x%x) busy\n",
     1586                           chip->buffer_addr, chip->buffer_size);
     1587                err = -EBUSY;
     1588                goto __error;
     1589        }
     1590        chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
     1591        if (chip->buffer == NULL) {
     1592                err = -ENOMEM;
     1593                snd_printk(KERN_ERR "unable to map ring buffer at %lx\n", chip->buffer_addr);
     1594                goto __error;
     1595        }
     1596
     1597        /* set offsets */
     1598        addr = chip->buffer_start;
     1599        chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr;
     1600        addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize;
     1601        chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr;
     1602        addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize;
     1603        if (chip->use_cache) {
     1604                chip->all_coeff_buf = addr;
     1605        } else {
     1606                chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr;
     1607                addr += NM_MAX_PLAYBACK_COEF_SIZE;
     1608                chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr;
     1609        }
     1610
     1611        /* Fixed setting. */
     1612        chip->mixer_base = NM_MIXER_OFFSET;
     1613
     1614        chip->coeffs_current = 0;
     1615
     1616        snd_nm256_init_chip(chip);
     1617
     1618        // pci_set_master(pci); /* needed? */
     1619       
     1620        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
     1621                goto __error;
     1622
     1623        snd_card_set_dev(card, &pci->dev);
     1624
     1625        *chip_ret = chip;
     1626        return 0;
    15801627
    15811628__error:
    1582     snd_nm256_free(chip);
    1583     return err;
    1584 }
     1629        snd_nm256_free(chip);
     1630        return err;
     1631}
     1632
    15851633
    15861634struct nm256_quirk {
     
    15901638};
    15911639
    1592 enum { NM_BLACKLISTED, NM_RESET_WORKAROUND };
     1640enum { NM_BLACKLISTED, NM_RESET_WORKAROUND, NM_RESET_WORKAROUND_2 };
    15931641
    15941642static struct nm256_quirk nm256_quirks[] __devinitdata = {
    15951643        /* HP omnibook 4150 has cs4232 codec internally */
    1596         { 0x103c, 0x0007, NM_BLACKLISTED },
     1644        { .vendor = 0x103c, .device = 0x0007, .type = NM_BLACKLISTED },
    15971645        /* Sony PCG-F305 */
    1598         { 0x104d, 0x8041, NM_RESET_WORKAROUND },
     1646        { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND },
    15991647        /* Dell Latitude LS */
    1600         { 0x1028, 0x0080, NM_RESET_WORKAROUND },
    1601         {0 } /* terminator */
     1648        { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND },
     1649        /* Dell Latitude CSx */
     1650        { .vendor = 0x1028, .device = 0x0091, .type = NM_RESET_WORKAROUND_2 },
     1651        {0} /* terminator */
    16021652};
    16031653
    16041654
    16051655static int __devinit snd_nm256_probe(struct pci_dev *pci,
    1606                                      const struct pci_device_id *pci_id)
    1607 {
    1608     static int dev;
    1609     snd_card_t *card;
    1610     nm256_t *chip;
    1611     int err;
    1612     unsigned int xbuffer_top;
    1613     struct nm256_quirk *q;
    1614     u16 subsystem_vendor, subsystem_device;
    1615 
    1616     if ((err = pci_enable_device(pci)) < 0)
    1617         return err;
    1618 
    1619     if (dev >= SNDRV_CARDS)
    1620         return -ENODEV;
    1621     if (!enable[dev]) {
    1622         dev++;
    1623         return -ENOENT;
    1624     }
    1625 
    1626     pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
    1627     pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
    1628 
    1629     for (q = nm256_quirks; q->vendor; q++) {
    1630         if (q->vendor == subsystem_vendor && q->device == subsystem_device) {
    1631             switch (q->type) {
    1632             case NM_BLACKLISTED:
    1633                 printk(KERN_INFO "nm256: The device is blacklisted.  Loading stopped\n");
    1634                 return -ENODEV;
    1635             case NM_RESET_WORKAROUND:
    1636                 reset_workaround[dev] = 1;
    1637                 break;
    1638             }
    1639         }
    1640     }
    1641 
    1642     card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
    1643     if (card == NULL)
    1644         return -ENOMEM;
    1645 
    1646     switch (pci->device) {
    1647     case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO:
    1648         strcpy(card->driver, "NM256AV");
    1649         break;
    1650     case PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO:
    1651         strcpy(card->driver, "NM256ZX");
    1652         break;
    1653     default:
    1654         snd_printk("invalid device id 0x%x\n", pci->device);
    1655         snd_card_free(card);
    1656         return -EINVAL;
    1657     }
    1658 
    1659     if (vaio_hack[dev])
    1660         xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */
    1661     else
    1662         xbuffer_top = buffer_top[dev];
    1663 
    1664     if (playback_bufsize[dev] < 4)
    1665         playback_bufsize[dev] = 4;
    1666     if (playback_bufsize[dev] > 128)
    1667         playback_bufsize[dev] = 128;
    1668     if (capture_bufsize[dev] < 4)
    1669         capture_bufsize[dev] = 4;
    1670     if (capture_bufsize[dev] > 128)
    1671         capture_bufsize[dev] = 128;
    1672     if ((err = snd_nm256_create(card, pci,
    1673                                 playback_bufsize[dev] * 1024, /* in bytes */
    1674                                 capture_bufsize[dev] * 1024,  /* in bytes */
    1675                                 force_ac97[dev],
    1676                                 xbuffer_top,
    1677                                 use_cache[dev],
    1678                                 &chip)) < 0) {
    1679         snd_card_free(card);
    1680         return err;
    1681     }
    1682 
    1683     if (reset_workaround[dev]) {
    1684         snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
    1685         chip->reset_workaround = 1;
    1686     }
    1687     if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
    1688         (err = snd_nm256_mixer(chip)) < 0) {
    1689         snd_card_free(card);
    1690         return err;
    1691     }
    1692 
    1693     sprintf(card->shortname, "NeoMagic %s", card->driver);
    1694     sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d",
    1695             card->shortname,
    1696             chip->buffer_addr, chip->cport_addr, chip->irq);
    1697 
    1698     if ((err = snd_card_register(card)) < 0) {
    1699         snd_card_free(card);
    1700         return err;
    1701     }
    1702 
    1703     pci_set_drvdata(pci, card);
    1704     dev++;
    1705     return 0;
     1656                                     const struct pci_device_id *pci_id)
     1657{
     1658        struct snd_card *card;
     1659        struct nm256 *chip;
     1660        int err;
     1661        struct nm256_quirk *q;
     1662        u16 subsystem_vendor, subsystem_device;
     1663
     1664        pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
     1665        pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
     1666
     1667        for (q = nm256_quirks; q->vendor; q++) {
     1668                if (q->vendor == subsystem_vendor && q->device == subsystem_device) {
     1669                        switch (q->type) {
     1670                        case NM_BLACKLISTED:
     1671                                printk(KERN_INFO "nm256: The device is blacklisted. "
     1672                                       "Loading stopped\n");
     1673                                return -ENODEV;
     1674                        case NM_RESET_WORKAROUND_2:
     1675                                reset_workaround_2 = 1;
     1676                                /* Fall-through */
     1677                        case NM_RESET_WORKAROUND:
     1678                                reset_workaround = 1;
     1679                                break;
     1680                        }
     1681                }
     1682        }
     1683
     1684        card = snd_card_new(index, id, THIS_MODULE, 0);
     1685        if (card == NULL)
     1686                return -ENOMEM;
     1687
     1688        switch (pci->device) {
     1689        case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO:
     1690                strcpy(card->driver, "NM256AV");
     1691                break;
     1692        case PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO:
     1693                strcpy(card->driver, "NM256ZX");
     1694                break;
     1695        case PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO:
     1696                strcpy(card->driver, "NM256XL+");
     1697                break;
     1698        default:
     1699                snd_printk(KERN_ERR "invalid device id 0x%x\n", pci->device);
     1700                snd_card_free(card);
     1701                return -EINVAL;
     1702        }
     1703
     1704        if (vaio_hack)
     1705                buffer_top = 0x25a800;  /* this avoids conflicts with XFree86 server */
     1706
     1707        if (playback_bufsize < 4)
     1708                playback_bufsize = 4;
     1709        if (playback_bufsize > 128)
     1710                playback_bufsize = 128;
     1711        if (capture_bufsize < 4)
     1712                capture_bufsize = 4;
     1713        if (capture_bufsize > 128)
     1714                capture_bufsize = 128;
     1715        if ((err = snd_nm256_create(card, pci, &chip)) < 0) {
     1716                snd_card_free(card);
     1717                return err;
     1718        }
     1719        card->private_data = chip;
     1720
     1721        if (reset_workaround) {
     1722                snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
     1723                chip->reset_workaround = 1;
     1724        }
     1725
     1726        if (reset_workaround_2) {
     1727                snd_printdd(KERN_INFO "nm256: reset_workaround_2 activated\n");
     1728                chip->reset_workaround_2 = 1;
     1729        }
     1730
     1731        if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
     1732            (err = snd_nm256_mixer(chip)) < 0) {
     1733                snd_card_free(card);
     1734                return err;
     1735        }
     1736
     1737        sprintf(card->shortname, "NeoMagic %s", card->driver);
     1738        sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d",
     1739                card->shortname,
     1740                chip->buffer_addr, chip->cport_addr, chip->irq);
     1741
     1742        if ((err = snd_card_register(card)) < 0) {
     1743                snd_card_free(card);
     1744                return err;
     1745        }
     1746
     1747        pci_set_drvdata(pci, card);
     1748        return 0;
    17061749}
    17071750
    17081751static void __devexit snd_nm256_remove(struct pci_dev *pci)
    17091752{
    1710     snd_card_free(pci_get_drvdata(pci));
    1711     pci_set_drvdata(pci, NULL);
    1712 }
     1753        snd_card_free(pci_get_drvdata(pci));
     1754        pci_set_drvdata(pci, NULL);
     1755}
     1756
    17131757
    17141758static struct pci_driver driver = {
    1715     0,0,0,"NeoMagic 256",
    1716     snd_nm256_ids,
    1717     snd_nm256_probe,
    1718     snd_nm256_remove,
    1719     SND_PCI_PM_CALLBACKS
     1759        .name = "NeoMagic 256",
     1760        .id_table = snd_nm256_ids,
     1761        .probe = snd_nm256_probe,
     1762        .remove = snd_nm256_remove,
     1763#ifdef CONFIG_PM
     1764        .suspend = nm256_suspend,
     1765        .resume = nm256_resume,
     1766#endif
    17201767};
    17211768
     1769
    17221770static int __init alsa_card_nm256_init(void)
    17231771{
    1724     int err;
    1725     if ((err = pci_module_init(&driver)) < 0) {
    1726 #ifdef MODULE
    1727         //              printk(KERN_ERR "NeoMagic 256 audio soundchip not found or device busy\n");
    1728 #endif
    1729         return err;
    1730     }
    1731     return 0;
     1772        return pci_register_driver(&driver);
    17321773}
    17331774
    17341775static void __exit alsa_card_nm256_exit(void)
    17351776{
    1736     pci_unregister_driver(&driver);
     1777        pci_unregister_driver(&driver);
    17371778}
    17381779
    17391780module_init(alsa_card_nm256_init)
    17401781module_exit(alsa_card_nm256_exit)
    1741 
    1742 #ifndef MODULE
    1743 
    1744 /* format is: snd-nm256=enable,index,id,
    1745  playback_bufsize,capture_bufsize,
    1746  force_ac97,buffer_top,use_cache */
    1747 
    1748 static int __init alsa_card_nm256_setup(char *str)
    1749 {
    1750     static unsigned __initdata nr_dev = 0;
    1751 
    1752     if (nr_dev >= SNDRV_CARDS)
    1753         return 0;
    1754     (void)(get_option(&str,&enable[nr_dev]) == 2 &&
    1755            get_option(&str,&index[nr_dev]) == 2 &&
    1756            get_id(&str,&id[nr_dev]) == 2 &&
    1757            get_option(&str,&playback_bufsize[nr_dev]) == 2 &&
    1758            get_option(&str,&capture_bufsize[nr_dev]) == 2 &&
    1759            get_option(&str,&force_ac97[nr_dev]) == 2 &&
    1760            get_option(&str,&buffer_top[nr_dev]) == 2 &&
    1761            get_option(&str,&use_cache[nr_dev]) == 2);
    1762     nr_dev++;
    1763     return 1;
    1764 }
    1765 
    1766 __setup("snd-nm256=", alsa_card_nm256_setup);
    1767 
    1768 #endif /* ifndef MODULE */
  • GPL/trunk/alsa-kernel/pci/via82xx.c

    r70 r76  
    23632363                { .subvendor = 0x1462, .subdevice = 0x7023, .action = VIA_DXS_NO_VRA }, /* MSI K8T Neo2-FI */
    23642364                { .subvendor = 0x1462, .subdevice = 0x7120, .action = VIA_DXS_ENABLE }, /* MSI KT4V */
    2365                 { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */
     2365                { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */
     2366                { .subvendor = 0x1462, .subdevice = 0xb012, .action = VIA_DXS_SRC }, /* P4M800/VIA8237R */
    23662367                { .subvendor = 0x147b, .subdevice = 0x1401, .action = VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */
    23672368                { .subvendor = 0x147b, .subdevice = 0x1411, .action = VIA_DXS_ENABLE }, /* ABIT VA-20 */
     
    23762377                { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */
    23772378                { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */
    2378                 { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */
    2379                 { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */
    2380                 { .subvendor = 0x1849, .subdevice = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */
     2379                { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */
     2380                { .subvendor = 0x1695, .subdevice = 0x300c, .action = VIA_DXS_SRC }, /* EPoX EP-8KRAI */
     2381                { .subvendor = 0x1695, .subdevice = 0x300e, .action = VIA_DXS_SRC }, /* EPoX 9HEAI */
     2382                { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */
     2383                { .subvendor = 0x1734, .subdevice = 0x1078, .action = VIA_DXS_SRC }, /* FSC Amilo L7300 */
     2384                { .subvendor = 0x1734, .subdevice = 0x1093, .action = VIA_DXS_SRC }, /* FSC */
     2385                { .subvendor = 0x1849, .subdevice = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */                { .subvendor = 0x1849, .subdevice = 0x9739, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */
    23812386                { .subvendor = 0x1849, .subdevice = 0x9761, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */
    23822387                { .subvendor = 0x1919, .subdevice = 0x200a, .action = VIA_DXS_NO_VRA }, /* Soltek SL-K8Tpro-939 */
  • GPL/trunk/drv32/pciids.h

    r32 r76  
    7878#define PCIID_INTEL_ICH6           ((PCI_DEVICE_ID_INTEL_ICH6<<16)     | PCI_VENDOR_ID_INTEL)
    7979#define PCIID_INTEL_ICH7           ((PCI_DEVICE_ID_INTEL_ICH7<<16)     | PCI_VENDOR_ID_INTEL)
    80 #define PCIID_SI_7012              0x7012
     80#define PCIID_SI_7012              0x70121039
    8181
    82 #define PCIID_NVIDIA_MCP_AUDIO     0x10de01b1
    83 #define PCIID_NVIDIA_MCP2_AUDIO    0x10de006a
    84 #define PCIID_NVIDIA_MCP3_AUDIO    0x10de00da
    85 #define PCIID_NVIDIA_CK8S_AUDIO    0x10de00ea
    86 #define PCIID_NVIDIA_CK8_AUDIO     0x10de008a
    87 
     82#define PCIID_NVIDIA_MCP_AUDIO     0x01b110de
     83#define PCIID_NVIDIA_MCP2_AUDIO    0x006a10de
     84#define PCIID_NVIDIA_MCP3_AUDIO    0x00da10de
     85#define PCIID_NVIDIA_CK8S_AUDIO    0x00ea10de
     86#define PCIID_NVIDIA_CK8_AUDIO     0x008a10de
    8887
    8988#define PCIID_CIRRUS_4281          ((PCI_DEVICE_ID_CIRRUS_4281<<16)    | PCI_VENDOR_ID_CIRRUS)
  • GPL/trunk/include/version.mak

    r63 r76  
    1111BLDLVL_REVISION = 1.1
    1212BLDLVL_FILEVER = 4
    13 BLDLVL_DATETIME = 04.01.2006 00:19:06
     13BLDLVL_DATETIME = 31.03.2006 01:05:34
    1414BLDLVL_MACHINE = VLAD
  • GPL/trunk/lib32/fminstrload.c

    r34 r76  
    125125//******************************************************************************
    126126
    127 #ifdef DEBUG
     127#if 0
     128//def DEBUG
    128129/*
    129130 * Show instrument FM operators
  • GPL/trunk/lib32/ioctl.c

    r32 r76  
    10631063                if (fileid == opened_handles[i].FileId)
    10641064                {
     1065                    opened_handles[i].reuse = 0;
    10651066                    if (OSS32_WaveClose((OSSSTREAMID)opened_handles[i].handle) == 0)
    10661067                        opened_handles[i].handle = 0;
     
    10691070            else
    10701071            {
     1072                opened_handles[i].reuse = 0;
    10711073                if (OSS32_WaveClose((OSSSTREAMID)opened_handles[i].handle) == 0)
    10721074                    opened_handles[i].handle = 0;
  • GPL/trunk/lib32/irq.c

    r63 r76  
    4545
    4646static IRQ_SLOT         arSlots[MAX_IRQ_SLOTS] = { 0 };
     47static ULONG           eoiIrq[255] = {0};
    4748
    4849
     
    5152static IRQ_SLOT *FindSlot(unsigned irq)
    5253{
    53   IRQ_SLOT      *pSlot;
    54 
    55   for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
    56   {
    57     if( pSlot->irqNo == irq )   return pSlot;
    58   }
    59 
    60   return NULL;
     54    IRQ_SLOT      *pSlot;
     55
     56    for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
     57    {
     58        if( pSlot->irqNo == irq )   return pSlot;
     59    }
     60
     61    return NULL;
    6162}
    6263
     
    7172    IRQ_SLOT    *pSlot = FindSlot(irq);
    7273    unsigned    u, uSlotNo = (unsigned)-1;
    73   if( !pSlot )
    74   {
    75     // find empty slot
    76     for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ )
    77     {
    78       if( arSlots[uSlotNo].flHandlers == 0 )
    79       {
    80         pSlot = &arSlots[uSlotNo];      break;
    81       }
    82     }
    83 
    84     }
    85 
    86   if( pSlot )
    87   {
    88     if(RMRequestIRQ(/*hResMgr,*/ irq, (x0 & SA_SHIRQ) != 0) == FALSE) {
    89         dprintf(("RMRequestIRQ failed for irq %d", irq));
    90 //      return 0;
    91     }
    92 
    93     for( u = 0; u < MAX_SHAREDIRQS; u++ )
    94     {
    95       if( pSlot->irqHandlers[u].handler == NULL )
    96       {
    97           pSlot->irqNo = irq;
    98         pSlot->irqHandlers[u].handler = handler;
    99         pSlot->irqHandlers[u].x0 = x0;
    100         pSlot->irqHandlers[u].x1 = (char *)x1;
    101         pSlot->irqHandlers[u].x2 = x2;
    102 
    103         if( pSlot->flHandlers != 0 ||
    104             ALSA_SetIrq(irq, uSlotNo, (x0 & SA_SHIRQ) != 0) )
     74    if( !pSlot )
     75    {
     76        // find empty slot
     77        for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ )
     78        {
     79            if( arSlots[uSlotNo].flHandlers == 0 )
     80            {
     81                pSlot = &arSlots[uSlotNo];      break;
     82            }
     83        }
     84
     85    }
     86
     87    if( pSlot )
     88    {
     89        if(RMRequestIRQ(/*hResMgr,*/ irq, (x0 & SA_SHIRQ) != 0) == FALSE) {
     90            dprintf(("RMRequestIRQ failed for irq %d", irq));
     91            //  return 0;
     92        }
     93
     94        for( u = 0; u < MAX_SHAREDIRQS; u++ )
     95        {
     96            if( pSlot->irqHandlers[u].handler == NULL )
     97            {
     98                pSlot->irqNo = irq;
     99                pSlot->irqHandlers[u].handler = handler;
     100                pSlot->irqHandlers[u].x0 = x0;
     101                pSlot->irqHandlers[u].x1 = (char *)x1;
     102                pSlot->irqHandlers[u].x2 = x2;
     103
     104                if( pSlot->flHandlers != 0 ||
     105                   ALSA_SetIrq(irq, uSlotNo, (x0 & SA_SHIRQ) != 0) )
    105106                {
    106           pSlot->flHandlers |= 1 << u;
    107           return 0;
     107                    pSlot->flHandlers |= 1 << u;
     108                    return 0;
    108109                }
    109110
    110         break;
    111             }
    112         }
    113     }
    114 
    115   dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
     111                break;
     112            }
     113        }
     114    }
     115
     116    dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
    116117    return 1;
    117118}
     
    122123void free_irq(unsigned int irq, void *userdata)
    123124{
    124   unsigned      u;
    125   IRQ_SLOT      *pSlot;
    126 
    127   if( (pSlot = FindSlot(irq)) != NULL )
    128   {
    129     for( u = 0; u < MAX_SHAREDIRQS; u++ )
    130     {
    131       if( pSlot->irqHandlers[u].x2 == userdata )
    132       {
    133         pSlot->flHandlers &= ~(1 << u);
    134         if( pSlot->flHandlers == 0 )
    135         {
    136           ALSA_FreeIrq(pSlot->irqNo);
    137           pSlot->irqNo = 0;
    138 //        pSlot->fEOI = 0;
    139             }
    140 
    141         pSlot->irqHandlers[u].handler = NULL;
    142         pSlot->irqHandlers[u].x0 = 0;
    143         pSlot->irqHandlers[u].x1 = NULL;
    144         pSlot->irqHandlers[u].x2 = NULL;
    145 
    146         return;
    147 
    148       }
    149     }
    150 }
     125    unsigned    u;
     126    IRQ_SLOT    *pSlot;
     127
     128    if( (pSlot = FindSlot(irq)) != NULL )
     129    {
     130        for( u = 0; u < MAX_SHAREDIRQS; u++ )
     131        {
     132            if( pSlot->irqHandlers[u].x2 == userdata )
     133            {
     134                pSlot->flHandlers &= ~(1 << u);
     135                if( pSlot->flHandlers == 0 )
     136                {
     137                    ALSA_FreeIrq(pSlot->irqNo);
     138                    pSlot->irqNo = 0;
     139                    //    pSlot->fEOI = 0;
     140                }
     141
     142                pSlot->irqHandlers[u].handler = NULL;
     143                pSlot->irqHandlers[u].x0 = 0;
     144                pSlot->irqHandlers[u].x1 = NULL;
     145                pSlot->irqHandlers[u].x2 = NULL;
     146
     147                return;
     148
     149            }
     150        }
     151    }
    151152}
    152153
     
    156157void eoi_irq(unsigned int irq)
    157158{
    158   (void)irq;
    159 /*
    160   IRQ_SLOT      *pSlot = FindSlot(irq);
    161 
    162   if( pSlot )   pSlot->fEOI = 1;
    163 */
     159    /*(void)irq; */
     160    /*
     161     IRQ_SLOT   *pSlot = FindSlot(irq);
     162
     163     if( pSlot )        pSlot->fEOI = 1;
     164     */
     165    eoiIrq[irq]++;
    164166}
    165167
     
    169171BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq)
    170172{
    171   unsigned      u;
    172  int rc;
    173   IRQ_SLOT      *pSlot;
    174 
    175 #ifdef DEBUG
    176 // dprintf(("int proc"));
    177 #endif
    178 
    179     if(fSuspended) 
     173    unsigned    u;
     174    int rc;
     175    IRQ_SLOT    *pSlot;
     176
     177#ifdef DEBUG
     178    dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
     179#endif
     180
     181    if(fSuspended)
    180182    {//If our device is suspended, then we can't receive interrupts, so it must
    181      //be for some other device
    182      //Don't pass it to the linux handler as the device doesn't respond as expected
     183        //be for some other device
     184        //Don't pass it to the linux handler as the device doesn't respond as expected
    183185        //when suspended
    184186#ifdef DEBUG
    185         dprintf(("IRQ %d suspended",irq));
     187        dprintf(("Slot %d IRQ %d suspended",ulSlotNo, *pulIrq));
    186188#endif
    187189        return FALSE;
    188190    }
    189191
    190   if( ulSlotNo < MAX_IRQ_SLOTS )
    191     {
    192     pSlot = &arSlots[ulSlotNo];
    193 
    194     for( u = 0; u < MAX_SHAREDIRQS; u++ )
    195     {
    196       if( pSlot->irqHandlers[u].handler )
    197         {
    198             fInInterrupt = TRUE;
    199         rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
    200                                            pSlot->irqHandlers[u].x2, 0);
    201             fInInterrupt = FALSE;
    202 
    203         if( rc /*== 1 || pSlot->fEOI*/ ) {
    204 
    205             *pulIrq = pSlot->irqNo;
    206 //          pSlot->fEOI = 0;
    207 
    208                 //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
    209                 OSS32_ProcessIRQ();
    210                 return TRUE;
    211             }
    212         }
    213     }
    214     }
     192    if( ulSlotNo < MAX_IRQ_SLOTS )
     193    {
     194        pSlot = &arSlots[ulSlotNo];
     195
     196        for( u = 0; u < MAX_SHAREDIRQS; u++ )
     197        {
     198            if(pSlot && pSlot->irqHandlers[u].handler )
     199            {
     200                fInInterrupt = TRUE;
     201                rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
     202                                                   pSlot->irqHandlers[u].x2, 0);
     203                if (rc == 1) eoi_irq(pSlot->irqNo);
     204                rc = (eoiIrq[pSlot->irqNo] > 0);
     205                fInInterrupt = FALSE;
     206
     207                if( rc /*== 1 || pSlot->fEOI*/ ) {
     208
     209                    *pulIrq = pSlot->irqNo;
     210                    //      pSlot->fEOI = 0;
     211
     212                    //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
     213                    OSS32_ProcessIRQ();
     214#ifdef DEBUG
     215                    dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
     216#endif
     217                    eoiIrq[pSlot->irqNo] = 0;
     218                    return TRUE;
     219                }
     220            }
     221        }
     222    }
     223#ifdef DEBUG
     224                    dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
     225#endif
    215226
    216227    return FALSE;
     
    236247//******************************************************************************
    237248
    238 
    239 
  • GPL/trunk/lib32/memory.cpp

    r32 r76  
    195195    if (rc == 0) {
    196196        *pAddr = (LINEAR)addr;
     197        if (flags & VMDHA_USEHIGHMEM)
     198            dprintf(("allocated %X in HIGH memory"), size);
     199        else dprintf(("allocated %X in LOW memory"), size);
    197200    }
    198201    if ((rc == 87) &&
  • GPL/trunk/lib32/ossidc.cpp

    r34 r76  
    268268        fnCardExitCall[nrCardsDetected] = name_module_exit(alsa_card_ca0106_exit);
    269269    }
     270    if((ForceCard == CARD_NONE || ForceCard == CARD_AZX) &&
     271       nrCardsDetected < (OSS32_MAX_AUDIOCARDS-1) && call_module_init(alsa_card_azx_init) == 0)
     272    {
     273        fnCardExitCall[nrCardsDetected] = name_module_exit(alsa_card_azx_exit);
     274    }
    270275    if((ForceCard == CARD_NONE || ForceCard == CARD_BT87X) &&
    271276       nrCardsDetected < (OSS32_MAX_AUDIOCARDS-1) && call_module_init(alsa_card_bt87x_init) == 0)
     
    273278        fnCardExitCall[nrCardsDetected] = name_module_exit(alsa_card_bt87x_exit);
    274279    }
    275     if((ForceCard == CARD_NONE || ForceCard == CARD_AZX) &&
    276        nrCardsDetected < (OSS32_MAX_AUDIOCARDS-1) && call_module_init(alsa_card_azx_init) == 0)
    277     {
    278         fnCardExitCall[nrCardsDetected] = name_module_exit(alsa_card_azx_exit);
    279     }
     280
    280281#endif
    281282    fStrategyInit = FALSE;
  • GPL/trunk/lib32/pci.c

    r75 r76  
    465465
    466466                    // create adapter
    467                     RMDone((driver->id_table[i].vendor << 16) | driver->id_table[i].device);
     467                    RMDone((driver->id_table[i].device << 16) | driver->id_table[i].vendor);
    468468                    nrCardsDetected++;
    469469                    return 1;
  • GPL/trunk/lib32/sound.c

    r34 r76  
    775775        return OSSERR_INVALID_PARAMETER;
    776776    }
    777 
     777tryagain:
    778778    //set operation to non-blocking
    779779    pHandle->file.f_flags = O_NONBLOCK;
     
    950950    //initialize parameter block & set sample rate, nr of channels and sample format, nr of periods,
    951951    //period size and buffer size
    952 tryagain:
     952//tryagain:
    953953    _snd_pcm_hw_params_any(&params);
    954954    _snd_pcm_hw_param_set(&params, SNDRV_PCM_HW_PARAM_ACCESS,
  • GPL/trunk/lib32/stack.cpp

    r32 r76  
    7777        //allocate our private stack
    7878        rc = DevVMAlloc(VMDHA_USEHIGHMEM|VMDHA_FIXED|VMDHL_CONTIGUOUS, TOTAL_STACKSIZE, (LINEAR)-1, (LINEAR)&StackBase);
     79
    7980        if(rc) {
    80             DebugInt3();
    81             return 0;
     81            if (rc == 87)
     82            {
     83                rc = DevVMAlloc(VMDHA_FIXED|VMDHL_CONTIGUOUS, TOTAL_STACKSIZE, (LINEAR)-1, (LINEAR)&StackBase);
     84            }
     85            if (rc)
     86            {
     87                DebugInt3();
     88                return 0;
     89            }
    8290        }
    8391        Ring0Stack[0].addr = StackBase;
  • GPL/trunk/lib32/timer.c

    r32 r76  
    9494void do_gettimeofday(struct timeval *tv)
    9595{
     96#if 0
    9697    tv->tv_sec  = 0; //os2gettimesec();
    9798    tv->tv_usec = os2gettimemsec() * 1000;
     99#else /* r.ihle patch */
     100    unsigned u = os2gettimemsec();
     101    tv->tv_sec  = u / 1000;
     102    tv->tv_usec = (u % 1000) * 1000;
     103#endif
    98104}
    99105//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.