Ignore:
Timestamp:
Oct 23, 2006, 11:07:11 PM (19 years ago)
Author:
vladest
Message:

SB code update
HDA code update
Some other updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/alsa-kernel/pci/emu10k1/p16v.c

    r34 r84  
    100100#include <sound/ac97_codec.h>
    101101#include <sound/info.h>
     102#include <sound/tlv.h>
    102103#include <sound/emu10k1.h>
    103104#include "p16v.h"
     
    107108#define PCM_REAR_CHANNEL 1
    108109#define PCM_CENTER_LFE_CHANNEL 2
    109 #define PCM_UNKNOWN_CHANNEL 3
     110#define PCM_SIDE_CHANNEL 3
    110111#define CONTROL_FRONT_CHANNEL 0
    111112#define CONTROL_REAR_CHANNEL 3
    112113#define CONTROL_CENTER_LFE_CHANNEL 1
    113 #define CONTROL_UNKNOWN_CHANNEL 2
     114#define CONTROL_SIDE_CHANNEL 2
    114115
    115116/* Card IDs:
     
    122123
    123124/* hardware definition */
    124 static snd_pcm_hardware_t snd_p16v_playback_hw = {
    125     /*.info =                  */ (SNDRV_PCM_INFO_MMAP |
    126                                  SNDRV_PCM_INFO_INTERLEAVED |
    127                                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
    128                                  SNDRV_PCM_INFO_MMAP_VALID),
    129     /* .formats =             */     SNDRV_PCM_FMTBIT_S32_LE, /* Only supports 24-bit samples padded to 32 bits. */
    130     /* .rates =       */     SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
    131     /* .rate_min =            */  44100,
    132     /* .rate_max =            */  192000,
    133     /* .channels_min =    */    8,
    134     /* .channels_max =    */    8,
    135     /* .buffer_bytes_max =*/    ((65536 - 64) * 8),
    136     /* .period_bytes_min =*/    64,
    137     /* .period_bytes_max =*/    (65536 - 64),
    138     /* .periods_min =     */    2,
    139     /* .periods_max =     */    8,
    140     /* .fifo_size =           */  0
     125static struct snd_pcm_hardware snd_p16v_playback_hw = {
     126        .info =                 (SNDRV_PCM_INFO_MMAP |
     127                                 SNDRV_PCM_INFO_INTERLEAVED |
     128                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     129                                 SNDRV_PCM_INFO_RESUME |
     130                                 SNDRV_PCM_INFO_MMAP_VALID),
     131        .formats =              SNDRV_PCM_FMTBIT_S32_LE, /* Only supports 24-bit samples padded to 32 bits. */
     132        .rates =                SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
     133        .rate_min =             44100,
     134        .rate_max =             192000,
     135        .channels_min =         8,
     136        .channels_max =         8,
     137        .buffer_bytes_max =     ((65536 - 64) * 8),
     138        .period_bytes_min =     64,
     139        .period_bytes_max =     (65536 - 64),
     140        .periods_min =          2,
     141        .periods_max =          8,
     142        .fifo_size =            0,
    141143};
    142144
    143 static snd_pcm_hardware_t snd_p16v_capture_hw = {
    144     /*.info =                */ (SNDRV_PCM_INFO_MMAP |
    145                              SNDRV_PCM_INFO_INTERLEAVED |
    146                              SNDRV_PCM_INFO_BLOCK_TRANSFER |
    147                              SNDRV_PCM_INFO_MMAP_VALID),
    148     /*  .formats =            */  SNDRV_PCM_FMTBIT_S32_LE,
    149     /*  .rates =              */  SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
    150     /*  .rate_min =           */  44100,
    151     /*  .rate_max =           */  192000,
    152     /*  .channels_min =       */  2,
    153     /*  .channels_max =       */  2,
    154     /*  .buffer_bytes_max =   */  (65536 - 64),
    155     /*  .period_bytes_min =   */  64,
    156     /*  .period_bytes_max =   */  (65536 - 128) >> 1,  /* size has to be N*64 bytes */
    157     /*  .periods_min =        */  2,
    158     /*  .periods_max =        */  2,
    159     /*  .fifo_size =          */  0
     145static struct snd_pcm_hardware snd_p16v_capture_hw = {
     146        .info =                 (SNDRV_PCM_INFO_MMAP |
     147                                 SNDRV_PCM_INFO_INTERLEAVED |
     148                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     149                                 SNDRV_PCM_INFO_RESUME |
     150                                 SNDRV_PCM_INFO_MMAP_VALID),
     151        .formats =              SNDRV_PCM_FMTBIT_S32_LE,
     152        .rates =                SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100,
     153        .rate_min =             44100,
     154        .rate_max =             192000,
     155        .channels_min =         2,
     156        .channels_max =         2,
     157        .buffer_bytes_max =     (65536 - 64),
     158        .period_bytes_min =     64,
     159        .period_bytes_max =     (65536 - 128) >> 1,  /* size has to be N*64 bytes */
     160        .periods_min =          2,
     161        .periods_max =          2,
     162        .fifo_size =            0,
    160163};
    161164
    162 static void snd_p16v_pcm_free_substream(snd_pcm_runtime_t *runtime)
     165static void snd_p16v_pcm_free_substream(struct snd_pcm_runtime *runtime)
    163166{
    164167    struct snd_emu10k1_pcm *epcm = runtime->private_data;
     
    171174
    172175/* open_playback callback */
    173 static int snd_p16v_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
     176static int snd_p16v_pcm_open_playback_channel(struct snd_pcm_substream *substream, int channel_id)
    174177{
    175178    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    176179    struct snd_emu10k1_voice *channel = &(emu->p16v_voices[channel_id]);
    177180    struct snd_emu10k1_pcm *epcm;
    178     snd_pcm_runtime_t *runtime = substream->runtime;
     181    struct snd_pcm_runtime *runtime = substream->runtime;
    179182    int err;
    180183
    181     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
     184    epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    182185    //snd_printk("epcm kcalloc: %p\n", epcm);
    183186
     
    208211
    209212/* open_capture callback */
    210 static int snd_p16v_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id)
     213static int snd_p16v_pcm_open_capture_channel(struct snd_pcm_substream *substream, int channel_id)
    211214{
    212215    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    213216    struct snd_emu10k1_voice *channel = &(emu->p16v_capture_voice);
    214217    struct snd_emu10k1_pcm *epcm;
    215     snd_pcm_runtime_t *runtime = substream->runtime;
     218    struct snd_pcm_runtime *runtime = substream->runtime;
    216219    int err;
    217220
    218     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
     221    epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    219222    //snd_printk("epcm kcalloc: %p\n", epcm);
    220223
     
    246249
    247250/* close callback */
    248 static int snd_p16v_pcm_close_playback(snd_pcm_substream_t *substream)
    249 {
    250     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    251     //snd_pcm_runtime_t *runtime = substream->runtime;
     251static int snd_p16v_pcm_close_playback(struct snd_pcm_substream *substream)
     252{
     253    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     254    //struct snd_pcm_runtime *runtime = substream->runtime;
    252255    //struct snd_emu10k1_pcm *epcm = runtime->private_data;
    253256    emu->p16v_voices[substream->pcm->device - emu->p16v_device_offset].use=0;
     
    257260
    258261/* close callback */
    259 static int snd_p16v_pcm_close_capture(snd_pcm_substream_t *substream)
    260 {
    261     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    262     //snd_pcm_runtime_t *runtime = substream->runtime;
     262static int snd_p16v_pcm_close_capture(struct snd_pcm_substream *substream)
     263{
     264    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     265    //struct snd_pcm_runtime *runtime = substream->runtime;
    263266    //struct snd_emu10k1_pcm *epcm = runtime->private_data;
    264267    emu->p16v_capture_voice.use=0;
     
    267270}
    268271
    269 static int snd_p16v_pcm_open_playback_front(snd_pcm_substream_t *substream)
     272static int snd_p16v_pcm_open_playback_front(struct snd_pcm_substream *substream)
    270273{
    271274    return snd_p16v_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
    272275}
    273276
    274 static int snd_p16v_pcm_open_capture(snd_pcm_substream_t *substream)
     277static int snd_p16v_pcm_open_capture(struct snd_pcm_substream *substream)
    275278{
    276279    // Only using channel 0 for now, but the card has 2 channels.
     
    279282
    280283/* hw_params callback */
    281 static int snd_p16v_pcm_hw_params_playback(snd_pcm_substream_t *substream,
    282                                            snd_pcm_hw_params_t * hw_params)
     284static int snd_p16v_pcm_hw_params_playback(struct snd_pcm_substream *substream,
     285                                      struct snd_pcm_hw_params *hw_params)
    283286{
    284287    int result;
     
    289292
    290293/* hw_params callback */
    291 static int snd_p16v_pcm_hw_params_capture(snd_pcm_substream_t *substream,
    292                                           snd_pcm_hw_params_t * hw_params)
     294static int snd_p16v_pcm_hw_params_capture(struct snd_pcm_substream *substream,
     295                                      struct snd_pcm_hw_params *hw_params)
    293296{
    294297    int result;
     
    300303
    301304/* hw_free callback */
    302 static int snd_p16v_pcm_hw_free_playback(snd_pcm_substream_t *substream)
     305static int snd_p16v_pcm_hw_free_playback(struct snd_pcm_substream *substream)
    303306{
    304307    int result;
     
    308311
    309312/* hw_free callback */
    310 static int snd_p16v_pcm_hw_free_capture(snd_pcm_substream_t *substream)
     313static int snd_p16v_pcm_hw_free_capture(struct snd_pcm_substream *substream)
    311314{
    312315    int result;
     
    317320
    318321/* prepare playback callback */
    319 static int snd_p16v_pcm_prepare_playback(snd_pcm_substream_t *substream)
    320 {
    321     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    322     snd_pcm_runtime_t *runtime = substream->runtime;
     322static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream)
     323{
     324    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     325    struct snd_pcm_runtime *runtime = substream->runtime;
    323326    int channel = substream->pcm->device - emu->p16v_device_offset;
    324327    u32 *table_base = (u32 *)(emu->p16v_buffer.area+(8*16*channel));
     
    366369
    367370/* prepare capture callback */
    368 static int snd_p16v_pcm_prepare_capture(snd_pcm_substream_t *substream)
    369 {
    370     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    371     snd_pcm_runtime_t *runtime = substream->runtime;
     371static int snd_p16v_pcm_prepare_capture(struct snd_pcm_substream *substream)
     372{
     373    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     374    struct snd_pcm_runtime *runtime = substream->runtime;
    372375    int channel = substream->pcm->device - emu->p16v_device_offset;
    373376    u32 tmp;
     
    423426
    424427/* trigger_playback callback */
    425 static int snd_p16v_pcm_trigger_playback(snd_pcm_substream_t *substream,
     428static int snd_p16v_pcm_trigger_playback(struct snd_pcm_substream *substream,
    426429                                         int cmd)
    427430{
    428431    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    429     snd_pcm_runtime_t *runtime;
     432    struct snd_pcm_runtime *runtime;
    430433    struct snd_emu10k1_pcm *epcm;
    431434    int channel;
    432435    int result = 0;
    433436    struct list_head *pos;
    434     snd_pcm_substream_t *s;
     437    struct snd_pcm_substream *s;
    435438    u32 basic = 0;
    436439    u32 inte = 0;
     
    476479
    477480/* trigger_capture callback */
    478 static int snd_p16v_pcm_trigger_capture(snd_pcm_substream_t *substream,
     481static int snd_p16v_pcm_trigger_capture(struct snd_pcm_substream *substream,
    479482                                        int cmd)
    480483{
    481484    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    482     snd_pcm_runtime_t *runtime = substream->runtime;
     485    struct snd_pcm_runtime *runtime = substream->runtime;
    483486    struct snd_emu10k1_pcm *epcm = runtime->private_data;
    484487    int channel = 0;
     
    507510/* pointer_playback callback */
    508511static snd_pcm_uframes_t
    509 snd_p16v_pcm_pointer_playback(snd_pcm_substream_t *substream)
    510 {
    511     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    512     snd_pcm_runtime_t *runtime = substream->runtime;
     512snd_p16v_pcm_pointer_playback(struct snd_pcm_substream *substream)
     513{
     514    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     515    struct snd_pcm_runtime *runtime = substream->runtime;
    513516    struct snd_emu10k1_pcm *epcm = runtime->private_data;
    514517    snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
     
    532535/* pointer_capture callback */
    533536static snd_pcm_uframes_t
    534 snd_p16v_pcm_pointer_capture(snd_pcm_substream_t *substream)
    535 {
    536     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    537     snd_pcm_runtime_t *runtime = substream->runtime;
     537snd_p16v_pcm_pointer_capture(struct snd_pcm_substream *substream)
     538{
     539    struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     540    struct snd_pcm_runtime *runtime = substream->runtime;
    538541    struct snd_emu10k1_pcm *epcm = runtime->private_data;
    539542    snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
     
    556559
    557560/* operators */
    558 static snd_pcm_ops_t snd_p16v_playback_front_ops = {
    559     /*.open =        */snd_p16v_pcm_open_playback_front,
    560     /*.close =       */snd_p16v_pcm_close_playback,
    561     /*.ioctl =       */snd_pcm_lib_ioctl,
    562     /*.hw_params =   */snd_p16v_pcm_hw_params_playback,
    563     /*.hw_free =     */snd_p16v_pcm_hw_free_playback,
    564     /*.prepare =     */snd_p16v_pcm_prepare_playback,
    565     /*.trigger =     */snd_p16v_pcm_trigger_playback,
    566     /*.pointer =     */snd_p16v_pcm_pointer_playback,
    567     0,0,0,0
     561static struct snd_pcm_ops snd_p16v_playback_front_ops = {
     562        .open =        snd_p16v_pcm_open_playback_front,
     563        .close =       snd_p16v_pcm_close_playback,
     564        .ioctl =       snd_pcm_lib_ioctl,
     565        .hw_params =   snd_p16v_pcm_hw_params_playback,
     566        .hw_free =     snd_p16v_pcm_hw_free_playback,
     567        .prepare =     snd_p16v_pcm_prepare_playback,
     568        .trigger =     snd_p16v_pcm_trigger_playback,
     569        .pointer =     snd_p16v_pcm_pointer_playback,
    568570};
    569571
    570 static snd_pcm_ops_t snd_p16v_capture_ops = {
    571     /*.open =        */snd_p16v_pcm_open_capture,
    572     /*.close =       */snd_p16v_pcm_close_capture,
    573     /*.ioctl =       */snd_pcm_lib_ioctl,
    574     /*.hw_params =   */snd_p16v_pcm_hw_params_capture,
    575     /*.hw_free =     */snd_p16v_pcm_hw_free_capture,
    576     /*.prepare =     */snd_p16v_pcm_prepare_capture,
    577     /*.trigger =     */snd_p16v_pcm_trigger_capture,
    578     /*.pointer =     */snd_p16v_pcm_pointer_capture,
    579     0,0,0,0
     572static struct snd_pcm_ops snd_p16v_capture_ops = {
     573        .open =        snd_p16v_pcm_open_capture,
     574        .close =       snd_p16v_pcm_close_capture,
     575        .ioctl =       snd_pcm_lib_ioctl,
     576        .hw_params =   snd_p16v_pcm_hw_params_capture,
     577        .hw_free =     snd_p16v_pcm_hw_free_capture,
     578        .prepare =     snd_p16v_pcm_prepare_capture,
     579        .trigger =     snd_p16v_pcm_trigger_capture,
     580        .pointer =     snd_p16v_pcm_pointer_capture,
    580581};
    581582
     
    590591}
    591592
    592 static void snd_p16v_pcm_free(snd_pcm_t *pcm)
    593 {
    594     struct snd_emu10k1 *emu = pcm->private_data;
    595     //snd_printk("snd_p16v_pcm_free pcm: called\n");
    596     snd_pcm_lib_preallocate_free_for_all(pcm);
    597     emu->pcm = NULL;
    598 }
    599 
    600 int snd_p16v_pcm(struct snd_emu10k1 *emu, int device, snd_pcm_t **rpcm)
    601 {
    602     snd_pcm_t *pcm;
    603     snd_pcm_substream_t *substream;
     593int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
     594{
     595    struct snd_pcm *pcm;
     596    struct snd_pcm_substream *substream;
    604597    int err;
    605598    int capture=1;
     
    613606
    614607    pcm->private_data = emu;
    615     pcm->private_free = snd_p16v_pcm_free;
    616608    // Single playback 8 channel device.
    617609    // Single capture 2 channel device.
     
    622614    pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
    623615    strcpy(pcm->name, "p16v");
    624     emu->pcm = pcm;
     616    emu->pcm_p16v = pcm;
    625617
    626618    for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
     
    652644}
    653645
    654 static int snd_p16v_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    655 {
    656     uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    657     uinfo->count = 2;
    658     uinfo->value.integer.min = 0;
    659     uinfo->value.integer.max = 255;
    660     return 0;
    661 }
    662 
    663 static int snd_p16v_volume_get(snd_kcontrol_t * kcontrol,
    664                                snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
    665 {
    666     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    667     u32 value;
    668 
    669     value = snd_emu10k1_ptr20_read(emu, reg, high_low);
    670     if (high_low == 1) {
    671         ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
    672         ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
    673     } else {
    674         ucontrol->value.integer.value[0] = 0xff - ((value >> 8) & 0xff); /* Left */
    675         ucontrol->value.integer.value[1] = 0xff - ((value >> 0) & 0xff); /* Right */
    676     }
    677     return 0;
    678 }
    679 
    680 static int snd_p16v_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
    681                                            snd_ctl_elem_value_t * ucontrol)
    682 {
    683     int high_low = 0;
    684     int reg = PLAYBACK_VOLUME_MIXER7;
    685     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    686 }
    687 
    688 static int snd_p16v_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
    689                                                 snd_ctl_elem_value_t * ucontrol)
    690 {
    691     int high_low = 1;
    692     int reg = PLAYBACK_VOLUME_MIXER7;
    693     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    694 }
    695 static int snd_p16v_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
    696                                              snd_ctl_elem_value_t * ucontrol)
    697 {
    698     int high_low = 0;
    699     int reg = PLAYBACK_VOLUME_MIXER8;
    700     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    701 }
    702 static int snd_p16v_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
    703                                           snd_ctl_elem_value_t * ucontrol)
    704 {
    705     int high_low = 1;
    706     int reg = PLAYBACK_VOLUME_MIXER8;
    707     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    708 }
    709 
    710 static int snd_p16v_volume_get_analog_front(snd_kcontrol_t * kcontrol,
    711                                             snd_ctl_elem_value_t * ucontrol)
    712 {
    713     int high_low = 0;
    714     int reg = PLAYBACK_VOLUME_MIXER9;
    715     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    716 }
    717 
    718 static int snd_p16v_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
    719                                                  snd_ctl_elem_value_t * ucontrol)
    720 {
    721     int high_low = 1;
    722     int reg = PLAYBACK_VOLUME_MIXER9;
    723     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    724 }
    725 static int snd_p16v_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
    726                                            snd_ctl_elem_value_t * ucontrol)
    727 {
    728     int high_low = 1;
    729     int reg = PLAYBACK_VOLUME_MIXER10;
    730     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    731 }
    732 
    733 static int snd_p16v_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
    734                                               snd_ctl_elem_value_t * ucontrol)
    735 {
    736     int high_low = 0;
    737     int reg = PLAYBACK_VOLUME_MIXER10;
    738     return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
    739 }
    740 
    741 static int snd_p16v_volume_put(snd_kcontrol_t * kcontrol,
    742                                snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
    743 {
    744     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    745     u32 value;
    746     value = snd_emu10k1_ptr20_read(emu, reg, 0);
    747     //value = value & 0xffff;
    748     if (high_low == 1) {
    749         value &= 0xffff;
    750         value = value | ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
    751     } else {
    752         value &= 0xffff0000;
    753         value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
    754     }
    755     snd_emu10k1_ptr20_write(emu, reg, 0, value);
    756     return 1;
    757 }
    758 
    759 static int snd_p16v_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
    760                                            snd_ctl_elem_value_t * ucontrol)
    761 {
    762     int high_low = 0;
    763     int reg = PLAYBACK_VOLUME_MIXER7;
    764     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    765 }
    766 
    767 static int snd_p16v_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
    768                                                 snd_ctl_elem_value_t * ucontrol)
    769 {
    770     int high_low = 1;
    771     int reg = PLAYBACK_VOLUME_MIXER7;
    772     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    773 }
    774 
    775 static int snd_p16v_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
    776                                              snd_ctl_elem_value_t * ucontrol)
    777 {
    778     int high_low = 0;
    779     int reg = PLAYBACK_VOLUME_MIXER8;
    780     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    781 }
    782 
    783 static int snd_p16v_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
    784                                           snd_ctl_elem_value_t * ucontrol)
    785 {
    786     int high_low = 1;
    787     int reg = PLAYBACK_VOLUME_MIXER8;
    788     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    789 }
    790 
    791 static int snd_p16v_volume_put_analog_front(snd_kcontrol_t * kcontrol,
    792                                             snd_ctl_elem_value_t * ucontrol)
    793 {
    794     int high_low = 0;
    795     int reg = PLAYBACK_VOLUME_MIXER9;
    796     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    797 }
    798 
    799 static int snd_p16v_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
    800                                                  snd_ctl_elem_value_t * ucontrol)
    801 {
    802     int high_low = 1;
    803     int reg = PLAYBACK_VOLUME_MIXER9;
    804     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    805 }
    806 
    807 static int snd_p16v_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
    808                                            snd_ctl_elem_value_t * ucontrol)
    809 {
    810     int high_low = 1;
    811     int reg = PLAYBACK_VOLUME_MIXER10;
    812     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    813 }
    814 
    815 static int snd_p16v_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
    816                                               snd_ctl_elem_value_t * ucontrol)
    817 {
    818     int high_low = 0;
    819     int reg = PLAYBACK_VOLUME_MIXER10;
    820     return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
    821 }
    822 
    823 static snd_kcontrol_new_t snd_p16v_volume_control_analog_front =
    824 {
    825     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    826     "HD Analog Front Playback Volume",0,0,0,
    827     snd_p16v_volume_info,
    828     snd_p16v_volume_get_analog_front,
    829     snd_p16v_volume_put_analog_front,0
    830 };
    831 
    832 static snd_kcontrol_new_t snd_p16v_volume_control_analog_center_lfe =
    833 {
    834     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    835     "HD Analog Center/LFE Playback Volume",0,0,0,
    836     snd_p16v_volume_info,
    837     snd_p16v_volume_get_analog_center_lfe,
    838     snd_p16v_volume_put_analog_center_lfe
    839 };
    840 
    841 static snd_kcontrol_new_t snd_p16v_volume_control_analog_unknown =
    842 {
    843     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    844     "HD Analog Unknown Playback Volume",0,0,0,
    845     snd_p16v_volume_info,
    846     snd_p16v_volume_get_analog_unknown,
    847     snd_p16v_volume_put_analog_unknown,0
    848 };
    849 
    850 static snd_kcontrol_new_t snd_p16v_volume_control_analog_rear =
    851 {
    852     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    853     "HD Analog Rear Playback Volume",0,0,0,
    854     snd_p16v_volume_info,
    855     snd_p16v_volume_get_analog_rear,
    856     snd_p16v_volume_put_analog_rear,0
    857 };
    858 
    859 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_front =
    860 {
    861     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    862     "HD SPDIF Front Playback Volume",0,0,0,
    863     snd_p16v_volume_info,
    864     snd_p16v_volume_get_spdif_front,
    865     snd_p16v_volume_put_spdif_front,0
    866 };
    867 
    868 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_center_lfe =
    869 {
    870     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    871     "HD SPDIF Center/LFE Playback Volume",0,0,0,
    872     snd_p16v_volume_info,
    873     snd_p16v_volume_get_spdif_center_lfe,
    874     snd_p16v_volume_put_spdif_center_lfe,0
    875 };
    876 
    877 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_unknown =
    878 {
    879     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    880     "HD SPDIF Unknown Playback Volume",0,0,0,
    881     snd_p16v_volume_info,
    882     snd_p16v_volume_get_spdif_unknown,
    883     snd_p16v_volume_put_spdif_unknown,0
    884 };
    885 
    886 static snd_kcontrol_new_t snd_p16v_volume_control_spdif_rear =
    887 {
    888     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    889     "HD SPDIF Rear Playback Volume",0,0,0,
    890     snd_p16v_volume_info,
    891     snd_p16v_volume_get_spdif_rear,
    892     snd_p16v_volume_put_spdif_rear,0
    893 };
    894 
    895 static int snd_p16v_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    896 {
    897     static char *texts[8] = { "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S", "CDIF", "FX", "AC97" };
     646static int snd_p16v_volume_info(struct snd_kcontrol *kcontrol,
     647                                struct snd_ctl_elem_info *uinfo)
     648{
     649        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     650        uinfo->count = 2;
     651        uinfo->value.integer.min = 0;
     652        uinfo->value.integer.max = 255;
     653        return 0;
     654}
     655
     656static int snd_p16v_volume_get(struct snd_kcontrol *kcontrol,
     657                               struct snd_ctl_elem_value *ucontrol)
     658{
     659        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     660        int high_low = (kcontrol->private_value >> 8) & 0xff;
     661        int reg = kcontrol->private_value & 0xff;
     662        u32 value;
     663
     664        value = snd_emu10k1_ptr20_read(emu, reg, high_low);
     665        if (high_low) {
     666                ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
     667                ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
     668        } else {
     669                ucontrol->value.integer.value[0] = 0xff - ((value >> 8) & 0xff); /* Left */
     670                ucontrol->value.integer.value[1] = 0xff - ((value >> 0) & 0xff); /* Right */
     671        }
     672        return 0;
     673}
     674
     675static int snd_p16v_volume_put(struct snd_kcontrol *kcontrol,
     676                               struct snd_ctl_elem_value *ucontrol)
     677{
     678        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     679        int high_low = (kcontrol->private_value >> 8) & 0xff;
     680        int reg = kcontrol->private_value & 0xff;
     681        u32 value, oval;
     682
     683        oval = value = snd_emu10k1_ptr20_read(emu, reg, 0);
     684        if (high_low == 1) {
     685                value &= 0xffff;
     686                value |= ((0xff - ucontrol->value.integer.value[0]) << 24) |
     687                        ((0xff - ucontrol->value.integer.value[1]) << 16);
     688        } else {
     689                value &= 0xffff0000;
     690                value |= ((0xff - ucontrol->value.integer.value[0]) << 8) |
     691                        ((0xff - ucontrol->value.integer.value[1]) );
     692        }
     693        if (value != oval) {
     694                snd_emu10k1_ptr20_write(emu, reg, 0, value);
     695                return 1;
     696        }
     697        return 0;
     698}
     699
     700
     701static int snd_p16v_capture_source_info(struct snd_kcontrol *kcontrol,
     702                                        struct snd_ctl_elem_info *uinfo)
     703{
     704    static char *texts[8] = {
     705        "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S",
     706        "CDIF", "FX", "AC97"
     707    };
    898708
    899709    uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     
    906716}
    907717
    908 static int snd_p16v_capture_source_get(snd_kcontrol_t * kcontrol,
    909                                        snd_ctl_elem_value_t * ucontrol)
     718static int snd_p16v_capture_source_get(struct snd_kcontrol *kcontrol,
     719                                        struct snd_ctl_elem_value *ucontrol)
    910720{
    911721    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    915725}
    916726
    917 static int snd_p16v_capture_source_put(snd_kcontrol_t * kcontrol,
    918                                        snd_ctl_elem_value_t * ucontrol)
     727static int snd_p16v_capture_source_put(struct snd_kcontrol *kcontrol,
     728                                        struct snd_ctl_elem_value *ucontrol)
    919729{
    920730    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    935745}
    936746
    937 static snd_kcontrol_new_t snd_p16v_capture_source __devinitdata =
    938 {
    939     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    940     "HD source Capture",0,0,0,
    941     snd_p16v_capture_source_info,
    942     snd_p16v_capture_source_get,
    943     snd_p16v_capture_source_put,0
    944 };
    945 
    946 static int snd_p16v_capture_channel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     747static int snd_p16v_capture_channel_info(struct snd_kcontrol *kcontrol,
     748                                         struct snd_ctl_elem_info *uinfo)
    947749{
    948750    static char *texts[4] = { "0", "1", "2", "3",  };
     
    957759}
    958760
    959 static int snd_p16v_capture_channel_get(snd_kcontrol_t * kcontrol,
    960                                         snd_ctl_elem_value_t * ucontrol)
     761static int snd_p16v_capture_channel_get(struct snd_kcontrol *kcontrol,
     762                                        struct snd_ctl_elem_value *ucontrol)
    961763{
    962764    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    966768}
    967769
    968 static int snd_p16v_capture_channel_put(snd_kcontrol_t * kcontrol,
    969                                         snd_ctl_elem_value_t * ucontrol)
     770static int snd_p16v_capture_channel_put(struct snd_kcontrol *kcontrol,
     771                                        struct snd_ctl_elem_value *ucontrol)
    970772{
    971773    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    984786}
    985787
    986 static snd_kcontrol_new_t snd_p16v_capture_channel __devinitdata =
    987 {
    988     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    989     "HD channel Capture",0,0,0,
    990     snd_p16v_capture_channel_info,
    991     snd_p16v_capture_channel_get,
    992     snd_p16v_capture_channel_put,0
     788static DECLARE_TLV_DB_SCALE(snd_p16v_db_scale1, -5175, 25, 1);
     789
     790#define P16V_VOL(xname,xreg,xhl) { \
     791        .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
     792        .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |             \
     793                  SNDRV_CTL_ELEM_ACCESS_TLV_READ,               \
     794        .info = snd_p16v_volume_info, \
     795        .get = snd_p16v_volume_get, \
     796        .put = snd_p16v_volume_put, \
     797        .tlv = { .p = snd_p16v_db_scale1 },     \
     798        .private_value = ((xreg) | ((xhl) << 8)) \
     799}
     800
     801static struct snd_kcontrol_new p16v_mixer_controls[] __devinitdata = {
     802        P16V_VOL("HD Analog Front Playback Volume", PLAYBACK_VOLUME_MIXER9, 0),
     803        P16V_VOL("HD Analog Rear Playback Volume", PLAYBACK_VOLUME_MIXER10, 1),
     804        P16V_VOL("HD Analog Center/LFE Playback Volume", PLAYBACK_VOLUME_MIXER9, 1),
     805        P16V_VOL("HD Analog Side Playback Volume", PLAYBACK_VOLUME_MIXER10, 0),
     806        P16V_VOL("HD SPDIF Front Playback Volume", PLAYBACK_VOLUME_MIXER7, 0),
     807        P16V_VOL("HD SPDIF Rear Playback Volume", PLAYBACK_VOLUME_MIXER8, 1),
     808        P16V_VOL("HD SPDIF Center/LFE Playback Volume", PLAYBACK_VOLUME_MIXER7, 1),
     809        P16V_VOL("HD SPDIF Side Playback Volume", PLAYBACK_VOLUME_MIXER8, 0),
     810        {
     811                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     812                .name =         "HD source Capture",
     813                .info =         snd_p16v_capture_source_info,
     814                .get =          snd_p16v_capture_source_get,
     815                .put =          snd_p16v_capture_source_put
     816        },
     817        {
     818                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     819                .name =         "HD channel Capture",
     820                .info =         snd_p16v_capture_channel_info,
     821                .get =          snd_p16v_capture_channel_get,
     822                .put =          snd_p16v_capture_channel_put
     823        },
    993824};
    994825
    995 int snd_p16v_mixer(struct snd_emu10k1 *emu)
    996 {
    997     int err;
    998     snd_kcontrol_t *kctl;
    999     snd_card_t *card = emu->card;
    1000     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_front, emu)) == NULL)
    1001         return -ENOMEM;
    1002     if ((err = snd_ctl_add(card, kctl)))
    1003         return err;
    1004     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_rear, emu)) == NULL)
    1005         return -ENOMEM;
    1006     if ((err = snd_ctl_add(card, kctl)))
    1007         return err;
    1008     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_center_lfe, emu)) == NULL)
    1009         return -ENOMEM;
    1010     if ((err = snd_ctl_add(card, kctl)))
    1011         return err;
    1012     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_unknown, emu)) == NULL)
    1013         return -ENOMEM;
    1014     if ((err = snd_ctl_add(card, kctl)))
    1015         return err;
    1016     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_front, emu)) == NULL)
    1017         return -ENOMEM;
    1018     if ((err = snd_ctl_add(card, kctl)))
    1019         return err;
    1020     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_rear, emu)) == NULL)
    1021         return -ENOMEM;
    1022     if ((err = snd_ctl_add(card, kctl)))
    1023         return err;
    1024     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_center_lfe, emu)) == NULL)
    1025         return -ENOMEM;
    1026     if ((err = snd_ctl_add(card, kctl)))
    1027         return err;
    1028     if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_unknown, emu)) == NULL)
    1029         return -ENOMEM;
    1030     if ((err = snd_ctl_add(card, kctl)))
    1031         return err;
    1032     if ((kctl = snd_ctl_new1(&snd_p16v_capture_source, emu)) == NULL)
    1033         return -ENOMEM;
    1034     if ((err = snd_ctl_add(card, kctl)))
    1035         return err;
    1036     if ((kctl = snd_ctl_new1(&snd_p16v_capture_channel, emu)) == NULL)
    1037         return -ENOMEM;
    1038     if ((err = snd_ctl_add(card, kctl)))
    1039         return err;
    1040     return 0;
    1041 }
    1042 
     826int __devinit snd_p16v_mixer(struct snd_emu10k1 *emu)
     827{
     828        int i, err;
     829        struct snd_card *card = emu->card;
     830
     831        for (i = 0; i < ARRAY_SIZE(p16v_mixer_controls); i++) {
     832                if ((err = snd_ctl_add(card, snd_ctl_new1(&p16v_mixer_controls[i],
     833                                                          emu))) < 0)
     834                        return err;
     835        }
     836        return 0;
     837}
     838
     839#ifdef CONFIG_PM
     840
     841#define NUM_CHS 1       /* up to 4, but only first channel is used */
     842
     843int __devinit snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
     844{
     845        emu->p16v_saved = vmalloc(NUM_CHS * 4 * 0x80);
     846        if (! emu->p16v_saved)
     847                return -ENOMEM;
     848        return 0;
     849}
     850
     851void snd_p16v_free_pm_buffer(struct snd_emu10k1 *emu)
     852{
     853        vfree(emu->p16v_saved);
     854}
     855
     856void snd_p16v_suspend(struct snd_emu10k1 *emu)
     857{
     858        int i, ch;
     859        unsigned int *val;
     860
     861        val = emu->p16v_saved;
     862        for (ch = 0; ch < NUM_CHS; ch++)
     863                for (i = 0; i < 0x80; i++, val++)
     864                        *val = snd_emu10k1_ptr20_read(emu, i, ch);
     865}
     866
     867void snd_p16v_resume(struct snd_emu10k1 *emu)
     868{
     869        int i, ch;
     870        unsigned int *val;
     871
     872        val = emu->p16v_saved;
     873        for (ch = 0; ch < NUM_CHS; ch++)
     874                for (i = 0; i < 0x80; i++, val++)
     875                        snd_emu10k1_ptr20_write(emu, i, ch, *val);
     876}
     877#endif
     878
Note: See TracChangeset for help on using the changeset viewer.