Changeset 84


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

SB code update
HDA code update
Some other updates

Location:
GPL/trunk
Files:
34 edited

Legend:

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

    r77 r84  
    2727/* max number of user-defined controls */
    2828#define MAX_USER_CONTROLS       32
    29 
    30 static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id *dst_id,
    31                                                     struct snd_kcontrol *src_kctl,
    32                                                     unsigned int offset)
    33 {
    34         *dst_id = src_kctl->id;
    35         dst_id->index += offset;
    36         dst_id->numid += offset;
    37         return dst_id;
    38 }
    3929
    4030extern int control_id_changed;
     
    223213 * Returns the pointer of the newly generated instance, or NULL on failure.
    224214 */
    225 struct snd_kcontrol *snd_ctl_new1(struct snd_kcontrol_new const * ncontrol, void *private_data)
     215struct snd_kcontrol *snd_ctl_new1(struct snd_kcontrol_new const * ncontrol,
     216                                  void *private_data)
    226217{
    227218    struct snd_kcontrol kctl;
     
    244235    kctl.get = ncontrol->get;
    245236    kctl.put = ncontrol->put;
    246     kctl.tlv = ncontrol->tlv;
     237    kctl.tlv.p =
     238        ncontrol->tlv.p;
    247239    kctl.private_value = ncontrol->private_value;
    248240    kctl.private_data = private_data;
     
    10371029#endif
    10381030
    1039 static int snd_ctl_tlv_read(struct snd_card *card,
    1040                             struct snd_ctl_tlv __user *_tlv)
    1041 {
    1042     struct snd_ctl_tlv tlv;
    1043     struct snd_kcontrol *kctl;
    1044     unsigned int len;
    1045     int err = 0;
    1046 
    1047     if (copy_from_user(&tlv, _tlv, sizeof(tlv)))
    1048         return -EFAULT;
    1049     if (tlv.length < sizeof(unsigned int) * 3)
    1050         return -EINVAL;
    1051     down_read(&card->controls_rwsem);
    1052     kctl = snd_ctl_find_numid(card, tlv.numid);
    1053     if (kctl == NULL) {
    1054         err = -ENOENT;
    1055         goto __kctl_end;
    1056     }
    1057     if (kctl->tlv == NULL) {
    1058         err = -ENXIO;
    1059         goto __kctl_end;
    1060     }
    1061     len = kctl->tlv[1] + 2 * sizeof(unsigned int);
    1062     if (tlv.length < len) {
    1063         err = -ENOMEM;
    1064         goto __kctl_end;
    1065     }
    1066     if (copy_to_user(_tlv->tlv, kctl->tlv, len))
    1067         err = -EFAULT;
    1068 __kctl_end:
    1069     up_read(&card->controls_rwsem);
    1070     return err;
    1071 }
     1031static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
     1032                             struct snd_ctl_tlv __user *_tlv,
     1033                             int op_flag)
     1034{
     1035        struct snd_card *card = file->card;
     1036        struct snd_ctl_tlv tlv;
     1037        struct snd_kcontrol *kctl;
     1038        struct snd_kcontrol_volatile *vd;
     1039        unsigned int len;
     1040        int err = 0;
     1041
     1042        if (copy_from_user(&tlv, _tlv, sizeof(tlv)))
     1043                return -EFAULT;
     1044        if (tlv.length < sizeof(unsigned int) * 3)
     1045                return -EINVAL;
     1046        down_read(&card->controls_rwsem);
     1047        kctl = snd_ctl_find_numid(card, tlv.numid);
     1048        if (kctl == NULL) {
     1049                err = -ENOENT;
     1050                goto __kctl_end;
     1051        }
     1052        if (kctl->tlv.p == NULL) {
     1053                err = -ENXIO;
     1054                goto __kctl_end;
     1055        }
     1056        vd = &kctl->vd[tlv.numid - kctl->id.numid];
     1057        if ((op_flag == 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) == 0) ||
     1058            (op_flag > 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) == 0) ||
     1059            (op_flag < 0 && (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND) == 0)) {
     1060                err = -ENXIO;
     1061                goto __kctl_end;
     1062        }
     1063        if (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
     1064                if (file && vd->owner != NULL && vd->owner != file) {
     1065                        err = -EPERM;
     1066                        goto __kctl_end;
     1067                }
     1068                err = kctl->tlv.c(kctl, op_flag, tlv.length, _tlv->tlv);
     1069                if (err > 0) {
     1070                        up_read(&card->controls_rwsem);
     1071                        snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_TLV, &kctl->id);
     1072                        return 0;
     1073                }
     1074        } else {
     1075                if (op_flag) {
     1076                        err = -ENXIO;
     1077                        goto __kctl_end;
     1078                }
     1079                len = kctl->tlv.p[1] + 2 * sizeof(unsigned int);
     1080                if (tlv.length < len) {
     1081                        err = -ENOMEM;
     1082                        goto __kctl_end;
     1083                }
     1084                if (copy_to_user(_tlv->tlv, kctl->tlv.p, len))
     1085                        err = -EFAULT;
     1086        }
     1087      __kctl_end:
     1088        up_read(&card->controls_rwsem);
     1089        return err;
     1090}
     1091
    10721092
    10731093static int snd_ctl_ioctl(struct inode *inode, struct file *file,
     
    10931113    case SNDRV_CTL_IOCTL_ELEM_INFO:
    10941114        return snd_ctl_elem_info(ctl, (struct snd_ctl_elem_info *) arg);
    1095 #if 1
    10961115    case SNDRV_CTL_IOCTL_ELEM_READ:
    10971116        return snd_ctl_elem_read_user(ctl->card, argp);
    10981117    case SNDRV_CTL_IOCTL_ELEM_WRITE:
    10991118        return snd_ctl_elem_write_user(ctl, argp);
    1100 #else
    1101     case SNDRV_CTL_IOCTL_ELEM_READ:
    1102         return snd_ctl_elem_read(ctl->card, (struct snd_ctl_elem_value *) arg);
    1103     case SNDRV_CTL_IOCTL_ELEM_WRITE:
    1104         return snd_ctl_elem_write(ctl, (struct snd_ctl_elem_value *) arg);
    1105 #endif
    11061119    case SNDRV_CTL_IOCTL_ELEM_LOCK:
    11071120        return snd_ctl_elem_lock(ctl, (struct snd_ctl_elem_id *) arg);
     
    11171130        return snd_ctl_subscribe_events(ctl, (int *) arg);
    11181131    case SNDRV_CTL_IOCTL_TLV_READ:
    1119         return snd_ctl_tlv_read(card, argp);
     1132        return snd_ctl_tlv_ioctl(ctl, argp, 0);
     1133    case SNDRV_CTL_IOCTL_TLV_WRITE:
     1134        return snd_ctl_tlv_ioctl(ctl, argp, 1);
     1135    case SNDRV_CTL_IOCTL_TLV_COMMAND:
     1136        return snd_ctl_tlv_ioctl(ctl, argp, -1);
    11201137    case SNDRV_CTL_IOCTL_POWER:
    11211138        if (get_user(err, (int *)arg))
  • GPL/trunk/alsa-kernel/core/misc.c

    r34 r84  
    2121
    2222#include <sound/driver.h>
    23 
     23#include <sound/firmware.h>
    2424int snd_task_name(struct task_struct *task, char *name, size_t size)
    2525{
     
    669669}
    670670
     671int mod_firmware_load(const char *fn, char **fp)
     672{
     673    return 0;
     674}
     675
     676static int snd_try_load_firmware(const char *path, const char *name,
     677                                 struct firmware *firmware)
     678{
     679        char filename[30 + FIRMWARE_NAME_MAX];
     680
     681        sprintf(filename, "%s/%s", path, name);
     682        firmware->size = mod_firmware_load(filename, (char **)&firmware->data);
     683        if (firmware->size)
     684                printk(KERN_INFO "Loaded '%s'.", filename);
     685        return firmware->size;
     686}
     687
     688int request_firmware(const struct firmware **fw, const char *name)
     689{
     690        struct firmware *firmware;
     691
     692        *fw = NULL;
     693        firmware = kmalloc(sizeof *firmware, GFP_KERNEL);
     694        if (!firmware)
     695                return -ENOMEM;
     696        if (!snd_try_load_firmware("/lib/firmware", name, firmware) &&
     697            !snd_try_load_firmware("/lib/hotplug/firmware", name, firmware) &&
     698            !snd_try_load_firmware("/usr/lib/hotplug/firmware", name, firmware)) {
     699                kfree(firmware);
     700                return -EIO;
     701        }
     702        *fw = firmware;
     703        return 0;
     704}
     705
     706void release_firmware(const struct firmware *fw)
     707{
     708        if (fw) {
     709                vfree(fw->data);
     710                kfree(fw);
     711        }
     712}
     713
  • GPL/trunk/alsa-kernel/include/sound/asound.h

    r77 r84  
    754754#define SNDRV_CTL_ELEM_ACCESS_VOLATILE          (1<<2)  /* control value may be changed without a notification */
    755755#define SNDRV_CTL_ELEM_ACCESS_TIMESTAMP         (1<<2)  /* when was control changed */
     756#define SNDRV_CTL_ELEM_ACCESS_TLV_READ          (1<<4)  /* TLV read is possible */
     757#define SNDRV_CTL_ELEM_ACCESS_TLV_WRITE         (1<<5)  /* TLV write is possible */
     758#define SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE     (SNDRV_CTL_ELEM_ACCESS_TLV_READ|SNDRV_CTL_ELEM_ACCESS_TLV_WRITE)
     759#define SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND       (1<<6)  /* TLV command is possible */
    756760#define SNDRV_CTL_ELEM_ACCESS_INACTIVE          (1<<8)  /* control does actually nothing, but may be updated */
    757761#define SNDRV_CTL_ELEM_ACCESS_LOCK              (1<<9)  /* write lock */
    758762#define SNDRV_CTL_ELEM_ACCESS_OWNER             (1<<10) /* write lock owner */
     763#define SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK      (1<<28) /* kernel use a TLV callback */
    759764#define SNDRV_CTL_ELEM_ACCESS_USER              (1<<29) /* user space element */
    760765#define SNDRV_CTL_ELEM_ACCESS_DINDIRECT         (1<<30) /* indirect access for matrix dimensions in the info structure */
     
    864869        SNDRV_CTL_IOCTL_ELEM_REMOVE = _IOWR('U', 0x19, struct snd_ctl_elem_id),
    865870        SNDRV_CTL_IOCTL_TLV_READ = _IOWR('U', 0x1a, struct snd_ctl_tlv),
     871        SNDRV_CTL_IOCTL_TLV_WRITE = _IOWR('U', 0x1b, struct snd_ctl_tlv),
     872        SNDRV_CTL_IOCTL_TLV_COMMAND = _IOWR('U', 0x1c, struct snd_ctl_tlv),
    866873        SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE = _IOWR('U', 0x20, int),
    867874        SNDRV_CTL_IOCTL_HWDEP_INFO = _IOR('U', 0x21, struct snd_hwdep_info),
     
    893900#define SNDRV_CTL_EVENT_MASK_INFO       (1<<1)  /* element info was changed */
    894901#define SNDRV_CTL_EVENT_MASK_ADD        (1<<2)  /* element was added */
     902#define SNDRV_CTL_EVENT_MASK_TLV        (1<<3)  /* element TLV tree was changed */
    895903#define SNDRV_CTL_EVENT_MASK_REMOVE     (~0U)   /* element was removed */
    896904
  • GPL/trunk/alsa-kernel/include/sound/control.h

    r77 r84  
    2828typedef int (snd_kcontrol_get_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
    2929typedef int (snd_kcontrol_put_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
     30typedef int (snd_kcontrol_tlv_rw_t)(struct snd_kcontrol *kcontrol,
     31                                    int op_flag, /* 0=read,1=write,-1=command */
     32                                    unsigned int size,
     33                                    unsigned int __user *tlv);
    3034
    3135struct snd_kcontrol_new {
     
    4044    snd_kcontrol_get_t *get;
    4145    snd_kcontrol_put_t *put;
    42     unsigned int *tlv;
     46    union {
     47        snd_kcontrol_tlv_rw_t *c;
     48        unsigned int *p;
     49    } tlv;
    4350    unsigned long private_value;
    4451};
     
    5764        snd_kcontrol_get_t *get;
    5865        snd_kcontrol_put_t *put;
    59         unsigned int *tlv;
     66        union {
     67                snd_kcontrol_tlv_rw_t *c;
     68                unsigned int *p;
     69        } tlv;
    6070        unsigned long private_value;
    6171#ifdef TARGET_OS2
     
    140150}
    141151
     152static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id *dst_id,
     153                                                    struct snd_kcontrol *src_kctl,
     154                                                    unsigned int offset)
     155{
     156        *dst_id = src_kctl->id;
     157        dst_id->index += offset;
     158        dst_id->numid += offset;
     159        return dst_id;
     160}
     161
    142162#endif                          /* __CONTROL_H */
  • GPL/trunk/alsa-kernel/include/sound/emu10k1.h

    r34 r84  
    188188                                                /* NOTE: The rest of the bits in this register  */
    189189                                                /* _are_ relevant under Linux.                  */
    190 #define HCFG_CODECFORMAT_MASK   0x00070000      /* CODEC format                                 */
     190#define HCFG_PUSH_BUTTON_ENABLE 0x00100000      /* Enables Volume Inc/Dec and Mute functions    */
     191#define HCFG_BAUD_RATE          0x00080000      /* 0 = 48kHz, 1 = 44.1kHz                       */
     192#define HCFG_EXPANDED_MEM       0x00040000      /* 1 = any 16M of 4G addr, 0 = 32M of 2G addr   */
     193#define HCFG_CODECFORMAT_MASK   0x00030000      /* CODEC format                                 */
     194
     195/* Specific to Alice2, CA0102 */
     196#define HCFG_CODECFORMAT_AC97_1 0x00000000      /* AC97 CODEC format -- Ver 1.03                */
     197#define HCFG_CODECFORMAT_AC97_2 0x00010000      /* AC97 CODEC format -- Ver 2.1                 */
     198#define HCFG_AUTOMUTE_ASYNC     0x00008000      /* When set, the async sample rate convertors   */
     199                                                /* will automatically mute their output when    */
     200                                                /* they are not rate-locked to the external     */
     201                                                /* async audio source                           */
     202#define HCFG_AUTOMUTE_SPDIF     0x00004000      /* When set, the async sample rate convertors   */
     203                                                /* will automatically mute their output when    */
     204                                                /* the SPDIF V-bit indicates invalid audio      */
     205#define HCFG_EMU32_SLAVE        0x00002000      /* 0 = Master, 1 = Slave. Slave for EMU1010     */
     206#define HCFG_SLOW_RAMP          0x00001000      /* Increases Send Smoothing time constant       */
     207/* 0x00000800 not used on Alice2 */
     208#define HCFG_PHASE_TRACK_MASK   0x00000700      /* When set, forces corresponding input to      */
     209                                                /* phase track the previous input.              */
     210                                                /* I2S0 can phase track the last S/PDIF input   */
     211#define HCFG_I2S_ASRC_ENABLE    0x00000070      /* When set, enables asynchronous sample rate   */
     212                                                /* conversion for the corresponding             */
     213                                                /* I2S format input                             */
     214/* Rest of HCFG 0x0000000f same as below. LOCKSOUNDCACHE etc.  */
     215
     216
     217
     218/* Older chips */
    191219#define HCFG_CODECFORMAT_AC97   0x00000000      /* AC97 CODEC format -- Primary Output          */
    192220#define HCFG_CODECFORMAT_I2S    0x00010000      /* I2S CODEC format -- Secondary (Rear) Output  */
     
    245273#define A_IOCFG_DISABLE_ANALOG  0x0040          /* = 'enable' for Audigy2 (chiprev=4)           */
    246274#define A_IOCFG_ENABLE_DIGITAL  0x0004
     275#define A_IOCFG_ENABLE_DIGITAL_AUDIGY4  0x0080
    247276#define A_IOCFG_UNKNOWN_20      0x0020
    248277#define A_IOCFG_DISABLE_AC97_FRONT      0x0080  /* turn off ac97 front -> front (10k2.1)        */
     
    885914#define A_HIWORD_OPA_MASK       0x000007ff
    886915
     916/************************************************************************************************/
     917/* EMU1010m HANA FPGA registers                                                                 */
     918/************************************************************************************************/
     919#define EMU_HANA_DESTHI         0x00    /* 0000xxx  3 bits Link Destination */
     920#define EMU_HANA_DESTLO         0x01    /* 00xxxxx  5 bits */
     921#define EMU_HANA_SRCHI          0x02    /* 0000xxx  3 bits Link Source */
     922#define EMU_HANA_SRCLO          0x03    /* 00xxxxx  5 bits */
     923#define EMU_HANA_DOCK_PWR       0x04    /* 000000x  1 bits Audio Dock power */
     924#define EMU_HANA_DOCK_PWR_ON            0x01 /* Audio Dock power on */
     925#define EMU_HANA_WCLOCK         0x05    /* 0000xxx  3 bits Word Clock source select  */
     926                                        /* Must be written after power on to reset DLL */
     927                                        /* One is unable to detect the Audio dock without this */
     928#define EMU_HANA_WCLOCK_SRC_MASK        0x07
     929#define EMU_HANA_WCLOCK_INT_48K         0x00
     930#define EMU_HANA_WCLOCK_INT_44_1K       0x01
     931#define EMU_HANA_WCLOCK_HANA_SPDIF_IN   0x02
     932#define EMU_HANA_WCLOCK_HANA_ADAT_IN    0x03
     933#define EMU_HANA_WCLOCK_SYNC_BNCN       0x04
     934#define EMU_HANA_WCLOCK_2ND_HANA        0x05
     935#define EMU_HANA_WCLOCK_SRC_RESERVED    0x06
     936#define EMU_HANA_WCLOCK_OFF             0x07 /* For testing, forces fallback to DEFCLOCK */
     937#define EMU_HANA_WCLOCK_MULT_MASK       0x18
     938#define EMU_HANA_WCLOCK_1X              0x00
     939#define EMU_HANA_WCLOCK_2X              0x08
     940#define EMU_HANA_WCLOCK_4X              0x10
     941#define EMU_HANA_WCLOCK_MULT_RESERVED   0x18
     942
     943#define EMU_HANA_DEFCLOCK       0x06    /* 000000x  1 bits Default Word Clock  */
     944#define EMU_HANA_DEFCLOCK_48K           0x00
     945#define EMU_HANA_DEFCLOCK_44_1K         0x01
     946
     947#define EMU_HANA_UNMUTE         0x07    /* 000000x  1 bits Mute all audio outputs  */
     948#define EMU_MUTE                        0x00
     949#define EMU_UNMUTE                      0x01
     950
     951#define EMU_HANA_FPGA_CONFIG    0x08    /* 00000xx  2 bits Config control of FPGAs  */
     952#define EMU_HANA_FPGA_CONFIG_AUDIODOCK  0x01 /* Set in order to program FPGA on Audio Dock */
     953#define EMU_HANA_FPGA_CONFIG_HANA       0x02 /* Set in order to program FPGA on Hana */
     954
     955#define EMU_HANA_IRQ_ENABLE     0x09    /* 000xxxx  4 bits IRQ Enable  */
     956#define EMU_HANA_IRQ_WCLK_CHANGED       0x01
     957#define EMU_HANA_IRQ_ADAT               0x02
     958#define EMU_HANA_IRQ_DOCK               0x04
     959#define EMU_HANA_IRQ_DOCK_LOST          0x08
     960
     961#define EMU_HANA_SPDIF_MODE     0x0a    /* 00xxxxx  5 bits SPDIF MODE  */
     962#define EMU_HANA_SPDIF_MODE_TX_COMSUMER 0x00
     963#define EMU_HANA_SPDIF_MODE_TX_PRO      0x01
     964#define EMU_HANA_SPDIF_MODE_TX_NOCOPY   0x02
     965#define EMU_HANA_SPDIF_MODE_RX_COMSUMER 0x00
     966#define EMU_HANA_SPDIF_MODE_RX_PRO      0x04
     967#define EMU_HANA_SPDIF_MODE_RX_NOCOPY   0x08
     968#define EMU_HANA_SPDIF_MODE_RX_INVALID  0x10
     969
     970#define EMU_HANA_OPTICAL_TYPE   0x0b    /* 00000xx  2 bits ADAT or SPDIF in/out  */
     971#define EMU_HANA_OPTICAL_IN_SPDIF       0x00
     972#define EMU_HANA_OPTICAL_IN_ADAT        0x01
     973#define EMU_HANA_OPTICAL_OUT_SPDIF      0x00
     974#define EMU_HANA_OPTICAL_OUT_ADAT       0x02
     975
     976#define EMU_HANA_MIDI_IN                0x0c    /* 000000x  1 bit  Control MIDI  */
     977#define EMU_HANA_MIDI_IN_FROM_HAMOA     0x00 /* HAMOA MIDI in to Alice 2 MIDI B */
     978#define EMU_HANA_MIDI_IN_FROM_DOCK      0x01 /* Audio Dock MIDI in to Alice 2 MIDI B */
     979
     980#define EMU_HANA_DOCK_LEDS_1    0x0d    /* 000xxxx  4 bit  Audio Dock LEDs  */
     981#define EMU_HANA_DOCK_LEDS_1_MIDI1      0x01    /* MIDI 1 LED on */
     982#define EMU_HANA_DOCK_LEDS_1_MIDI2      0x02    /* MIDI 2 LED on */
     983#define EMU_HANA_DOCK_LEDS_1_SMPTE_IN   0x04    /* SMPTE IN LED on */
     984#define EMU_HANA_DOCK_LEDS_1_SMPTE_OUT  0x08    /* SMPTE OUT LED on */
     985
     986#define EMU_HANA_DOCK_LEDS_2    0x0e    /* 0xxxxxx  6 bit  Audio Dock LEDs  */
     987#define EMU_HANA_DOCK_LEDS_2_44K        0x01    /* 44.1 kHz LED on */
     988#define EMU_HANA_DOCK_LEDS_2_48K        0x02    /* 48 kHz LED on */
     989#define EMU_HANA_DOCK_LEDS_2_96K        0x04    /* 96 kHz LED on */
     990#define EMU_HANA_DOCK_LEDS_2_192K       0x08    /* 192 kHz LED on */
     991#define EMU_HANA_DOCK_LEDS_2_LOCK       0x10    /* LOCK LED on */
     992#define EMU_HANA_DOCK_LEDS_2_EXT        0x20    /* EXT LED on */
     993
     994#define EMU_HANA_DOCK_LEDS_3    0x0f    /* 0xxxxxx  6 bit  Audio Dock LEDs  */
     995#define EMU_HANA_DOCK_LEDS_3_CLIP_A     0x01    /* Mic A Clip LED on */
     996#define EMU_HANA_DOCK_LEDS_3_CLIP_B     0x02    /* Mic B Clip LED on */
     997#define EMU_HANA_DOCK_LEDS_3_SIGNAL_A   0x04    /* Signal A Clip LED on */
     998#define EMU_HANA_DOCK_LEDS_3_SIGNAL_B   0x08    /* Signal B Clip LED on */
     999#define EMU_HANA_DOCK_LEDS_3_MANUAL_CLIP        0x10    /* Manual Clip detection */
     1000#define EMU_HANA_DOCK_LEDS_3_MANUAL_SIGNAL      0x20    /* Manual Signal detection */
     1001
     1002#define EMU_HANA_ADC_PADS       0x10    /* 0000xxx  3 bit  Audio Dock ADC 14dB pads */
     1003#define EMU_HANA_DOCK_ADC_PAD1  0x01    /* 14dB Attenuation on Audio Dock ADC 1 */
     1004#define EMU_HANA_DOCK_ADC_PAD2  0x02    /* 14dB Attenuation on Audio Dock ADC 2 */
     1005#define EMU_HANA_DOCK_ADC_PAD3  0x04    /* 14dB Attenuation on Audio Dock ADC 3 */
     1006#define EMU_HANA_0202_ADC_PAD1  0x08    /* 14dB Attenuation on 0202 ADC 1 */
     1007
     1008#define EMU_HANA_DOCK_MISC      0x11    /* 0xxxxxx  6 bit  Audio Dock misc bits */
     1009#define EMU_HANA_DOCK_DAC1_MUTE 0x01    /* DAC 1 Mute */
     1010#define EMU_HANA_DOCK_DAC2_MUTE 0x02    /* DAC 2 Mute */
     1011#define EMU_HANA_DOCK_DAC3_MUTE 0x04    /* DAC 3 Mute */
     1012#define EMU_HANA_DOCK_DAC4_MUTE 0x08    /* DAC 4 Mute */
     1013#define EMU_HANA_DOCK_PHONES_192_DAC1   0x00    /* DAC 1 Headphones source at 192kHz */
     1014#define EMU_HANA_DOCK_PHONES_192_DAC2   0x10    /* DAC 2 Headphones source at 192kHz */
     1015#define EMU_HANA_DOCK_PHONES_192_DAC3   0x20    /* DAC 3 Headphones source at 192kHz */
     1016#define EMU_HANA_DOCK_PHONES_192_DAC4   0x30    /* DAC 4 Headphones source at 192kHz */
     1017
     1018#define EMU_HANA_MIDI_OUT       0x12    /* 00xxxxx  5 bit  Source for each MIDI out port */
     1019#define EMU_HANA_MIDI_OUT_0202  0x01 /* 0202 MIDI from Alice 2. 0 = A, 1 = B */
     1020#define EMU_HANA_MIDI_OUT_DOCK1 0x02 /* Audio Dock MIDI1 front, from Alice 2. 0 = A, 1 = B */
     1021#define EMU_HANA_MIDI_OUT_DOCK2 0x04 /* Audio Dock MIDI2 rear, from Alice 2. 0 = A, 1 = B */
     1022#define EMU_HANA_MIDI_OUT_SYNC2 0x08 /* Sync card. Not the actual MIDI out jack. 0 = A, 1 = B */
     1023#define EMU_HANA_MIDI_OUT_LOOP  0x10 /* 0 = bits (3:0) normal. 1 = MIDI loopback enabled. */
     1024
     1025#define EMU_HANA_DAC_PADS       0x13    /* 00xxxxx  5 bit  DAC 14dB attenuation pads */
     1026#define EMU_HANA_DOCK_DAC_PAD1  0x01    /* 14dB Attenuation on AudioDock DAC 1. Left and Right */
     1027#define EMU_HANA_DOCK_DAC_PAD2  0x02    /* 14dB Attenuation on AudioDock DAC 2. Left and Right */
     1028#define EMU_HANA_DOCK_DAC_PAD3  0x04    /* 14dB Attenuation on AudioDock DAC 3. Left and Right */
     1029#define EMU_HANA_DOCK_DAC_PAD4  0x08    /* 14dB Attenuation on AudioDock DAC 4. Left and Right */
     1030#define EMU_HANA_0202_DAC_PAD1  0x10    /* 14dB Attenuation on 0202 DAC 1. Left and Right */
     1031
     1032/* 0x14 - 0x1f Unused R/W registers */
     1033#define EMU_HANA_IRQ_STATUS     0x20    /* 000xxxx  4 bits IRQ Status  */
     1034#if 0  /* Already defined for reg 0x09 IRQ_ENABLE */
     1035#define EMU_HANA_IRQ_WCLK_CHANGED       0x01
     1036#define EMU_HANA_IRQ_ADAT               0x02
     1037#define EMU_HANA_IRQ_DOCK               0x04
     1038#define EMU_HANA_IRQ_DOCK_LOST          0x08
     1039#endif
     1040
     1041#define EMU_HANA_OPTION_CARDS   0x21    /* 000xxxx  4 bits Presence of option cards */
     1042#define EMU_HANA_OPTION_HAMOA   0x01    /* HAMOA card present */
     1043#define EMU_HANA_OPTION_SYNC    0x02    /* Sync card present */
     1044#define EMU_HANA_OPTION_DOCK_ONLINE     0x04    /* Audio Dock online and FPGA configured */
     1045#define EMU_HANA_OPTION_DOCK_OFFLINE    0x08    /* Audio Dock online and FPGA not configured */
     1046
     1047#define EMU_HANA_ID             0x22    /* 1010101  7 bits ID byte & 0x7f = 0x55 */
     1048
     1049#define EMU_HANA_MAJOR_REV      0x23    /* 0000xxx  3 bit  Hana FPGA Major rev */
     1050#define EMU_HANA_MINOR_REV      0x24    /* 0000xxx  3 bit  Hana FPGA Minor rev */
     1051
     1052#define EMU_DOCK_MAJOR_REV      0x25    /* 0000xxx  3 bit  Audio Dock FPGA Major rev */
     1053#define EMU_DOCK_MINOR_REV      0x26    /* 0000xxx  3 bit  Audio Dock FPGA Minor rev */
     1054
     1055#define EMU_DOCK_BOARD_ID       0x27    /* 00000xx  2 bits Audio Dock ID pins */
     1056#define EMU_DOCK_BOARD_ID0      0x00    /* ID bit 0 */
     1057#define EMU_DOCK_BOARD_ID1      0x03    /* ID bit 1 */
     1058
     1059#define EMU_HANA_WC_SPDIF_HI    0x28    /* 0xxxxxx  6 bit  SPDIF IN Word clock, upper 6 bits */
     1060#define EMU_HANA_WC_SPDIF_LO    0x29    /* 0xxxxxx  6 bit  SPDIF IN Word clock, lower 6 bits */
     1061
     1062#define EMU_HANA_WC_ADAT_HI     0x2a    /* 0xxxxxx  6 bit  ADAT IN Word clock, upper 6 bits */
     1063#define EMU_HANA_WC_ADAT_LO     0x2b    /* 0xxxxxx  6 bit  ADAT IN Word clock, lower 6 bits */
     1064
     1065#define EMU_HANA_WC_BNC_LO      0x2c    /* 0xxxxxx  6 bit  BNC IN Word clock, lower 6 bits */
     1066#define EMU_HANA_WC_BNC_HI      0x2d    /* 0xxxxxx  6 bit  BNC IN Word clock, upper 6 bits */
     1067
     1068#define EMU_HANA2_WC_SPDIF_HI   0x2e    /* 0xxxxxx  6 bit  HANA2 SPDIF IN Word clock, upper 6 bits */
     1069#define EMU_HANA2_WC_SPDIF_LO   0x2f    /* 0xxxxxx  6 bit  HANA2 SPDIF IN Word clock, lower 6 bits */
     1070/* 0x30 - 0x3f Unused Read only registers */
     1071
     1072/************************************************************************************************/
     1073/* EMU1010m HANA Destinations                                                                   */
     1074/************************************************************************************************/
     1075#define EMU_DST_ALICE2_EMU32_0  0x000f  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1076#define EMU_DST_ALICE2_EMU32_1  0x0000  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1077#define EMU_DST_ALICE2_EMU32_2  0x0001  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1078#define EMU_DST_ALICE2_EMU32_3  0x0002  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1079#define EMU_DST_ALICE2_EMU32_4  0x0003  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1080#define EMU_DST_ALICE2_EMU32_5  0x0004  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1081#define EMU_DST_ALICE2_EMU32_6  0x0005  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1082#define EMU_DST_ALICE2_EMU32_7  0x0006  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1083#define EMU_DST_ALICE2_EMU32_8  0x0007  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1084#define EMU_DST_ALICE2_EMU32_9  0x0008  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1085#define EMU_DST_ALICE2_EMU32_A  0x0009  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1086#define EMU_DST_ALICE2_EMU32_B  0x000a  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1087#define EMU_DST_ALICE2_EMU32_C  0x000b  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1088#define EMU_DST_ALICE2_EMU32_D  0x000c  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1089#define EMU_DST_ALICE2_EMU32_E  0x000d  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1090#define EMU_DST_ALICE2_EMU32_F  0x000e  /* 16 EMU32 channels to Alice2 +0 to +0xf */
     1091#define EMU_DST_DOCK_DAC1_LEFT1 0x0100  /* Audio Dock DAC1 Left, 1st or 48kHz only */
     1092#define EMU_DST_DOCK_DAC1_LEFT2 0x0101  /* Audio Dock DAC1 Left, 2nd or 96kHz */
     1093#define EMU_DST_DOCK_DAC1_LEFT3 0x0102  /* Audio Dock DAC1 Left, 3rd or 192kHz */
     1094#define EMU_DST_DOCK_DAC1_LEFT4 0x0103  /* Audio Dock DAC1 Left, 4th or 192kHz */
     1095#define EMU_DST_DOCK_DAC1_RIGHT1        0x0104  /* Audio Dock DAC1 Right, 1st or 48kHz only */
     1096#define EMU_DST_DOCK_DAC1_RIGHT2        0x0105  /* Audio Dock DAC1 Right, 2nd or 96kHz */
     1097#define EMU_DST_DOCK_DAC1_RIGHT3        0x0106  /* Audio Dock DAC1 Right, 3rd or 192kHz */
     1098#define EMU_DST_DOCK_DAC1_RIGHT4        0x0107  /* Audio Dock DAC1 Right, 4th or 192kHz */
     1099#define EMU_DST_DOCK_DAC2_LEFT1 0x0108  /* Audio Dock DAC2 Left, 1st or 48kHz only */
     1100#define EMU_DST_DOCK_DAC2_LEFT2 0x0109  /* Audio Dock DAC2 Left, 2nd or 96kHz */
     1101#define EMU_DST_DOCK_DAC2_LEFT3 0x010a  /* Audio Dock DAC2 Left, 3rd or 192kHz */
     1102#define EMU_DST_DOCK_DAC2_LEFT4 0x010b  /* Audio Dock DAC2 Left, 4th or 192kHz */
     1103#define EMU_DST_DOCK_DAC2_RIGHT1        0x010c  /* Audio Dock DAC2 Right, 1st or 48kHz only */
     1104#define EMU_DST_DOCK_DAC2_RIGHT2        0x010d  /* Audio Dock DAC2 Right, 2nd or 96kHz */
     1105#define EMU_DST_DOCK_DAC2_RIGHT3        0x010e  /* Audio Dock DAC2 Right, 3rd or 192kHz */
     1106#define EMU_DST_DOCK_DAC2_RIGHT4        0x010f  /* Audio Dock DAC2 Right, 4th or 192kHz */
     1107#define EMU_DST_DOCK_DAC3_LEFT1 0x0110  /* Audio Dock DAC1 Left, 1st or 48kHz only */
     1108#define EMU_DST_DOCK_DAC3_LEFT2 0x0111  /* Audio Dock DAC1 Left, 2nd or 96kHz */
     1109#define EMU_DST_DOCK_DAC3_LEFT3 0x0112  /* Audio Dock DAC1 Left, 3rd or 192kHz */
     1110#define EMU_DST_DOCK_DAC3_LEFT4 0x0113  /* Audio Dock DAC1 Left, 4th or 192kHz */
     1111#define EMU_DST_DOCK_PHONES_LEFT1       0x0112  /* Audio Dock PHONES Left, 1st or 48kHz only */
     1112#define EMU_DST_DOCK_PHONES_LEFT2       0x0113  /* Audio Dock PHONES Left, 2nd or 96kHz */
     1113#define EMU_DST_DOCK_DAC3_RIGHT1        0x0114  /* Audio Dock DAC1 Right, 1st or 48kHz only */
     1114#define EMU_DST_DOCK_DAC3_RIGHT2        0x0115  /* Audio Dock DAC1 Right, 2nd or 96kHz */
     1115#define EMU_DST_DOCK_DAC3_RIGHT3        0x0116  /* Audio Dock DAC1 Right, 3rd or 192kHz */
     1116#define EMU_DST_DOCK_DAC3_RIGHT4        0x0117  /* Audio Dock DAC1 Right, 4th or 192kHz */
     1117#define EMU_DST_DOCK_PHONES_RIGHT1      0x0116  /* Audio Dock PHONES Right, 1st or 48kHz only */
     1118#define EMU_DST_DOCK_PHONES_RIGHT2      0x0117  /* Audio Dock PHONES Right, 2nd or 96kHz */
     1119#define EMU_DST_DOCK_DAC4_LEFT1 0x0118  /* Audio Dock DAC2 Left, 1st or 48kHz only */
     1120#define EMU_DST_DOCK_DAC4_LEFT2 0x0119  /* Audio Dock DAC2 Left, 2nd or 96kHz */
     1121#define EMU_DST_DOCK_DAC4_LEFT3 0x011a  /* Audio Dock DAC2 Left, 3rd or 192kHz */
     1122#define EMU_DST_DOCK_DAC4_LEFT4 0x011b  /* Audio Dock DAC2 Left, 4th or 192kHz */
     1123#define EMU_DST_DOCK_SPDIF_LEFT1        0x011a  /* Audio Dock SPDIF Left, 1st or 48kHz only */
     1124#define EMU_DST_DOCK_SPDIF_LEFT2        0x011b  /* Audio Dock SPDIF Left, 2nd or 96kHz */
     1125#define EMU_DST_DOCK_DAC4_RIGHT1        0x011c  /* Audio Dock DAC2 Right, 1st or 48kHz only */
     1126#define EMU_DST_DOCK_DAC4_RIGHT2        0x011d  /* Audio Dock DAC2 Right, 2nd or 96kHz */
     1127#define EMU_DST_DOCK_DAC4_RIGHT3        0x011e  /* Audio Dock DAC2 Right, 3rd or 192kHz */
     1128#define EMU_DST_DOCK_DAC4_RIGHT4        0x011f  /* Audio Dock DAC2 Right, 4th or 192kHz */
     1129#define EMU_DST_DOCK_SPDIF_RIGHT1       0x011e  /* Audio Dock SPDIF Right, 1st or 48kHz only */
     1130#define EMU_DST_DOCK_SPDIF_RIGHT2       0x011f  /* Audio Dock SPDIF Right, 2nd or 96kHz */
     1131#define EMU_DST_HANA_SPDIF_LEFT1        0x0200  /* Hana SPDIF Left, 1st or 48kHz only */
     1132#define EMU_DST_HANA_SPDIF_LEFT2        0x0202  /* Hana SPDIF Left, 2nd or 96kHz */
     1133#define EMU_DST_HANA_SPDIF_RIGHT1       0x0201  /* Hana SPDIF Right, 1st or 48kHz only */
     1134#define EMU_DST_HANA_SPDIF_RIGHT2       0x0203  /* Hana SPDIF Right, 2nd or 96kHz */
     1135#define EMU_DST_HAMOA_DAC_LEFT1 0x0300  /* Hamoa DAC Left, 1st or 48kHz only */
     1136#define EMU_DST_HAMOA_DAC_LEFT2 0x0302  /* Hamoa DAC Left, 2nd or 96kHz */
     1137#define EMU_DST_HAMOA_DAC_LEFT3 0x0304  /* Hamoa DAC Left, 3rd or 192kHz */
     1138#define EMU_DST_HAMOA_DAC_LEFT4 0x0306  /* Hamoa DAC Left, 4th or 192kHz */
     1139#define EMU_DST_HAMOA_DAC_RIGHT1        0x0301  /* Hamoa DAC Right, 1st or 48kHz only */
     1140#define EMU_DST_HAMOA_DAC_RIGHT2        0x0303  /* Hamoa DAC Right, 2nd or 96kHz */
     1141#define EMU_DST_HAMOA_DAC_RIGHT3        0x0305  /* Hamoa DAC Right, 3rd or 192kHz */
     1142#define EMU_DST_HAMOA_DAC_RIGHT4        0x0307  /* Hamoa DAC Right, 4th or 192kHz */
     1143#define EMU_DST_HANA_ADAT       0x0400  /* Hana ADAT 8 channel out +0 to +7 */
     1144#define EMU_DST_ALICE_I2S0_LEFT         0x0500  /* Alice2 I2S0 Left */
     1145#define EMU_DST_ALICE_I2S0_RIGHT        0x0501  /* Alice2 I2S0 Right */
     1146#define EMU_DST_ALICE_I2S1_LEFT         0x0600  /* Alice2 I2S1 Left */
     1147#define EMU_DST_ALICE_I2S1_RIGHT        0x0601  /* Alice2 I2S1 Right */
     1148#define EMU_DST_ALICE_I2S2_LEFT         0x0700  /* Alice2 I2S2 Left */
     1149#define EMU_DST_ALICE_I2S2_RIGHT        0x0701  /* Alice2 I2S2 Right */
     1150
     1151/************************************************************************************************/
     1152/* EMU1010m HANA Sources                                                                        */
     1153/************************************************************************************************/
     1154#define EMU_SRC_SILENCE         0x0000  /* Silence */
     1155#define EMU_SRC_DOCK_MIC_A1     0x0100  /* Audio Dock Mic A, 1st or 48kHz only */
     1156#define EMU_SRC_DOCK_MIC_A2     0x0101  /* Audio Dock Mic A, 2nd or 96kHz */
     1157#define EMU_SRC_DOCK_MIC_A3     0x0102  /* Audio Dock Mic A, 3rd or 192kHz */
     1158#define EMU_SRC_DOCK_MIC_A4     0x0103  /* Audio Dock Mic A, 4th or 192kHz */
     1159#define EMU_SRC_DOCK_MIC_B1     0x0104  /* Audio Dock Mic B, 1st or 48kHz only */
     1160#define EMU_SRC_DOCK_MIC_B2     0x0105  /* Audio Dock Mic B, 2nd or 96kHz */
     1161#define EMU_SRC_DOCK_MIC_B3     0x0106  /* Audio Dock Mic B, 3rd or 192kHz */
     1162#define EMU_SRC_DOCK_MIC_B4     0x0107  /* Audio Dock Mic B, 4th or 192kHz */
     1163#define EMU_SRC_DOCK_ADC1_LEFT1 0x0108  /* Audio Dock ADC1 Left, 1st or 48kHz only */
     1164#define EMU_SRC_DOCK_ADC1_LEFT2 0x0109  /* Audio Dock ADC1 Left, 2nd or 96kHz */
     1165#define EMU_SRC_DOCK_ADC1_LEFT3 0x010a  /* Audio Dock ADC1 Left, 3rd or 192kHz */
     1166#define EMU_SRC_DOCK_ADC1_LEFT4 0x010b  /* Audio Dock ADC1 Left, 4th or 192kHz */
     1167#define EMU_SRC_DOCK_ADC1_RIGHT1        0x010c  /* Audio Dock ADC1 Right, 1st or 48kHz only */
     1168#define EMU_SRC_DOCK_ADC1_RIGHT2        0x010d  /* Audio Dock ADC1 Right, 2nd or 96kHz */
     1169#define EMU_SRC_DOCK_ADC1_RIGHT3        0x010e  /* Audio Dock ADC1 Right, 3rd or 192kHz */
     1170#define EMU_SRC_DOCK_ADC1_RIGHT4        0x010f  /* Audio Dock ADC1 Right, 4th or 192kHz */
     1171#define EMU_SRC_DOCK_ADC2_LEFT1 0x0110  /* Audio Dock ADC2 Left, 1st or 48kHz only */
     1172#define EMU_SRC_DOCK_ADC2_LEFT2 0x0111  /* Audio Dock ADC2 Left, 2nd or 96kHz */
     1173#define EMU_SRC_DOCK_ADC2_LEFT3 0x0112  /* Audio Dock ADC2 Left, 3rd or 192kHz */
     1174#define EMU_SRC_DOCK_ADC2_LEFT4 0x0113  /* Audio Dock ADC2 Left, 4th or 192kHz */
     1175#define EMU_SRC_DOCK_ADC2_RIGHT1        0x0114  /* Audio Dock ADC2 Right, 1st or 48kHz only */
     1176#define EMU_SRC_DOCK_ADC2_RIGHT2        0x0115  /* Audio Dock ADC2 Right, 2nd or 96kHz */
     1177#define EMU_SRC_DOCK_ADC2_RIGHT3        0x0116  /* Audio Dock ADC2 Right, 3rd or 192kHz */
     1178#define EMU_SRC_DOCK_ADC2_RIGHT4        0x0117  /* Audio Dock ADC2 Right, 4th or 192kHz */
     1179#define EMU_SRC_DOCK_ADC3_LEFT1 0x0118  /* Audio Dock ADC3 Left, 1st or 48kHz only */
     1180#define EMU_SRC_DOCK_ADC3_LEFT2 0x0119  /* Audio Dock ADC3 Left, 2nd or 96kHz */
     1181#define EMU_SRC_DOCK_ADC3_LEFT3 0x011a  /* Audio Dock ADC3 Left, 3rd or 192kHz */
     1182#define EMU_SRC_DOCK_ADC3_LEFT4 0x011b  /* Audio Dock ADC3 Left, 4th or 192kHz */
     1183#define EMU_SRC_DOCK_ADC3_RIGHT1        0x011c  /* Audio Dock ADC3 Right, 1st or 48kHz only */
     1184#define EMU_SRC_DOCK_ADC3_RIGHT2        0x011d  /* Audio Dock ADC3 Right, 2nd or 96kHz */
     1185#define EMU_SRC_DOCK_ADC3_RIGHT3        0x011e  /* Audio Dock ADC3 Right, 3rd or 192kHz */
     1186#define EMU_SRC_DOCK_ADC3_RIGHT4        0x011f  /* Audio Dock ADC3 Right, 4th or 192kHz */
     1187#define EMU_SRC_HAMOA_ADC_LEFT1 0x0200  /* Hamoa ADC Left, 1st or 48kHz only */
     1188#define EMU_SRC_HAMOA_ADC_LEFT2 0x0202  /* Hamoa ADC Left, 2nd or 96kHz */
     1189#define EMU_SRC_HAMOA_ADC_LEFT3 0x0204  /* Hamoa ADC Left, 3rd or 192kHz */
     1190#define EMU_SRC_HAMOA_ADC_LEFT4 0x0206  /* Hamoa ADC Left, 4th or 192kHz */
     1191#define EMU_SRC_HAMOA_ADC_RIGHT1        0x0201  /* Hamoa ADC Right, 1st or 48kHz only */
     1192#define EMU_SRC_HAMOA_ADC_RIGHT2        0x0203  /* Hamoa ADC Right, 2nd or 96kHz */
     1193#define EMU_SRC_HAMOA_ADC_RIGHT3        0x0205  /* Hamoa ADC Right, 3rd or 192kHz */
     1194#define EMU_SRC_HAMOA_ADC_RIGHT4        0x0207  /* Hamoa ADC Right, 4th or 192kHz */
     1195#define EMU_SRC_ALICE_EMU32A            0x0300  /* Alice2 EMU32a 16 outputs. +0 to +0xf */
     1196#define EMU_SRC_ALICE_EMU32B            0x0310  /* Alice2 EMU32b 16 outputs. +0 to +0xf */
     1197#define EMU_SRC_HANA_ADAT       0x0400  /* Hana ADAT 8 channel in +0 to +7 */
     1198#define EMU_SRC_HANA_SPDIF_LEFT1        0x0500  /* Hana SPDIF Left, 1st or 48kHz only */
     1199#define EMU_SRC_HANA_SPDIF_LEFT2        0x0502  /* Hana SPDIF Left, 2nd or 96kHz */
     1200#define EMU_SRC_HANA_SPDIF_RIGHT1       0x0501  /* Hana SPDIF Right, 1st or 48kHz only */
     1201#define EMU_SRC_HANA_SPDIF_RIGHT2       0x0503  /* Hana SPDIF Right, 2nd or 96kHz */
     1202/* 0x600 and 0x700 no used */
    8871203
    8881204/* ------------------- STRUCTURES -------------------- */
     
    10611377        unsigned char spdif_bug;    /* Has Spdif phasing bug */
    10621378        unsigned char ac97_chip;    /* Has an AC97 chip: 1 = mandatory, 2 = optional */
    1063         unsigned char ecard;        /* APS EEPROM */
     1379        unsigned char ecard;        /* APS EEPROM */
     1380        unsigned char emu1010;     /* EMU 1010m card */
     1381        unsigned char spi_dac;      /* SPI interface for DAC */
     1382        unsigned char i2c_adc;      /* I2C interface for ADC */
     1383        unsigned char adc_1361t;    /* Use Philips 1361T ADC */
    10641384        const char *driver;
    10651385        const char *name;
    10661386        const char *id;         /* for backward compatibility - can be NULL if not needed */
    10671387};
     1388
     1389struct snd_emu1010 {
     1390        unsigned int output_source[64];
     1391        unsigned int input_source[64];
     1392        unsigned int adc_pads; /* bit mask */
     1393        unsigned int dac_pads; /* bit mask */
     1394        unsigned int internal_clock; /* 44100 or 48000 */
     1395};
     1396
    10681397
    10691398struct snd_emu10k1 {
     
    11201449        spinlock_t emu_lock;
    11211450        spinlock_t voice_lock;
    1122         struct semaphore ptb_lock;
     1451        //struct semaphore ptb_lock;
    11231452
    11241453        struct snd_emu10k1_voice voices[NUM_G];
     
    11261455        struct snd_emu10k1_voice p16v_capture_voice;
    11271456        int p16v_device_offset;
    1128         u32 p16v_capture_source;
     1457        u32 p16v_capture_source;
     1458        struct snd_emu1010 emu1010;
    11291459        u32 p16v_capture_channel;
    11301460        struct snd_emu10k1_pcm_mixer pcm_mixer[32];
     
    11901520int snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct snd_hwdep ** rhwdep);
    11911521
    1192 irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs);
     1522irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id);
    11931523
    11941524void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int voice);
     
    12031533unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, unsigned int reg, unsigned int chn);
    12041534void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data);
     1535int snd_emu10k1_spi_write(struct snd_emu10k1 * emu, unsigned int data);
     1536int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, int reg, int value);
     1537int snd_emu1010_fpga_read(struct snd_emu10k1 * emu, int reg, int *value);
     1538int snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 * emu, int dst, int src);
    12051539unsigned int snd_emu10k1_efx_read(struct snd_emu10k1 *emu, unsigned int pc);
    12061540void snd_emu10k1_intr_enable(struct snd_emu10k1 *emu, unsigned int intrenb);
     
    15191853        unsigned int min;               /* minimum range */
    15201854        unsigned int max;               /* maximum range */
     1855        union {
     1856                snd_kcontrol_tlv_rw_t *c;
     1857                unsigned int *p;
     1858        } tlv;
    15211859        unsigned int translation;       /* translation type (EMU10K1_GPR_TRANSLATION*) */
    15221860};
  • GPL/trunk/alsa-kernel/pci/ca0106/ca0106_mixer.c

    r77 r84  
    7575#include "ca0106.h"
    7676
    77 static DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale, -5150, 75, 1);
     77static DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1);
     78static DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1);
    7879
    7980static int snd_ca0106_shared_spdif_info(struct snd_kcontrol *kcontrol,
     
    336337{                                                               \
    337338        .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,     \
    338         .info = snd_ca0106_volume_info,                         \
    339         .get =          snd_ca0106_volume_get,                  \
    340     .put =          snd_ca0106_volume_put, \
    341     .tlv =       snd_ca0106_db_scale,                           \
     339        .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |             \
     340                  SNDRV_CTL_ELEM_ACCESS_TLV_READ,               \
     341        .info =  snd_ca0106_volume_info,                        \
     342        .get =   snd_ca0106_volume_get,                         \
     343        .put =   snd_ca0106_volume_put,                         \
     344        .tlv = { .p = snd_ca0106_db_scale1 },                   \
    342345        .private_value = ((chid) << 8) | (reg)                  \
    343346}
    344 
    345347
    346348static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = {
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1.c

    r34 r84  
    22 *  The driver for the EMU10K1 (SB Live!) based soundcards
    33 *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
     4 *
     5 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
     6 *      Added support for Audigy 2 Value.
    47 *
    58 *
     
    1720 *   along with this program; if not, write to the Free Software
    1821 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     22 *
    1923 *
    2024 */
     
    121125        static int dev;
    122126#endif
    123         snd_card_t *card;
     127        struct snd_card *card;
    124128        struct snd_emu10k1 *emu;
    125129#ifdef ENABLE_SYNTH
    126         snd_seq_device_t *wave = NULL;
     130        struct snd_seq_device *wave = NULL;
    127131#endif
    128132        int err;
     
    145149                                      (long)max_buffer_size[dev] * 1024 * 1024,
    146150                                      enable_ir[dev], subsystem[dev],
    147                                       &emu)) < 0) {
    148                 snd_card_free(card);
    149                 return err;
    150         }
    151         if ((err = snd_emu10k1_pcm(emu, 0, NULL)) < 0) {
    152                 snd_card_free(card);
    153                 return err;
    154         }
    155         if ((err = snd_emu10k1_pcm_mic(emu, 1, NULL)) < 0) {
    156                 snd_card_free(card);
    157                 return err;
    158         }
    159         if ((err = snd_emu10k1_pcm_efx(emu, 2, NULL)) < 0) {
    160                 snd_card_free(card);
    161                 return err;
    162         }
     151                                      &emu)) < 0)
     152            goto error;
     153        card->private_data = emu;
     154        if ((err = snd_emu10k1_pcm(emu, 0, NULL)) < 0)
     155                goto error;
     156        if ((err = snd_emu10k1_pcm_mic(emu, 1, NULL)) < 0)
     157                goto error;
     158        if ((err = snd_emu10k1_pcm_efx(emu, 2, NULL)) < 0)
     159                goto error;
    163160        /* This stores the periods table. */
    164161        if (emu->card_capabilities->ca0151_chip) { /* P16V */
    165             if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &emu->p16v_buffer) < 0) {
    166                 snd_p16v_free(emu);
    167                 return -ENOMEM;
    168             }
     162            if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
     163                                           1024, &emu->p16v_buffer)) < 0)
     164                goto error;
    169165        }
    170         if ((err = snd_emu10k1_mixer(emu, 0, 3)) < 0) {
    171             snd_card_free(card);
    172             return err;
     166
     167        if ((err = snd_emu10k1_mixer(emu, 0, 3)) < 0)
     168                goto error;
     169
     170        if ((err = snd_emu10k1_timer(emu, 0)) < 0)
     171                goto error;
     172
     173        if ((err = snd_emu10k1_pcm_multi(emu, 3, NULL)) < 0)
     174                goto error;
     175        if (emu->card_capabilities->ca0151_chip) { /* P16V */
     176            if ((err = snd_p16v_pcm(emu, 4, NULL)) < 0)
     177                goto error;
    173178        }
    174 
    175         if ((err = snd_emu10k1_timer(emu, 0)) < 0) {
    176             snd_card_free(card);
    177             return err;
     179        if (emu->audigy) {
     180            if ((err = snd_emu10k1_audigy_midi(emu)) < 0)
     181                goto error;
     182        } else {
     183            if ((err = snd_emu10k1_midi(emu)) < 0)
     184                goto error;
    178185        }
    179 
    180         if ((err = snd_emu10k1_pcm_multi(emu, 3, NULL)) < 0) {
    181             snd_card_free(card);
    182             return err;
    183         }
    184 
    185         if (emu->card_capabilities->ca0151_chip) { /* P16V */
    186             if ((err = snd_p16v_pcm(emu, 4, NULL)) < 0) {
    187                 snd_card_free(card);
    188                 return err;
    189             }
    190         }
    191 #ifdef TARGET_OS2
    192         if (emu->audigy) {
    193                 if ((err = snd_emu10k1_audigy_midi(emu)) < 0) {
    194                         snd_card_free(card);
    195                         return err;
    196                 }
    197         } else {
    198                 if ((err = snd_emu10k1_midi(emu)) < 0) {
    199                         snd_card_free(card);
    200                         return err;
    201                 }
    202         }
    203 #endif
    204         if ((err = snd_emu10k1_fx8010_new(emu, 0, NULL)) < 0) {
    205                 snd_card_free(card);
    206                 return err;
    207         }
     186        if ((err = snd_emu10k1_fx8010_new(emu, 0, NULL)) < 0)
     187                goto error;
    208188#ifdef ENABLE_SYNTH
    209189        if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
     
    224204        strcpy(card->driver, emu->card_capabilities->driver);
    225205        strcpy(card->shortname, emu->card_capabilities->name);
    226         sprintf(card->longname, "%s (rev.%d) at 0x%lx, irq %i", card->shortname, emu->revision, emu->port, emu->irq);
    227 
    228 //        DebugInt3();
    229 
    230         if ((err = snd_card_register(card)) < 0) {
    231                 snd_card_free(card);
    232                 return err;
    233         }
     206        sprintf(card->longname,
     207                "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i",
     208                card->shortname, emu->revision, emu->serial, emu->port, emu->irq);
     209
     210        if ((err = snd_card_register(card)) < 0)
     211                goto error;
     212
    234213        pci_set_drvdata(pci, card);
    235214        dev++;
    236         return 0;
     215        return 0;
     216
     217 error:
     218        snd_card_free(card);
     219        return err;
    237220}
    238221
     
    243226}
    244227
    245 #ifdef TARGET_OS2
     228#ifdef CONFIG_PM
     229static int snd_emu10k1_suspend(struct pci_dev *pci, pm_message_t state)
     230{
     231    struct snd_card *card = pci_get_drvdata(pci);
     232    struct snd_emu10k1 *emu = card->private_data;
     233    snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
     234
     235    snd_pcm_suspend_all(emu->pcm);
     236    snd_pcm_suspend_all(emu->pcm_mic);
     237    snd_pcm_suspend_all(emu->pcm_efx);
     238    snd_pcm_suspend_all(emu->pcm_multi);
     239    snd_pcm_suspend_all(emu->pcm_p16v);
     240
     241    snd_ac97_suspend(emu->ac97);
     242
     243    snd_emu10k1_efx_suspend(emu);
     244    snd_emu10k1_suspend_regs(emu);
     245    if (emu->card_capabilities->ca0151_chip)
     246        snd_p16v_suspend(emu);
     247
     248    snd_emu10k1_done(emu);
     249
     250    pci_disable_device(pci);
     251    pci_save_state(pci);
     252    pci_set_power_state(pci, PCI_D3hot);
     253    return 0;
     254}
     255
     256static int snd_emu10k1_resume(struct pci_dev *pci)
     257{
     258    struct snd_card *card = pci_get_drvdata(pci);
     259    struct snd_emu10k1 *emu = card->private_data;
     260
     261    pci_set_power_state(pci, PCI_D0);
     262    pci_restore_state(pci);
     263    if (pci_enable_device(pci) < 0) {
     264        printk(KERN_ERR "emu10k1: pci_enable_device failed, "
     265               "disabling device\n");
     266        snd_card_disconnect(card);
     267        return -EIO;
     268    }
     269
     270    pci_set_master(pci);
     271
     272    snd_emu10k1_resume_init(emu);
     273    snd_emu10k1_efx_resume(emu);
     274    snd_ac97_resume(emu->ac97);
     275    snd_emu10k1_resume_regs(emu);
     276
     277    if (emu->card_capabilities->ca0151_chip)
     278        snd_p16v_resume(emu);
     279    snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     280    return 0;
     281}
     282#endif
     283
    246284static struct pci_driver driver = {
    247         0, 0, 0,
    248 /*      name:    */ "EMU10K1/Audigy",
    249 /*      id_table:*/ snd_emu10k1_ids,
    250 /*      probe:   */ snd_card_emu10k1_probe,
    251 /*      remove:  */ snd_card_emu10k1_remove,
    252         0, 0
     285        .name = "EMU10K1_Audigy",
     286        .id_table = snd_emu10k1_ids,
     287        .probe = snd_card_emu10k1_probe,
     288        .remove = snd_card_emu10k1_remove,
     289#ifdef CONFIG_PM
     290        .suspend = snd_emu10k1_suspend,
     291        .resume = snd_emu10k1_resume,
     292#endif
    253293};
    254 #else
    255 static struct pci_driver driver = {
    256         name: "EMU10K1/Audigy",
    257         id_table: snd_emu10k1_ids,
    258         probe: snd_card_emu10k1_probe,
    259         remove: __devexit_p(snd_card_emu10k1_remove),
    260 };
    261 #endif
    262294
    263295static int __init alsa_card_emu10k1_init(void)
    264296{
    265         int err;
    266 
    267         if ((err = pci_module_init(&driver)) < 0) {
    268 #ifdef MODULE
    269 //              printk(KERN_ERR "EMU10K1/Audigy soundcard not found or device busy\n");
    270 #endif
    271                 return err;
    272         }
    273         return 0;
     297    return pci_register_driver(&driver);
    274298}
    275299
    276300static void __exit alsa_card_emu10k1_exit(void)
    277301{
    278         pci_unregister_driver(&driver);
     302    pci_unregister_driver(&driver);
    279303}
    280304
    281305module_init(alsa_card_emu10k1_init)
    282306module_exit(alsa_card_emu10k1_exit)
    283 
    284 #ifndef MODULE
    285 
    286 /* format is: snd-emu10k1=enable,index,id,
    287                           seq_ports,max_synth_voices */
    288 
    289 static int __init alsa_card_emu10k1_setup(char *str)
    290 {
    291         static unsigned __initdata nr_dev = 0;
    292 
    293         if (nr_dev >= SNDRV_CARDS)
    294                 return 0;
    295         (void)(get_option(&str,&enable[nr_dev]) == 2 &&
    296                get_option(&str,&index[nr_dev]) == 2 &&
    297                get_id(&str,&id[nr_dev]) == 2 &&
    298                get_option(&str,&seq_ports[nr_dev]) == 2 &&
    299                get_option(&str,&max_synth_voices[nr_dev]) == 2);
    300         nr_dev++;
    301         return 1;
    302 }
    303 
    304 __setup("snd-emu10k1=", alsa_card_emu10k1_setup);
    305 
    306 #endif /* ifndef MODULE */
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_callback.c

    r34 r84  
    1919 */
    2020
    21 #define __NO_VERSION__
    2221#include "emu10k1_synth_local.h"
    2322#include <sound/asoundef.h>
     
    2928
    3029/* Keeps track of what we are finding */
    31 typedef struct best_voice {
     30struct best_voice {
    3231        unsigned int time;
    3332        int voice;
    34 } best_voice_t;
     33};
    3534
    3635/*
    3736 * prototypes
    3837 */
    39 static void lookup_voices(struct snd_emux *emu, struct snd_emu10k1 *hw, best_voice_t *best, int active_only);
     38static void lookup_voices(struct snd_emux *emu, struct snd_emu10k1 *hw, struct best_voice *best, int active_only);
    4039static struct snd_emux_voice *get_voice(struct snd_emux *emu, struct snd_emux_port *port);
    4140static int start_voice(struct snd_emux_voice *vp);
     
    8988{
    9089        struct snd_emux *emu;
    91         struct snd_emux_voice *vp;
    92         best_voice_t best[V_END];
     90        struct snd_emux_voice *vp;
     91        struct best_voice best[V_END];
    9392        unsigned long flags;
    9493        int i;
     
    211210/* spinlock held! */
    212211static void
    213 lookup_voices(struct snd_emux *emu, struct snd_emu10k1 *hw, best_voice_t *best, int active_only)
    214 {
    215         struct snd_emux_voice *vp;
    216         best_voice_t *bp;
     212lookup_voices(struct snd_emux *emu, struct snd_emu10k1 *hw,
     213              struct best_voice *best, int active_only)
     214{
     215    struct snd_emux_voice *vp;
     216    struct best_voice *bp;
    217217        int  i;
    218218
     
    279279{
    280280        struct snd_emu10k1 *hw;
    281         struct snd_emux_voice *vp;
    282         best_voice_t best[V_END];
     281        struct snd_emux_voice *vp;
     282        struct best_voice best[V_END];
    283283        int i;
    284284
     
    313313        unsigned int temp;
    314314        int ch;
    315         unsigned int addr, mapped_offset;
    316         snd_midi_channel_t *chan;
     315        unsigned int addr, mapped_offset;
     316        struct snd_midi_channel *chan;
    317317        struct snd_emu10k1 *hw;
    318318        struct snd_emu10k1_memblk *emem;
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_main.c

    r34 r84  
    33 *                   Creative Labs, Inc.
    44 *  Routines for control of EMU10K1 chips
     5 *
     6 *  Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
     7 *      Added support for Audigy 2 Value.
     8 *      Added EMU 1010 support.
     9 *      General bug fixes and enhancements.
     10 *
    511 *
    612 *  BUGS:
     
    2632 */
    2733
    28 #define __NO_VERSION__
    2934#include <sound/driver.h>
    3035#include <linux/delay.h>
     
    3439#include <sound/core.h>
    3540#include <sound/emu10k1.h>
     41#include <sound/firmware.h>
    3642#include "p16v.h"
    37 
    38 #if 0
    39 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Creative Labs, Inc.");
    40 MODULE_DESCRIPTION("Routines for control of EMU10K1 chips");
    41 MODULE_LICENSE("GPL");
    42 #endif
     43#include "tina2.h"
    4344
    4445/*************************************************************************
     
    9192}
    9293
    93 static int __devinit snd_emu10k1_init(struct snd_emu10k1 * emu, int enable_ir)
     94static unsigned int spi_dac_init[] = {
     95    0x00ff,
     96    0x02ff,
     97    0x0400,
     98    0x0520,
     99    0x0600,
     100    0x08ff,
     101    0x0aff,
     102    0x0cff,
     103    0x0eff,
     104    0x10ff,
     105    0x1200,
     106    0x1400,
     107    0x1480,
     108    0x1800,
     109    0x1aff,
     110    0x1cff,
     111    0x1e00,
     112    0x0530,
     113    0x0602,
     114    0x0622,
     115    0x1400,
     116};
     117
     118static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
    94119{
    95     int ch, idx, err;
    96120    unsigned int silent_page;
    97 
    98     emu->fx8010.itram_size = (16 * 1024)/2;
    99     emu->fx8010.etram_pages.area = NULL;
    100     emu->fx8010.etram_pages.bytes = 0;
     121    int ch;
     122
    101123    /* disable audio and lock cache */
    102     outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
     124    outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
     125         emu->port + HCFG);
    103126
    104127    /* reset recording buffers */
     
    121144        snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
    122145        /* enable rear left + rear right AC97 slots */
    123         snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT | AC97SLOT_REAR_LEFT);
     146        snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
     147                              AC97SLOT_REAR_LEFT);
    124148    }
    125149
    126150    /* init envelope engine */
    127     for (ch = 0; ch < NUM_G; ch++) {
    128         emu->voices[ch].emu = emu;
    129         emu->voices[ch].number = ch;
     151    for (ch = 0; ch < NUM_G; ch++)
    130152        snd_emu10k1_voice_init(emu, ch);
    131     }
    132 
    133     /*
    134      *  Init to 0x02109204 :
    135      *  Clock accuracy    = 0     (1000ppm)
    136      *  Sample Rate       = 2     (48kHz)
    137      *  Audio Channel     = 1     (Left of 2)
    138      *  Source Number     = 0     (Unspecified)
    139      *  Generation Status = 1     (Original for Cat Code 12)
    140      *  Cat Code          = 12    (Digital Signal Mixer)
    141      *  Mode              = 0     (Mode 0)
    142      *  Emphasis          = 0     (None)
    143      *  CP                = 1     (Copyright unasserted)
    144      *  AN                = 0     (Audio data)
    145      *  P                 = 0     (Consumer)
    146      */
    147     snd_emu10k1_ptr_write(emu, SPCS0, 0,
    148                           emu->spdif_bits[0] =
    149                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    150                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    151                           SPCS_GENERATIONSTATUS | 0x00001200 |
    152                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    153     snd_emu10k1_ptr_write(emu, SPCS1, 0,
    154                           emu->spdif_bits[1] =
    155                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    156                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    157                           SPCS_GENERATIONSTATUS | 0x00001200 |
    158                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    159     snd_emu10k1_ptr_write(emu, SPCS2, 0,
    160                           emu->spdif_bits[2] =
    161                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    162                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    163                           SPCS_GENERATIONSTATUS | 0x00001200 |
    164                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    165 
    166     if (emu->audigy && emu->revision == 4) { /* audigy2 */
     153
     154    snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
     155    snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
     156    snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
     157
     158    if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
    167159        /* Hacks for Alice3 to work independent of haP16V driver */
    168160        u32 tmp;
     
    176168        /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
    177169        snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
    178 
    179170        /* Setup SRCMulti Input Audio Enable */
    180171        /* Use 0xFFFFFFFF to enable P16V sounds. */
     
    186177        snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
    187178    }
    188 
    189179    if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
    190180        /* Hacks for Alice3 to work independent of haP16V driver */
    191181        u32 tmp;
    192182
    193         snd_printk(KERN_ERR "Audigy2 value:Special config.\n");
     183        snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
    194184        //Setup SRCMulti_I2S SamplingRate
    195185        tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
     
    215205        outl(tmp, emu->port + A_IOCFG);
    216206    }
    217 
    218     /*
    219      *  Clear page with silence & setup all pointers to this page
    220      */
    221     memset(emu->silent_page.area, 0, PAGE_SIZE);
    222     silent_page = emu->silent_page.addr << 1;
    223     for (idx = 0; idx < MAXPAGES; idx++)
    224         ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
     207    if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
     208        int size, n;
     209        size = ARRAY_SIZE(spi_dac_init);
     210        for (n=0; n < size; n++)
     211            snd_emu10k1_spi_write(emu, spi_dac_init[n]);
     212
     213        snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
     214        /* Enable GPIOs
     215         * GPIO0: Unknown
     216         * GPIO1: Speakers-enabled.
     217         * GPIO2: Unknown
     218         * GPIO3: Unknown
     219         * GPIO4: IEC958 Output on.
     220         * GPIO5: Unknown
     221         * GPIO6: Unknown
     222         * GPIO7: Unknown
     223         */
     224        outl(0x76, emu->port + A_IOCFG); /* Windows uses 0x3f76 */
     225
     226    }
     227
    225228    snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
    226229    snd_emu10k1_ptr_write(emu, TCB, 0, 0);      /* taken from original driver */
     
    233236    }
    234237
    235     /*
    236      *  Hokay, setup HCFG
    237      *   Mute Disable Audio = 0
    238      *   Lock Tank Memory = 1
    239      *   Lock Sound Memory = 0
    240      *   Auto Mute = 1
    241      */
    242     if (emu->audigy) {
     238    if (emu->card_capabilities->emu1010) {
     239        outl(HCFG_AUTOMUTE_ASYNC |
     240             HCFG_EMU32_SLAVE |
     241             HCFG_AUDIOENABLE, emu->port + HCFG);
     242
     243        /*
     244         *  Hokay, setup HCFG
     245         *   Mute Disable Audio = 0
     246         *   Lock Tank Memory = 1
     247         *   Lock Sound Memory = 0
     248         *   Auto Mute = 1
     249         */
     250    } else if (emu->audigy) {
    243251        if (emu->revision == 4) /* audigy2 */
    244252            outl(HCFG_AUDIOENABLE |
     
    259267
    260268    if (enable_ir) {    /* enable IR for SB Live */
    261         if (emu->audigy) {
     269        if (emu->card_capabilities->emu1010) {
     270            ;  /* Disable all access to A_IOCFG for the emu1010 */
     271        } else if (emu->audigy) {
    262272            unsigned int reg = inl(emu->port + A_IOCFG);
    263273            outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
     
    276286    }
    277287
    278     if (emu->audigy) {  /* enable analog output */
     288    if (emu->card_capabilities->emu1010) {
     289        ;  /* Disable all access to A_IOCFG for the emu1010 */
     290    } else if (emu->audigy) {   /* enable analog output */
    279291        unsigned int reg = inl(emu->port + A_IOCFG);
    280292        outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
    281293    }
    282294
    283     /*
    284      *  Initialize the effect engine
    285      */
    286     if ((err = snd_emu10k1_init_efx(emu)) < 0)
    287         return err;
    288 
     295    return 0;
     296}
     297
     298static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
     299{
    289300    /*
    290301     *  Enable the audio bit
     
    293304
    294305    /* Enable analog/digital outs on audigy */
    295     if (emu->audigy) {
     306    if (emu->card_capabilities->emu1010) {
     307        ;  /* Disable all access to A_IOCFG for the emu1010 */
     308    } else if (emu->audigy) {
    296309        outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
     310
    297311        if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
    298312            /* Unmute Analog now.  Set GPO6 to 1 for Apollo.
     
    328342
    329343    snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
    330 
    331     emu->reserved_page = (struct snd_emu10k1_memblk *)snd_emu10k1_synth_alloc(emu, 4096);
    332     if (emu->reserved_page)
    333         emu->reserved_page->map_locked = 1;
    334 
    335     return 0;
    336344}
    337345
    338 static int snd_emu10k1_done(struct snd_emu10k1 * emu)
     346int snd_emu10k1_done(struct snd_emu10k1 * emu)
    339347{
    340348    int ch;
     
    375383    snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
    376384
    377     /* remove reserved page */
    378     if (emu->reserved_page != NULL) {
    379         snd_emu10k1_synth_free(emu, (snd_util_memblk_t *)emu->reserved_page);
    380         emu->reserved_page = NULL;
    381     }
    382 
    383385    /* disable audio and lock cache */
    384386    outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
    385387    snd_emu10k1_ptr_write(emu, PTB, 0, 0);
    386 
    387     snd_emu10k1_free_efx(emu);
    388388
    389389    return 0;
     
    533533}
    534534
    535 static int __devinit snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
     535static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
    536536{
    537537    unsigned int hc_value;
     
    573573}
    574574
    575 static int __devinit snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
     575static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
    576576{
    577577    unsigned long special_port;
     
    594594    value = inl(special_port);
    595595
     596    snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
    596597    return 0;
    597598}
     599
     600static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * filename)
     601{
     602    int err;
     603    int n, i;
     604    int reg;
     605    int value;
     606    const struct firmware *fw_entry;
     607
     608    if ((err = request_firmware(&fw_entry, filename, &emu->pci->dev)) != 0) {
     609        snd_printk(KERN_ERR "firmware: %s not found. Err=%d\n",filename, err);
     610        return err;
     611    }
     612
     613    snd_printk(KERN_INFO "firmware size=0x%zx\n", fw_entry->size);
     614    if (fw_entry->size != 0x133a4) {
     615        snd_printk(KERN_ERR "firmware: %s wrong size.\n",filename);
     616        return -EINVAL;
     617    }
     618
     619    /* The FPGA is a Xilinx Spartan IIE XC2S50E */
     620    /* GPIO7 -> FPGA PGMN
     621     * GPIO6 -> FPGA CCLK
     622     * GPIO5 -> FPGA DIN
     623     * FPGA CONFIG OFF -> FPGA PGMN
     624     */
     625    outl(0x00, emu->port + A_IOCFG); /* Set PGMN low for 1uS. */
     626    udelay(1);
     627    outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */
     628    udelay(100); /* Allow FPGA memory to clean */
     629    for(n = 0; n < fw_entry->size; n++) {
     630        value=fw_entry->data[n];
     631        for(i = 0; i < 8; i++) {
     632            reg = 0x80;
     633            if (value & 0x1)
     634                reg = reg | 0x20;
     635            value = value >> 1;
     636            outl(reg, emu->port + A_IOCFG);
     637            outl(reg | 0x40, emu->port + A_IOCFG);
     638        }
     639    }
     640    /* After programming, set GPIO bit 4 high again. */
     641    outl(0x10, emu->port + A_IOCFG);
     642
     643
     644    release_firmware(fw_entry);
     645    return 0;
     646}
     647
     648static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
     649{
     650    unsigned int i;
     651    int tmp,tmp2;
     652    int reg;
     653    int err;
     654    const char *hana_filename = "emu/hana.fw";
     655    const char *dock_filename = "emu/audio_dock.fw";
     656
     657    snd_printk(KERN_INFO "emu1010: Special config.\n");
     658    /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
     659     * Lock Sound Memory Cache, Lock Tank Memory Cache,
     660     * Mute all codecs.
     661     */
     662
     663    outl(0x0005a00c, emu->port + HCFG);
     664    /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
     665     * Lock Tank Memory Cache,
     666     * Mute all codecs.
     667     */
     668    outl(0x0005a004, emu->port + HCFG);
     669    /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
     670     * Mute all codecs.
     671     */
     672    outl(0x0005a000, emu->port + HCFG);
     673    /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
     674     * Mute all codecs.
     675     */
     676    outl(0x0005a000, emu->port + HCFG);
     677
     678    /* Disable 48Volt power to Audio Dock */
     679    snd_emu1010_fpga_write(emu,  EMU_HANA_DOCK_PWR,  0 );
     680
     681    /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
     682    snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
     683    snd_printdd("reg1=0x%x\n",reg);
     684    if (reg == 0x55) {
     685        /* FPGA netlist already present so clear it */
     686        /* Return to programming mode */
     687
     688        snd_emu1010_fpga_write(emu,  EMU_HANA_FPGA_CONFIG, 0x02 );
     689    }
     690    snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
     691    snd_printdd("reg2=0x%x\n",reg);
     692    if (reg == 0x55) {
     693        /* FPGA failed to return to programming mode */
     694        return -ENODEV;
     695    }
     696    snd_printk(KERN_INFO "emu1010: EMU_HANA_ID=0x%x\n",reg);
     697    if ((err = snd_emu1010_load_firmware(emu, hana_filename)) != 0) {
     698        snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file %s failed\n", hana_filename);
     699        return err;
     700    }
     701
     702    /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
     703    snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
     704    if (reg != 0x55) {
     705        /* FPGA failed to be programmed */
     706        snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg=0x%x\n", reg);
     707        return -ENODEV;
     708    }
     709
     710    snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
     711    snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp );
     712    snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2 );
     713    snd_printk("Hana ver:%d.%d\n",tmp ,tmp2);
     714    /* Enable 48Volt power to Audio Dock */
     715    snd_emu1010_fpga_write(emu,  EMU_HANA_DOCK_PWR,  EMU_HANA_DOCK_PWR_ON );
     716
     717    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
     718    snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
     719    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
     720    snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
     721    snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp );
     722    /* ADAT input. */
     723    snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x01 );
     724    snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp );
     725    /* Set no attenuation on Audio Dock pads. */
     726    snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00 );
     727    emu->emu1010.adc_pads = 0x00;
     728    snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
     729    /* Unmute Audio dock DACs, Headphone source DAC-4. */
     730    snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
     731    snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
     732    snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp );
     733    /* DAC PADs. */
     734    snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f );
     735    emu->emu1010.dac_pads = 0x0f;
     736    snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
     737    snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
     738    snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
     739    /* SPDIF Format. Set Consumer mode, 24bit, copy enable */
     740    snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 );
     741    /* MIDI routing */
     742    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 );
     743    /* Unknown. */
     744    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c );
     745    /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); // IRQ Enable: All on */
     746    /* IRQ Enable: All off */
     747    snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00 );
     748
     749    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
     750    snd_printk(KERN_INFO "emu1010: Card options3=0x%x\n",reg);
     751    /* Default WCLK set to 48kHz. */
     752    snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00 );
     753    /* Word Clock source, Internal 48kHz x1 */
     754    snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
     755    //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X );
     756    /* Audio Dock LEDs. */
     757    snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
     758
     759#if 0
     760    /* For 96kHz */
     761    snd_emu1010_fpga_link_dst_src_write(emu,
     762                                        EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
     763    snd_emu1010_fpga_link_dst_src_write(emu,
     764                                        EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
     765    snd_emu1010_fpga_link_dst_src_write(emu,
     766                                        EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT2);
     767    snd_emu1010_fpga_link_dst_src_write(emu,
     768                                        EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT2);
     769#endif
     770#if 0
     771    /* For 192kHz */
     772    snd_emu1010_fpga_link_dst_src_write(emu,
     773                                        EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
     774    snd_emu1010_fpga_link_dst_src_write(emu,
     775                                        EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
     776    snd_emu1010_fpga_link_dst_src_write(emu,
     777                                        EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
     778    snd_emu1010_fpga_link_dst_src_write(emu,
     779                                        EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_RIGHT2);
     780    snd_emu1010_fpga_link_dst_src_write(emu,
     781                                        EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT3);
     782    snd_emu1010_fpga_link_dst_src_write(emu,
     783                                        EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT3);
     784    snd_emu1010_fpga_link_dst_src_write(emu,
     785                                        EMU_DST_ALICE2_EMU32_6, EMU_SRC_HAMOA_ADC_LEFT4);
     786    snd_emu1010_fpga_link_dst_src_write(emu,
     787                                        EMU_DST_ALICE2_EMU32_7, EMU_SRC_HAMOA_ADC_RIGHT4);
     788#endif
     789#if 1
     790    /* For 48kHz */
     791    snd_emu1010_fpga_link_dst_src_write(emu,
     792                                        EMU_DST_ALICE2_EMU32_0, EMU_SRC_DOCK_MIC_A1);
     793    snd_emu1010_fpga_link_dst_src_write(emu,
     794                                        EMU_DST_ALICE2_EMU32_1, EMU_SRC_DOCK_MIC_B1);
     795    snd_emu1010_fpga_link_dst_src_write(emu,
     796                                        EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
     797    snd_emu1010_fpga_link_dst_src_write(emu,
     798                                        EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_LEFT2);
     799    snd_emu1010_fpga_link_dst_src_write(emu,
     800                                        EMU_DST_ALICE2_EMU32_4, EMU_SRC_DOCK_ADC1_LEFT1);
     801    snd_emu1010_fpga_link_dst_src_write(emu,
     802                                        EMU_DST_ALICE2_EMU32_5, EMU_SRC_DOCK_ADC1_RIGHT1);
     803    snd_emu1010_fpga_link_dst_src_write(emu,
     804                                        EMU_DST_ALICE2_EMU32_6, EMU_SRC_DOCK_ADC2_LEFT1);
     805    snd_emu1010_fpga_link_dst_src_write(emu,
     806                                        EMU_DST_ALICE2_EMU32_7, EMU_SRC_DOCK_ADC2_RIGHT1);
     807#endif
     808#if 0
     809    /* Original */
     810    snd_emu1010_fpga_link_dst_src_write(emu,
     811                                        EMU_DST_ALICE2_EMU32_4, EMU_SRC_HANA_ADAT);
     812    snd_emu1010_fpga_link_dst_src_write(emu,
     813                                        EMU_DST_ALICE2_EMU32_5, EMU_SRC_HANA_ADAT + 1);
     814    snd_emu1010_fpga_link_dst_src_write(emu,
     815                                        EMU_DST_ALICE2_EMU32_6, EMU_SRC_HANA_ADAT + 2);
     816    snd_emu1010_fpga_link_dst_src_write(emu,
     817                                        EMU_DST_ALICE2_EMU32_7, EMU_SRC_HANA_ADAT + 3);
     818    snd_emu1010_fpga_link_dst_src_write(emu,
     819                                        EMU_DST_ALICE2_EMU32_8, EMU_SRC_HANA_ADAT + 4);
     820    snd_emu1010_fpga_link_dst_src_write(emu,
     821                                        EMU_DST_ALICE2_EMU32_9, EMU_SRC_HANA_ADAT + 5);
     822    snd_emu1010_fpga_link_dst_src_write(emu,
     823                                        EMU_DST_ALICE2_EMU32_A, EMU_SRC_HANA_ADAT + 6);
     824    snd_emu1010_fpga_link_dst_src_write(emu,
     825                                        EMU_DST_ALICE2_EMU32_B, EMU_SRC_HANA_ADAT + 7);
     826    snd_emu1010_fpga_link_dst_src_write(emu,
     827                                        EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_MIC_A1);
     828    snd_emu1010_fpga_link_dst_src_write(emu,
     829                                        EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_MIC_B1);
     830    snd_emu1010_fpga_link_dst_src_write(emu,
     831                                        EMU_DST_ALICE2_EMU32_E, EMU_SRC_HAMOA_ADC_LEFT2);
     832    snd_emu1010_fpga_link_dst_src_write(emu,
     833                                        EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2);
     834#endif
     835    for (i=0;i < 0x20;i++) {
     836        /* AudioDock Elink <-  Silence */
     837        snd_emu1010_fpga_link_dst_src_write(emu, 0x0100+i, EMU_SRC_SILENCE);
     838    }
     839    for (i=0;i < 4;i++) {
     840        /* Hana SPDIF Out <- Silence */
     841        snd_emu1010_fpga_link_dst_src_write(emu, 0x0200+i, EMU_SRC_SILENCE);
     842    }
     843    for (i=0;i < 7;i++) {
     844        /* Hamoa DAC <- Silence */
     845        snd_emu1010_fpga_link_dst_src_write(emu, 0x0300+i, EMU_SRC_SILENCE);
     846    }
     847    for (i=0;i < 7;i++) {
     848        /* Hana ADAT Out <- Silence */
     849        snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE);
     850    }
     851    snd_emu1010_fpga_link_dst_src_write(emu,
     852                                        EMU_DST_ALICE_I2S0_LEFT, EMU_SRC_DOCK_ADC1_LEFT1);
     853    snd_emu1010_fpga_link_dst_src_write(emu,
     854                                        EMU_DST_ALICE_I2S0_RIGHT, EMU_SRC_DOCK_ADC1_RIGHT1);
     855    snd_emu1010_fpga_link_dst_src_write(emu,
     856                                        EMU_DST_ALICE_I2S1_LEFT, EMU_SRC_DOCK_ADC2_LEFT1);
     857    snd_emu1010_fpga_link_dst_src_write(emu,
     858                                        EMU_DST_ALICE_I2S1_RIGHT, EMU_SRC_DOCK_ADC2_RIGHT1);
     859    snd_emu1010_fpga_link_dst_src_write(emu,
     860                                        EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1);
     861    snd_emu1010_fpga_link_dst_src_write(emu,
     862                                        EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1);
     863    snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01 ); // Unmute all
     864
     865    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
     866
     867    /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
     868     * Lock Sound Memory Cache, Lock Tank Memory Cache,
     869     * Mute all codecs.
     870     */
     871    outl(0x0000a000, emu->port + HCFG);
     872    /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
     873     * Lock Sound Memory Cache, Lock Tank Memory Cache,
     874     * Un-Mute all codecs.
     875     */
     876    outl(0x0000a001, emu->port + HCFG);
     877
     878    /* Initial boot complete. Now patches */
     879
     880    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
     881    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
     882    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
     883    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
     884    snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
     885    snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
     886    snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 ); /* SPDIF Format spdif  (or 0x11 for aes/ebu) */
     887
     888    /* Delay to allow Audio Dock to settle */
     889    msleep(100);
     890    snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp ); /* IRQ Status */
     891    snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); /* OPTIONS: Which cards are attached to the EMU */
     892    /* FIXME: The loading of this should be able to happen any time,
     893     * as the user can plug/unplug it at any time
     894     */
     895    if (reg & (EMU_HANA_OPTION_DOCK_ONLINE | EMU_HANA_OPTION_DOCK_OFFLINE) ) {
     896        /* Audio Dock attached */
     897        /* Return to Audio Dock programming mode */
     898        snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
     899        snd_emu1010_fpga_write(emu,  EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK );
     900        if ((err = snd_emu1010_load_firmware(emu, dock_filename)) != 0) {
     901            return err;
     902        }
     903        snd_emu1010_fpga_write(emu,  EMU_HANA_FPGA_CONFIG, 0 );
     904        snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg );
     905        snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS=0x%x\n",reg);
     906        /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
     907        snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
     908        snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID=0x%x\n",reg);
     909        if (reg != 0x55) {
     910            /* FPGA failed to be programmed */
     911            snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg=0x%x\n", reg);
     912            return 0;
     913            return -ENODEV;
     914        }
     915        snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
     916        snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp );
     917        snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2 );
     918        snd_printk("Audio Dock ver:%d.%d\n",tmp ,tmp2);
     919    }
     920#if 0
     921    snd_emu1010_fpga_link_dst_src_write(emu,
     922                                        EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32B + 2); /* ALICE2 bus 0xa2 */
     923    snd_emu1010_fpga_link_dst_src_write(emu,
     924                                        EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32B + 3); /* ALICE2 bus 0xa3 */
     925    snd_emu1010_fpga_link_dst_src_write(emu,
     926                                        EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 2); /* ALICE2 bus 0xb2 */
     927    snd_emu1010_fpga_link_dst_src_write(emu,
     928                                        EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 3); /* ALICE2 bus 0xb3 */
     929#endif
     930    /* Default outputs */
     931    snd_emu1010_fpga_link_dst_src_write(emu,
     932                                        EMU_DST_DOCK_DAC1_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     933    emu->emu1010.output_source[0] = 21;
     934    snd_emu1010_fpga_link_dst_src_write(emu,
     935                                        EMU_DST_DOCK_DAC1_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
     936    emu->emu1010.output_source[1] = 22;
     937    snd_emu1010_fpga_link_dst_src_write(emu,
     938                                        EMU_DST_DOCK_DAC2_LEFT1, EMU_SRC_ALICE_EMU32A + 2);
     939    emu->emu1010.output_source[2] = 23;
     940    snd_emu1010_fpga_link_dst_src_write(emu,
     941                                        EMU_DST_DOCK_DAC2_RIGHT1, EMU_SRC_ALICE_EMU32A + 3);
     942    emu->emu1010.output_source[3] = 24;
     943    snd_emu1010_fpga_link_dst_src_write(emu,
     944                                        EMU_DST_DOCK_DAC3_LEFT1, EMU_SRC_ALICE_EMU32A + 4);
     945    emu->emu1010.output_source[4] = 25;
     946    snd_emu1010_fpga_link_dst_src_write(emu,
     947                                        EMU_DST_DOCK_DAC3_RIGHT1, EMU_SRC_ALICE_EMU32A + 5);
     948    emu->emu1010.output_source[5] = 26;
     949    snd_emu1010_fpga_link_dst_src_write(emu,
     950                                        EMU_DST_DOCK_DAC4_LEFT1, EMU_SRC_ALICE_EMU32A + 6);
     951    emu->emu1010.output_source[6] = 27;
     952    snd_emu1010_fpga_link_dst_src_write(emu,
     953                                        EMU_DST_DOCK_DAC4_RIGHT1, EMU_SRC_ALICE_EMU32A + 7);
     954    emu->emu1010.output_source[7] = 28;
     955    snd_emu1010_fpga_link_dst_src_write(emu,
     956                                        EMU_DST_DOCK_PHONES_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     957    emu->emu1010.output_source[8] = 21;
     958    snd_emu1010_fpga_link_dst_src_write(emu,
     959                                        EMU_DST_DOCK_PHONES_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
     960    emu->emu1010.output_source[9] = 22;
     961    snd_emu1010_fpga_link_dst_src_write(emu,
     962                                        EMU_DST_DOCK_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     963    emu->emu1010.output_source[10] = 21;
     964    snd_emu1010_fpga_link_dst_src_write(emu,
     965                                        EMU_DST_DOCK_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
     966    emu->emu1010.output_source[11] = 22;
     967    snd_emu1010_fpga_link_dst_src_write(emu,
     968                                        EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     969    emu->emu1010.output_source[12] = 21;
     970    snd_emu1010_fpga_link_dst_src_write(emu,
     971                                        EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
     972    emu->emu1010.output_source[13] = 22;
     973    snd_emu1010_fpga_link_dst_src_write(emu,
     974                                        EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     975    emu->emu1010.output_source[14] = 21;
     976    snd_emu1010_fpga_link_dst_src_write(emu,
     977                                        EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
     978    emu->emu1010.output_source[15] = 22;
     979    snd_emu1010_fpga_link_dst_src_write(emu,
     980                                        EMU_DST_HANA_ADAT, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
     981    emu->emu1010.output_source[16] = 21;
     982    snd_emu1010_fpga_link_dst_src_write(emu,
     983                                        EMU_DST_HANA_ADAT + 1, EMU_SRC_ALICE_EMU32A + 1);
     984    emu->emu1010.output_source[17] = 22;
     985    snd_emu1010_fpga_link_dst_src_write(emu,
     986                                        EMU_DST_HANA_ADAT + 2, EMU_SRC_ALICE_EMU32A + 2);
     987    emu->emu1010.output_source[18] = 23;
     988    snd_emu1010_fpga_link_dst_src_write(emu,
     989                                        EMU_DST_HANA_ADAT + 3, EMU_SRC_ALICE_EMU32A + 3);
     990    emu->emu1010.output_source[19] = 24;
     991    snd_emu1010_fpga_link_dst_src_write(emu,
     992                                        EMU_DST_HANA_ADAT + 4, EMU_SRC_ALICE_EMU32A + 4);
     993    emu->emu1010.output_source[20] = 25;
     994    snd_emu1010_fpga_link_dst_src_write(emu,
     995                                        EMU_DST_HANA_ADAT + 5, EMU_SRC_ALICE_EMU32A + 5);
     996    emu->emu1010.output_source[21] = 26;
     997    snd_emu1010_fpga_link_dst_src_write(emu,
     998                                        EMU_DST_HANA_ADAT + 6, EMU_SRC_ALICE_EMU32A + 6);
     999    emu->emu1010.output_source[22] = 27;
     1000    snd_emu1010_fpga_link_dst_src_write(emu,
     1001                                        EMU_DST_HANA_ADAT + 7, EMU_SRC_ALICE_EMU32A + 7);
     1002    emu->emu1010.output_source[23] = 28;
     1003
     1004    /* TEMP: Select SPDIF in/out */
     1005    snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); /* Output spdif */
     1006
     1007    /* TEMP: Select 48kHz SPDIF out */
     1008    snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */
     1009    snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */
     1010    /* Word Clock source, Internal 48kHz x1 */
     1011    snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
     1012    //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X );
     1013    emu->emu1010.internal_clock = 1; /* 48000 */
     1014    snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);/* Set LEDs on Audio Dock */
     1015    snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */
     1016    //snd_emu1010_fpga_write(emu, 0x7, 0x0); /* Mute all */
     1017    //snd_emu1010_fpga_write(emu, 0x7, 0x1); /* Unmute all */
     1018    //snd_emu1010_fpga_write(emu, 0xe, 0x12); /* Set LEDs on Audio Dock */
     1019
     1020    return 0;
     1021}
     1022
    5981023
    5991024/*
    6001025 *  Create the EMU10K1 instance
    6011026 */
     1027
     1028#ifdef CONFIG_PM
     1029static int alloc_pm_buffer(struct snd_emu10k1 *emu);
     1030static void free_pm_buffer(struct snd_emu10k1 *emu);
     1031#endif
    6021032
    6031033static int snd_emu10k1_free(struct snd_emu10k1 *emu)
     
    6061036        snd_emu10k1_fx8010_tram_setup(emu, 0);
    6071037        snd_emu10k1_done(emu);
    608     }
     1038        /* remove reserved page */
     1039        if (emu->reserved_page) {
     1040            snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
     1041            emu->reserved_page = NULL;
     1042        }
     1043        snd_emu10k1_free_efx(emu);
     1044    }
     1045    if (emu->card_capabilities->emu1010) {
     1046        /* Disable 48Volt power to Audio Dock */
     1047        snd_emu1010_fpga_write(emu,  EMU_HANA_DOCK_PWR,  0 );
     1048    }
     1049
    6091050    if (emu->memhdr)
    6101051        snd_util_memhdr_free(emu->memhdr);
     
    6131054    if (emu->ptb_pages.area)
    6141055        snd_dma_free_pages(&emu->ptb_pages);
    615     if (emu->page_ptr_table)
    616         vfree(emu->page_ptr_table);
    617     if (emu->page_addr_table)
    618         vfree(emu->page_addr_table);
     1056    vfree(emu->page_ptr_table);
     1057    vfree(emu->page_addr_table);
     1058#ifdef CONFIG_PM
     1059    free_pm_buffer(emu);
     1060#endif
    6191061    if (emu->irq >= 0)
    6201062        free_irq(emu->irq, (void *)emu);
    6211063    if (emu->port)
    6221064        pci_release_regions(emu->pci);
    623     if (emu->audigy && emu->revision == 4) /* P16V */
     1065    if (emu->card_capabilities->ca0151_chip) /* P16V */
    6241066        snd_p16v_free(emu);
     1067    pci_disable_device(emu->pci);
    6251068    kfree(emu);
    6261069    return 0;
    6271070}
    6281071
    629 static int snd_emu10k1_dev_free(snd_device_t *device)
     1072static int snd_emu10k1_dev_free(struct snd_device *device)
    6301073{
    6311074    struct snd_emu10k1 *emu = device->device_data;
     
    6331076}
    6341077
    635 /* vendor, device, subsystem, emu10k1_chip, emu10k2_chip, ca0102_chip, ca0108_chip, ca0151_chip, spk71, spdif_bug, ac97_chip, ecard, driver, name */
    6361078static struct snd_emu_chip_details emu_chip_details[] = {
    637         /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
    638         /* Tested by James@superbug.co.uk 3rd July 2005 */
    639         {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
    640          .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
    641          .id = "Audigy2",
    642          .emu10k2_chip = 1,
    643          .ca0108_chip = 1,
    644          .spk71 = 1,
    645          .ac97_chip = 1} ,
    646          /* Audigy 2 ZS Notebook Cardbus card.*/
    647          /* Tested by James@superbug.co.uk 30th October 2005 */
    648          /* Not working yet, but progressing. */
    649          {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
    650          .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
    651          .id = "Audigy2",
    652          .emu10k2_chip = 1,
    653          .ca0108_chip = 1,
    654          .ca_cardbus_chip = 1,
    655          .spk71 = 1} ,
    656         {.vendor = 0x1102, .device = 0x0008,
    657          .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
    658          .id = "Audigy2",
    659          .emu10k2_chip = 1,
    660          .ca0108_chip = 1,
    661          .ac97_chip = 1} ,
    662         /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
    663         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
    664          .driver = "Audigy2", .name = "E-mu 1212m [4001]",
    665          .id = "EMU1212m",
    666          .emu10k2_chip = 1,
    667          .ca0102_chip = 1,
    668          .ecard = 1} ,
    669         /* Tested by James@superbug.co.uk 3rd July 2005 */
    670         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
    671          .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
    672          .id = "Audigy2",
    673          .emu10k2_chip = 1,
    674          .ca0102_chip = 1,
    675          .ca0151_chip = 1,
    676          .spk71 = 1,
    677          .spdif_bug = 1,
    678          .ac97_chip = 1} ,
    679         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
    680          .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
    681          .id = "Audigy2",
    682          .emu10k2_chip = 1,
    683          .ca0102_chip = 1,
    684          .ca0151_chip = 1,
    685          .spk71 = 1,
    686          .spdif_bug = 1,
    687          .ac97_chip = 1} ,
    688         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
    689          .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
    690          .id = "Audigy2",
    691          .emu10k2_chip = 1,
    692          .ca0102_chip = 1,
    693          .ca0151_chip = 1,
    694          .spk71 = 1,
    695          .spdif_bug = 1,
    696          .ac97_chip = 1} ,
    697         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
    698          .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
    699          .id = "Audigy2",
    700          .emu10k2_chip = 1,
    701          .ca0102_chip = 1,
    702          .ca0151_chip = 1,
    703          .spk71 = 1,
    704          .spdif_bug = 1,
    705          .ac97_chip = 1} ,
    706         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
    707          .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
    708          .id = "Audigy2",
    709          .emu10k2_chip = 1,
    710          .ca0102_chip = 1,
    711          .ca0151_chip = 1,
    712          .spdif_bug = 1} ,
    713         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
    714          .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
    715          .id = "Audigy2",
    716          .emu10k2_chip = 1,
    717          .ca0102_chip = 1,
    718          .ca0151_chip = 1,
    719          .spk71 = 1,
    720          .spdif_bug = 1,
    721          .ac97_chip = 1} ,
    722         {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
    723          .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
    724          .id = "Audigy2",
    725          .emu10k2_chip = 1,
    726          .ca0102_chip = 1,
    727          .ca0151_chip = 1,
    728          .spdif_bug = 1,
    729          .ac97_chip = 1} ,
    730         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
    731          .driver = "Audigy", .name = "Audigy 1 [SB0090]",
    732          .id = "Audigy",
    733          .emu10k2_chip = 1,
    734          .ca0102_chip = 1,
    735          .ac97_chip = 1} ,
    736         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
    737          .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
    738          .id = "Audigy",
    739          .emu10k2_chip = 1,
    740          .ca0102_chip = 1,
    741          .spdif_bug = 1,
    742          .ac97_chip = 1} ,
    743         {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
    744          .driver = "Audigy", .name = "Audigy 1 [SB0090]",
    745          .id = "Audigy",
    746          .emu10k2_chip = 1,
    747          .ca0102_chip = 1,
    748          .ac97_chip = 1} ,
    749         {.vendor = 0x1102, .device = 0x0004,
    750          .driver = "Audigy", .name = "Audigy 1 [Unknown]",
    751          .id = "Audigy",
    752          .emu10k2_chip = 1,
    753          .ca0102_chip = 1,
    754          .ac97_chip = 1} ,
    755         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
    756          .driver = "EMU10K1", .name = "SBLive! [SB0105]",
    757          .id = "Live",
    758          .emu10k1_chip = 1,
    759          .ac97_chip = 1,
    760          .sblive51 = 1} ,
    761         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
    762          .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
    763          .id = "Live",
    764          .emu10k1_chip = 1,
    765          .ac97_chip = 1,
    766          .sblive51 = 1} ,
    767         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
    768          .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
    769          .id = "Live",
    770          .emu10k1_chip = 1,
    771          .ac97_chip = 1,
    772          .sblive51 = 1},
    773          /* Tested by Thomas Zehetbauer 27th Aug 2005 */
    774          {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
    775          .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
    776          .id = "Live",
    777          .emu10k1_chip = 1,
    778          .ac97_chip = 1,
    779          .sblive51 = 1} ,
    780         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
    781          .driver = "EMU10K1", .name = "SB Live 5.1",
    782          .id = "Live",
    783          .emu10k1_chip = 1,
    784          .ac97_chip = 1,
    785          .sblive51 = 1} ,
    786          /* Tested by alsa bugtrack user "hus" 12th Sept 2005 */
    787          {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
    788          .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
    789          .id = "Live",
    790          .emu10k1_chip = 1,
    791          .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
    792          * share the same IDs!
    793          */
    794          .sblive51 = 1} ,
    795         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
    796          .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
    797          .id = "Live",
    798          .emu10k1_chip = 1,
    799          .ac97_chip = 1,
    800          .sblive51 = 1} ,
    801         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
    802          .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
    803          .id = "Live",
    804          .emu10k1_chip = 1,
    805          .ac97_chip = 1} ,
    806         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
    807          .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
    808          .id = "Live",
    809          .emu10k1_chip = 1,
    810          .ac97_chip = 1,
    811          .sblive51 = 1} ,
    812         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
    813          .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
    814          .id = "Live",
    815          .emu10k1_chip = 1,
    816          .ac97_chip = 1,
    817          .sblive51 = 1} ,
    818         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
    819          .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
    820          .id = "Live",
    821          .emu10k1_chip = 1,
    822          .ac97_chip = 1,
    823          .sblive51 = 1} ,
    824         /* Tested by James@superbug.co.uk 3rd July 2005 */
    825         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
    826          .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
    827          .id = "Live",
    828          .emu10k1_chip = 1,
    829          .ac97_chip = 1,
    830          .sblive51 = 1} ,
    831         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
    832          .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
    833          .id = "Live",
    834          .emu10k1_chip = 1,
    835          .ac97_chip = 1,
    836          .sblive51 = 1} ,
    837         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
    838          .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
    839          .id = "Live",
    840          .emu10k1_chip = 1,
    841          .ac97_chip = 1,
    842          .sblive51 = 1} ,
    843         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
    844          .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
    845          .id = "Live",
    846          .emu10k1_chip = 1,
    847          .ac97_chip = 1,
    848          .sblive51 = 1} ,
    849         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
    850          .driver = "EMU10K1", .name = "E-mu APS [4001]",
    851          .id = "APS",
    852          .emu10k1_chip = 1,
    853          .ecard = 1} ,
    854         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
    855          .driver = "EMU10K1", .name = "SBLive! [CT4620]",
    856          .id = "Live",
    857          .emu10k1_chip = 1,
    858          .ac97_chip = 1,
    859          .sblive51 = 1} ,
    860         {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
    861          .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
    862          .id = "Live",
    863          .emu10k1_chip = 1,
    864          .ac97_chip = 1,
    865          .sblive51 = 1} ,
    866         {.vendor = 0x1102, .device = 0x0002,
    867          .driver = "EMU10K1", .name = "SB Live [Unknown]",
    868          .id = "Live",
    869          .emu10k1_chip = 1,
    870          .ac97_chip = 1,
    871          .sblive51 = 1} ,
    872         {0 } /* terminator */
     1079    /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
     1080    /* Tested by James@superbug.co.uk 3rd July 2005 */
     1081    /* DSP: CA0108-IAT
     1082     * DAC: CS4382-KQ
     1083     * ADC: Philips 1361T
     1084     * AC97: STAC9750
     1085     * CA0151: None
     1086     */
     1087    {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
     1088    .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
     1089    .id = "Audigy2",
     1090    .emu10k2_chip = 1,
     1091    .ca0108_chip = 1,
     1092    .spk71 = 1,
     1093    .ac97_chip = 1} ,
     1094    /* Audigy4 (Not PRO) SB0610 */
     1095    /* Tested by James@superbug.co.uk 4th April 2006 */
     1096    /* A_IOCFG bits
     1097     * Output
     1098     * 0: ?
     1099     * 1: ?
     1100     * 2: ?
     1101     * 3: 0 - Digital Out, 1 - Line in
     1102     * 4: ?
     1103     * 5: ?
     1104     * 6: ?
     1105     * 7: ?
     1106     * Input
     1107     * 8: ?
     1108     * 9: ?
     1109     * A: Green jack sense (Front)
     1110     * B: ?
     1111     * C: Black jack sense (Rear/Side Right)
     1112     * D: Yellow jack sense (Center/LFE/Side Left)
     1113     * E: ?
     1114     * F: ?
     1115     *
     1116     * Digital Out/Line in switch using A_IOCFG bit 3 (0x08)
     1117     * 0 - Digital Out
     1118     * 1 - Line in
     1119     */
     1120    /* Mic input not tested.
     1121     * Analog CD input not tested
     1122     * Digital Out not tested.
     1123     * Line in working.
     1124     * Audio output 5.1 working. Side outputs not working.
     1125     */
     1126    /* DSP: CA10300-IAT LF
     1127     * DAC: Cirrus Logic CS4382-KQZ
     1128     * ADC: Philips 1361T
     1129     * AC97: Sigmatel STAC9750
     1130     * CA0151: None
     1131     */
     1132    {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
     1133    .driver = "Audigy2", .name = "Audigy 4 [SB0610]",
     1134    .id = "Audigy2",
     1135    .emu10k2_chip = 1,
     1136    .ca0108_chip = 1,
     1137    .spk71 = 1,
     1138    .adc_1361t = 1,  /* 24 bit capture instead of 16bit */
     1139    .ac97_chip = 1} ,
     1140    /* Audigy 2 ZS Notebook Cardbus card.*/
     1141    /* Tested by James@superbug.co.uk 22th December 2005 */
     1142    /* Audio output 7.1/Headphones working.
     1143     * Digital output working. (AC3 not checked, only PCM)
     1144     * Audio inputs not tested.
     1145     */
     1146    /* DSP: Tina2
     1147     * DAC: Wolfson WM8768/WM8568
     1148     * ADC: Wolfson WM8775
     1149     * AC97: None
     1150     * CA0151: None
     1151     */
     1152    {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
     1153    .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
     1154    .id = "Audigy2",
     1155    .emu10k2_chip = 1,
     1156    .ca0108_chip = 1,
     1157    .ca_cardbus_chip = 1,
     1158    .spi_dac = 1,
     1159    .spk71 = 1} ,
     1160    {.vendor = 0x1102, .device = 0x0008,
     1161    .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
     1162    .id = "Audigy2",
     1163    .emu10k2_chip = 1,
     1164    .ca0108_chip = 1,
     1165    .ac97_chip = 1} ,
     1166    /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
     1167    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
     1168    .driver = "Audigy2", .name = "E-mu 1010 [4001]",
     1169    .id = "EMU1010",
     1170    .emu10k2_chip = 1,
     1171    .ca0102_chip = 1,
     1172    .spk71 = 1,
     1173    .emu1010 = 1} ,
     1174    /* Tested by James@superbug.co.uk 3rd July 2005 */
     1175    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
     1176    .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
     1177    .id = "Audigy2",
     1178    .emu10k2_chip = 1,
     1179    .ca0102_chip = 1,
     1180    .ca0151_chip = 1,
     1181    .spk71 = 1,
     1182    .spdif_bug = 1,
     1183    .ac97_chip = 1} ,
     1184    /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
     1185    /* The 0x20061102 does have SB0350 written on it
     1186     * Just like 0x20021102
     1187     */
     1188    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
     1189    .driver = "Audigy2", .name = "Audigy 2 [SB0350b]",
     1190    .id = "Audigy2",
     1191    .emu10k2_chip = 1,
     1192    .ca0102_chip = 1,
     1193    .ca0151_chip = 1,
     1194    .spk71 = 1,
     1195    .spdif_bug = 1,
     1196    .ac97_chip = 1} ,
     1197    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
     1198    .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
     1199    .id = "Audigy2",
     1200    .emu10k2_chip = 1,
     1201    .ca0102_chip = 1,
     1202    .ca0151_chip = 1,
     1203    .spk71 = 1,
     1204    .spdif_bug = 1,
     1205    .ac97_chip = 1} ,
     1206    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
     1207    .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
     1208    .id = "Audigy2",
     1209    .emu10k2_chip = 1,
     1210    .ca0102_chip = 1,
     1211    .ca0151_chip = 1,
     1212    .spk71 = 1,
     1213    .spdif_bug = 1,
     1214    .ac97_chip = 1} ,
     1215    /* Audigy 2 */
     1216    /* Tested by James@superbug.co.uk 3rd July 2005 */
     1217    /* DSP: CA0102-IAT
     1218     * DAC: CS4382-KQ
     1219     * ADC: Philips 1361T
     1220     * AC97: STAC9721
     1221     * CA0151: Yes
     1222     */
     1223    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
     1224    .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
     1225    .id = "Audigy2",
     1226    .emu10k2_chip = 1,
     1227    .ca0102_chip = 1,
     1228    .ca0151_chip = 1,
     1229    .spk71 = 1,
     1230    .spdif_bug = 1,
     1231    .adc_1361t = 1,  /* 24 bit capture instead of 16bit */
     1232    .ac97_chip = 1} ,
     1233    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
     1234    .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
     1235    .id = "Audigy2",
     1236    .emu10k2_chip = 1,
     1237    .ca0102_chip = 1,
     1238    .ca0151_chip = 1,
     1239    .spk71 = 1,
     1240    .spdif_bug = 1} ,
     1241    /* Dell OEM/Creative Labs Audigy 2 ZS */
     1242    /* See ALSA bug#1365 */
     1243    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
     1244    .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]",
     1245    .id = "Audigy2",
     1246    .emu10k2_chip = 1,
     1247    .ca0102_chip = 1,
     1248    .ca0151_chip = 1,
     1249    .spk71 = 1,
     1250    .spdif_bug = 1,
     1251    .ac97_chip = 1} ,
     1252    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
     1253    .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
     1254    .id = "Audigy2",
     1255    .emu10k2_chip = 1,
     1256    .ca0102_chip = 1,
     1257    .ca0151_chip = 1,
     1258    .spk71 = 1,
     1259    .spdif_bug = 1,
     1260    .ac97_chip = 1} ,
     1261    {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
     1262    .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
     1263    .id = "Audigy2",
     1264    .emu10k2_chip = 1,
     1265    .ca0102_chip = 1,
     1266    .ca0151_chip = 1,
     1267    .spdif_bug = 1,
     1268    .ac97_chip = 1} ,
     1269    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
     1270    .driver = "Audigy", .name = "Audigy 1 [SB0090]",
     1271    .id = "Audigy",
     1272    .emu10k2_chip = 1,
     1273    .ca0102_chip = 1,
     1274    .ac97_chip = 1} ,
     1275    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
     1276    .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
     1277    .id = "Audigy",
     1278    .emu10k2_chip = 1,
     1279    .ca0102_chip = 1,
     1280    .spdif_bug = 1,
     1281    .ac97_chip = 1} ,
     1282    {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
     1283    .driver = "Audigy", .name = "Audigy 1 [SB0090]",
     1284    .id = "Audigy",
     1285    .emu10k2_chip = 1,
     1286    .ca0102_chip = 1,
     1287    .ac97_chip = 1} ,
     1288    {.vendor = 0x1102, .device = 0x0004,
     1289    .driver = "Audigy", .name = "Audigy 1 [Unknown]",
     1290    .id = "Audigy",
     1291    .emu10k2_chip = 1,
     1292    .ca0102_chip = 1,
     1293    .ac97_chip = 1} ,
     1294    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
     1295    .driver = "EMU10K1", .name = "SBLive! [SB0105]",
     1296    .id = "Live",
     1297    .emu10k1_chip = 1,
     1298    .ac97_chip = 1,
     1299    .sblive51 = 1} ,
     1300    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
     1301    .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
     1302    .id = "Live",
     1303    .emu10k1_chip = 1,
     1304    .ac97_chip = 1,
     1305    .sblive51 = 1} ,
     1306    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
     1307    .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
     1308    .id = "Live",
     1309    .emu10k1_chip = 1,
     1310    .ac97_chip = 1,
     1311    .sblive51 = 1},
     1312    /* Tested by ALSA bug#1680 26th December 2005 */
     1313    /* note: It really has SB0220 written on the card. */
     1314    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
     1315    .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]",
     1316    .id = "Live",
     1317    .emu10k1_chip = 1,
     1318    .ac97_chip = 1,
     1319    .sblive51 = 1} ,
     1320    /* Tested by Thomas Zehetbauer 27th Aug 2005 */
     1321    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
     1322    .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
     1323    .id = "Live",
     1324    .emu10k1_chip = 1,
     1325    .ac97_chip = 1,
     1326    .sblive51 = 1} ,
     1327    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
     1328    .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
     1329    .id = "Live",
     1330    .emu10k1_chip = 1,
     1331    .ac97_chip = 1,
     1332    .sblive51 = 1} ,
     1333    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
     1334    .driver = "EMU10K1", .name = "SB Live 5.1",
     1335    .id = "Live",
     1336    .emu10k1_chip = 1,
     1337    .ac97_chip = 1,
     1338    .sblive51 = 1} ,
     1339    /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
     1340    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
     1341    .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
     1342    .id = "Live",
     1343    .emu10k1_chip = 1,
     1344    .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
     1345    * share the same IDs!
     1346    */
     1347    .sblive51 = 1} ,
     1348    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
     1349    .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
     1350    .id = "Live",
     1351    .emu10k1_chip = 1,
     1352    .ac97_chip = 1,
     1353    .sblive51 = 1} ,
     1354    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
     1355    .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
     1356    .id = "Live",
     1357    .emu10k1_chip = 1,
     1358    .ac97_chip = 1} ,
     1359    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
     1360    .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
     1361    .id = "Live",
     1362    .emu10k1_chip = 1,
     1363    .ac97_chip = 1,
     1364    .sblive51 = 1} ,
     1365    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
     1366    .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
     1367    .id = "Live",
     1368    .emu10k1_chip = 1,
     1369    .ac97_chip = 1,
     1370    .sblive51 = 1} ,
     1371    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
     1372    .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
     1373    .id = "Live",
     1374    .emu10k1_chip = 1,
     1375    .ac97_chip = 1,
     1376    .sblive51 = 1} ,
     1377    /* Tested by James@superbug.co.uk 3rd July 2005 */
     1378    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
     1379    .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
     1380    .id = "Live",
     1381    .emu10k1_chip = 1,
     1382    .ac97_chip = 1,
     1383    .sblive51 = 1} ,
     1384    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
     1385    .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
     1386    .id = "Live",
     1387    .emu10k1_chip = 1,
     1388    .ac97_chip = 1,
     1389    .sblive51 = 1} ,
     1390    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
     1391    .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
     1392    .id = "Live",
     1393    .emu10k1_chip = 1,
     1394    .ac97_chip = 1,
     1395    .sblive51 = 1} ,
     1396    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
     1397    .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
     1398    .id = "Live",
     1399    .emu10k1_chip = 1,
     1400    .ac97_chip = 1,
     1401    .sblive51 = 1} ,
     1402    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
     1403    .driver = "EMU10K1", .name = "E-mu APS [4001]",
     1404    .id = "APS",
     1405    .emu10k1_chip = 1,
     1406    .ecard = 1} ,
     1407    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
     1408    .driver = "EMU10K1", .name = "SBLive! [CT4620]",
     1409    .id = "Live",
     1410    .emu10k1_chip = 1,
     1411    .ac97_chip = 1,
     1412    .sblive51 = 1} ,
     1413    {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
     1414    .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
     1415    .id = "Live",
     1416    .emu10k1_chip = 1,
     1417    .ac97_chip = 1,
     1418    .sblive51 = 1} ,
     1419    {.vendor = 0x1102, .device = 0x0002,
     1420    .driver = "EMU10K1", .name = "SB Live [Unknown]",
     1421    .id = "Live",
     1422    .emu10k1_chip = 1,
     1423    .ac97_chip = 1,
     1424    .sblive51 = 1} ,
     1425    {0 } /* terminator */
    8731426};
    8741427
    875 int __devinit snd_emu10k1_create(snd_card_t * card,
     1428int __devinit snd_emu10k1_create(struct snd_card *card,
    8761429                                 struct pci_dev * pci,
    8771430                                 unsigned short extin_mask,
     
    8831436{
    8841437    struct snd_emu10k1 *emu;
    885     int err;
     1438    int idx, err;
    8861439    int is_audigy;
    8871440    unsigned char revision;
     1441    unsigned int silent_page;
    8881442    const struct snd_emu_chip_details *c;
    889 #ifdef TARGET_OS2
    890     static snd_device_ops_t ops = {
    891         snd_emu10k1_dev_free,0,0,0
     1443    static struct snd_device_ops ops = {
     1444        .dev_free =     snd_emu10k1_dev_free,
    8921445    };
    893 #else
    894     static snd_device_ops_t ops = {
    895     dev_free:   snd_emu10k1_dev_free,
    896     };
    897 #endif
     1446
    8981447    *remu = NULL;
    8991448
     
    9021451        return err;
    9031452
    904     emu = (struct snd_emu10k1 *)kzalloc(sizeof(*emu), GFP_KERNEL);
    905     if (emu == NULL)
     1453    emu = kzalloc(sizeof(*emu), GFP_KERNEL);
     1454    if (emu == NULL) {
     1455        pci_disable_device(pci);
    9061456        return -ENOMEM;
    907 
     1457    }
    9081458    emu->card = card;
    9091459    spin_lock_init(&emu->reg_lock);
     
    9121462    spin_lock_init(&emu->synth_lock);
    9131463    spin_lock_init(&emu->memblk_lock);
    914     init_MUTEX(&emu->ptb_lock);
    9151464    init_MUTEX(&emu->fx8010.lock);
    9161465    INIT_LIST_HEAD(&emu->mapped_link_head);
     
    9251474    pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
    9261475    pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
    927     emu->card_type = EMU10K1_CARD_CREATIVE;
    9281476    snd_printk("vendor=0x%x, device=0x%x, subsystem_vendor_id=0x%x, subsystem_id=0x%x\n",pci->vendor, pci->device, emu->serial, emu->model);
    9291477
     
    9371485                if (c->subsystem && (c->subsystem != emu->serial) )
    9381486                    continue;
    939             if (c->revision && c->revision != emu->revision)
    940                 continue;
     1487                if (c->revision && c->revision != emu->revision)
     1488                    continue;
    9411489            }
    9421490            break;
     
    9581506        snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
    9591507                    c->name, pci->vendor, pci->device, emu->serial);
     1508
     1509    if (!*card->id && c->id) {
     1510        int i, n = 0;
     1511        strlcpy(card->id, c->id, sizeof(card->id));
     1512        for (;;) {
     1513            for (i = 0; i < snd_ecards_limit; i++) {
     1514                if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
     1515                    break;
     1516            }
     1517            if (i >= snd_ecards_limit)
     1518                break;
     1519            n++;
     1520            if (n >= SNDRV_CARDS)
     1521                break;
     1522            sprintf(card->id, "%s_%d", c->id, n);
     1523        }
     1524    }
     1525
    9601526    is_audigy = emu->audigy = c->emu10k2_chip;
     1527
    9611528    /* set the DMA transfer mask */
    9621529    emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
     
    9691536    if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
    9701537        kfree(emu);
     1538        pci_disable_device(pci);
    9711539        return err;
    9721540    }
     
    9821550    if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    9831551                            32 * 1024, &emu->ptb_pages) < 0) {
    984         snd_emu10k1_free(emu);
    985         return -ENOMEM;
     1552        err = -ENOMEM;
     1553        goto error;
    9861554    }
    9871555
     
    9891557    emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
    9901558    if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
    991         snd_emu10k1_free(emu);
    992         return -ENOMEM;
     1559        err = -ENOMEM;
     1560        goto error;
    9931561    }
    9941562
    9951563    if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    9961564                            EMUPAGESIZE, &emu->silent_page) < 0) {
    997         snd_emu10k1_free(emu);
    998         return -ENOMEM;
     1565        err = -ENOMEM;
     1566        goto error;
    9991567    }
    10001568    emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
    10011569    if (emu->memhdr == NULL) {
    1002         snd_emu10k1_free(emu);
    1003         return -ENOMEM;
    1004     }
    1005     emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) - sizeof(snd_util_memblk_t);
     1570        err = -ENOMEM;
     1571        goto error;
     1572    }
     1573    emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
     1574        sizeof(struct snd_util_memblk);
    10061575
    10071576    pci_set_master(pci);
     
    10141583    emu->fx8010.extin_mask = extin_mask;
    10151584    emu->fx8010.extout_mask = extout_mask;
     1585    emu->enable_ir = enable_ir;
    10161586
    10171587    if (emu->card_capabilities->ecard) {
    1018         if ((err = snd_emu10k1_ecard_init(emu)) < 0) {
    1019             snd_emu10k1_free(emu);
    1020             return err;
    1021         }
     1588        if ((err = snd_emu10k1_ecard_init(emu)) < 0)
     1589            goto error;
    10221590    } else if (emu->card_capabilities->ca_cardbus_chip) {
    1023         if ((err = snd_emu10k1_cardbus_init(emu)) < 0) {
     1591        if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
     1592            goto error;
     1593    } else if (emu->card_capabilities->emu1010) {
     1594        if ((err = snd_emu10k1_emu1010_init(emu)) < 0) {
    10241595            snd_emu10k1_free(emu);
    10251596            return err;
     
    10311602    }
    10321603
    1033     if ((err = snd_emu10k1_init(emu, enable_ir)) < 0) {
    1034         snd_emu10k1_free(emu);
    1035         return err;
    1036     }
    1037 
    1038     if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) {
    1039         snd_emu10k1_free(emu);
    1040         return err;
    1041     }
    1042 
     1604    /* initialize TRAM setup */
     1605    emu->fx8010.itram_size = (16 * 1024)/2;
     1606    emu->fx8010.etram_pages.area = NULL;
     1607    emu->fx8010.etram_pages.bytes = 0;
     1608
     1609    /*
     1610     *  Init to 0x02109204 :
     1611     *  Clock accuracy    = 0     (1000ppm)
     1612     *  Sample Rate       = 2     (48kHz)
     1613     *  Audio Channel     = 1     (Left of 2)
     1614     *  Source Number     = 0     (Unspecified)
     1615     *  Generation Status = 1     (Original for Cat Code 12)
     1616     *  Cat Code          = 12    (Digital Signal Mixer)
     1617     *  Mode              = 0     (Mode 0)
     1618     *  Emphasis          = 0     (None)
     1619     *  CP                = 1     (Copyright unasserted)
     1620     *  AN                = 0     (Audio data)
     1621     *  P                 = 0     (Consumer)
     1622     */
     1623    emu->spdif_bits[0] = emu->spdif_bits[1] =
     1624        emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
     1625        SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     1626        SPCS_GENERATIONSTATUS | 0x00001200 |
     1627        0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
     1628
     1629    emu->reserved_page = (struct snd_emu10k1_memblk *)
     1630        snd_emu10k1_synth_alloc(emu, 4096);
     1631    if (emu->reserved_page)
     1632        emu->reserved_page->map_locked = 1;
     1633
     1634    /* Clear silent pages and set up pointers */
     1635    memset(emu->silent_page.area, 0, PAGE_SIZE);
     1636    silent_page = emu->silent_page.addr << 1;
     1637    for (idx = 0; idx < MAXPAGES; idx++)
     1638        ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
     1639
     1640    /* set up voice indices */
     1641    for (idx = 0; idx < NUM_G; idx++) {
     1642        emu->voices[idx].emu = emu;
     1643        emu->voices[idx].number = idx;
     1644    }
     1645
     1646    if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
     1647        goto error;
     1648#ifdef CONFIG_PM
     1649    if ((err = alloc_pm_buffer(emu)) < 0)
     1650        goto error;
     1651#endif
     1652
     1653    /*  Initialize the effect engine */
     1654    if ((err = snd_emu10k1_init_efx(emu)) < 0)
     1655        goto error;
     1656    snd_emu10k1_audio_enable(emu);
     1657
     1658    if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
     1659        goto error;
     1660
     1661#ifdef CONFIG_PROC_FS
    10431662    snd_emu10k1_proc_init(emu);
    1044 
     1663#endif
     1664
     1665    snd_card_set_dev(card, &pci->dev);
    10451666    *remu = emu;
    10461667    return 0;
     1668
     1669error:
     1670    snd_emu10k1_free(emu);
     1671    return err;
    10471672}
    10481673
    1049 /* memory.c */
    1050 EXPORT_SYMBOL(snd_emu10k1_synth_alloc);
    1051 EXPORT_SYMBOL(snd_emu10k1_synth_free);
    1052 EXPORT_SYMBOL(snd_emu10k1_synth_bzero);
    1053 EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);
    1054 EXPORT_SYMBOL(snd_emu10k1_memblk_map);
    1055 /* voice.c */
    1056 EXPORT_SYMBOL(snd_emu10k1_voice_alloc);
    1057 EXPORT_SYMBOL(snd_emu10k1_voice_free);
    1058 /* io.c */
    1059 EXPORT_SYMBOL(snd_emu10k1_ptr_read);
    1060 EXPORT_SYMBOL(snd_emu10k1_ptr_write);
     1674#ifdef CONFIG_PM
     1675static unsigned char saved_regs[] = {
     1676    CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
     1677    FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
     1678    ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
     1679    TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
     1680    MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
     1681    SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
     1682    0xff /* end */
     1683};
     1684static unsigned char saved_regs_audigy[] = {
     1685    A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
     1686    A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
     1687    0xff /* end */
     1688};
     1689
     1690static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
     1691{
     1692    int size;
     1693
     1694    size = ARRAY_SIZE(saved_regs);
     1695    if (emu->audigy)
     1696        size += ARRAY_SIZE(saved_regs_audigy);
     1697    emu->saved_ptr = vmalloc(4 * NUM_G * size);
     1698    if (! emu->saved_ptr)
     1699        return -ENOMEM;
     1700    if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
     1701        return -ENOMEM;
     1702    if (emu->card_capabilities->ca0151_chip &&
     1703        snd_p16v_alloc_pm_buffer(emu) < 0)
     1704        return -ENOMEM;
     1705
     1706    return 0;
     1707}
     1708
     1709static void free_pm_buffer(struct snd_emu10k1 *emu)
     1710{
     1711    vfree(emu->saved_ptr);
     1712    snd_emu10k1_efx_free_pm_buffer(emu);
     1713    if (emu->card_capabilities->ca0151_chip)
     1714        snd_p16v_free_pm_buffer(emu);
     1715}
     1716
     1717void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
     1718{
     1719    int i;
     1720    unsigned char *reg;
     1721    unsigned int *val;
     1722
     1723    val = emu->saved_ptr;
     1724    for (reg = saved_regs; *reg != 0xff; reg++)
     1725        for (i = 0; i < NUM_G; i++, val++)
     1726            *val = snd_emu10k1_ptr_read(emu, *reg, i);
     1727    if (emu->audigy) {
     1728        for (reg = saved_regs_audigy; *reg != 0xff; reg++)
     1729            for (i = 0; i < NUM_G; i++, val++)
     1730                *val = snd_emu10k1_ptr_read(emu, *reg, i);
     1731    }
     1732    if (emu->audigy)
     1733        emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
     1734    emu->saved_hcfg = inl(emu->port + HCFG);
     1735}
     1736
     1737void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
     1738{
     1739    if (emu->card_capabilities->ecard)
     1740        snd_emu10k1_ecard_init(emu);
     1741    else if (emu->card_capabilities->ca_cardbus_chip)
     1742        snd_emu10k1_cardbus_init(emu);
     1743    else if (emu->card_capabilities->emu1010)
     1744        snd_emu10k1_emu1010_init(emu);
     1745    else
     1746        snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
     1747    snd_emu10k1_init(emu, emu->enable_ir, 1);
     1748}
     1749
     1750void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
     1751{
     1752    int i;
     1753    unsigned char *reg;
     1754    unsigned int *val;
     1755
     1756    snd_emu10k1_audio_enable(emu);
     1757
     1758    /* resore for spdif */
     1759    if (emu->audigy)
     1760        outl(emu->saved_a_iocfg, emu->port + A_IOCFG);
     1761    outl(emu->saved_hcfg, emu->port + HCFG);
     1762
     1763    val = emu->saved_ptr;
     1764    for (reg = saved_regs; *reg != 0xff; reg++)
     1765        for (i = 0; i < NUM_G; i++, val++)
     1766            snd_emu10k1_ptr_write(emu, *reg, i, *val);
     1767    if (emu->audigy) {
     1768        for (reg = saved_regs_audigy; *reg != 0xff; reg++)
     1769            for (i = 0; i < NUM_G; i++, val++)
     1770                snd_emu10k1_ptr_write(emu, *reg, i, *val);
     1771    }
     1772}
     1773#endif
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_patch.c

    r34 r84  
    2323 */
    2424
    25 #define __NO_VERSION__
    2625#include "emu10k1_synth_local.h"
    2726
     
    3837int
    3938snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
    40                        snd_util_memhdr_t *hdr, const void *data, long count)
     39                       struct snd_util_memhdr *hdr,
     40                       const void __user *data, long count)
    4141{
    4242        int offset;
     
    211211int
    212212snd_emu10k1_sample_free(struct snd_emux *rec, struct snd_sf_sample *sp,
    213                         snd_util_memhdr_t *hdr)
     213                        struct snd_util_memhdr *hdr)
    214214{
    215215        struct snd_emu10k1 *emu;
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1_synth.c

    r34 r84  
    2929 * create a new hardware dependent device for Emu10k1
    3030 */
    31 int snd_emu10k1_synth_new_device(snd_seq_device_t *dev)
     31static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
    3232{
    3333        struct snd_emux *emu;
     
    6363        if (snd_emux_register(emu, dev->card, arg->index, "Emu10k1") < 0) {
    6464                snd_emux_free(emu);
    65                 emu->hw = NULL;
    6665                return -ENOMEM;
    6766        }
     
    7776}
    7877
    79 int snd_emu10k1_synth_delete_device(snd_seq_device_t *dev)
     78static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
    8079{
    8180        struct snd_emux *emu;
     
    105104static int __init alsa_emu10k1_synth_init(void)
    106105{
    107        
    108         static snd_seq_dev_ops_t ops = {
     106    static struct snd_seq_dev_ops ops = {
    109107                snd_emu10k1_synth_new_device,
    110108                snd_emu10k1_synth_delete_device,
    111109        };
    112         return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops, sizeof(struct snd_emu10k1_synth_arg));
     110        return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
     111                                              sizeof(struct snd_emu10k1_synth_arg));
    113112}
    114113
  • GPL/trunk/alsa-kernel/pci/emu10k1/emu10k1x.c

    r34 r84  
    6767
    6868#define PTR                     0x00            /* Indexed register set pointer register        */
    69                                                 /* NOTE: The CHANNELNUM and ADDRESS words can   */
    70                                                 /* be modified independently of each other.     */
     69/* NOTE: The CHANNELNUM and ADDRESS words can   */
     70/* be modified independently of each other.     */
    7171
    7272#define DATA                    0x04            /* Indexed register set data register           */
    7373
    7474#define IPR                     0x08            /* Global interrupt pending register            */
    75                                                 /* Clear pending interrupts by writing a 1 to   */
    76                                                 /* the relevant bits and zero to the other bits */
     75/* Clear pending interrupts by writing a 1 to   */
     76/* the relevant bits and zero to the other bits */
    7777#define IPR_MIDITRANSBUFEMPTY   0x00000001      /* MIDI UART transmit buffer empty              */
    7878#define IPR_MIDIRECVBUFEMPTY    0x00000002      /* MIDI UART receive buffer empty               */
     
    9393
    9494#define HCFG_LOCKSOUNDCACHE     0x00000008      /* 1 = Cancel bustmaster accesses to soundcache */
    95                                                 /* NOTE: This should generally never be used.   */
     95/* NOTE: This should generally never be used.   */
    9696#define HCFG_AUDIOENABLE        0x00000001      /* 0 = CODECs transmit zero-valued samples      */
    97                                                 /* Should be set to 1 when the EMU10K1 is       */
    98                                                 /* completely initialized.                      */
     97/* Should be set to 1 when the EMU10K1 is       */
     98/* completely initialized.                      */
    9999#define GPIO                    0x18            /* Defaults: 00001080-Analog, 00001000-SPDIF.   */
    100100
     
    108108/********************************************************************************************************/
    109109#define PLAYBACK_LIST_ADDR      0x00            /* Base DMA address of a list of pointers to each period/size */
    110                                                 /* One list entry: 4 bytes for DMA address,
    111                                                 * 4 bytes for period_size << 16.
    112                                                 * One list entry is 8 bytes long.
    113                                                 * One list entry for each period in the buffer.
    114                                                 */
     110/* One list entry: 4 bytes for DMA address,
     111 * 4 bytes for period_size << 16.
     112 * One list entry is 8 bytes long.
     113 * One list entry for each period in the buffer.
     114 */
    115115#define PLAYBACK_LIST_SIZE      0x01            /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000  */
    116116#define PLAYBACK_LIST_PTR       0x02            /* Pointer to the current period being played */
     
    187187 *  - channel 2 is the center/lfe chanel
    188188 * Volume is controlled by the AC97 for the front and rear channels by
    189  * the PCM Playback Volume, Sigmatel Surround Playback Volume and 
     189 * the PCM Playback Volume, Sigmatel Surround Playback Volume and
    190190 * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
    191191 * the front/rear channel mixing in the REAR OUT jack. When using the
     
    197197
    198198struct emu10k1x_voice {
    199         struct emu10k1x *emu;
    200         int number;
    201         int use;
    202  
    203         struct emu10k1x_pcm *epcm;
     199    struct emu10k1x *emu;
     200    int number;
     201    int use;
     202
     203    struct emu10k1x_pcm *epcm;
    204204};
    205205
    206206struct emu10k1x_pcm {
    207         struct emu10k1x *emu;
    208         struct snd_pcm_substream *substream;
    209         struct emu10k1x_voice *voice;
    210         unsigned short running;
     207    struct emu10k1x *emu;
     208    struct snd_pcm_substream *substream;
     209    struct emu10k1x_voice *voice;
     210    unsigned short running;
    211211};
    212212
    213213struct emu10k1x_midi {
    214         struct emu10k1x *emu;
    215         struct snd_rawmidi *rmidi;
    216         struct snd_rawmidi_substream *substream_input;
    217         struct snd_rawmidi_substream *substream_output;
    218         unsigned int midi_mode;
    219         spinlock_t input_lock;
    220         spinlock_t output_lock;
    221         spinlock_t open_lock;
    222         int tx_enable, rx_enable;
    223         int port;
    224         int ipr_tx, ipr_rx;
    225         void (*interrupt)(struct emu10k1x *emu, unsigned int status);
     214    struct emu10k1x *emu;
     215    struct snd_rawmidi *rmidi;
     216    struct snd_rawmidi_substream *substream_input;
     217    struct snd_rawmidi_substream *substream_output;
     218    unsigned int midi_mode;
     219    spinlock_t input_lock;
     220    spinlock_t output_lock;
     221    spinlock_t open_lock;
     222    int tx_enable, rx_enable;
     223    int port;
     224    int ipr_tx, ipr_rx;
     225    void (*interrupt)(struct emu10k1x *emu, unsigned int status);
    226226};
    227227
    228228// definition of the chip-specific record
    229229struct emu10k1x {
    230         struct snd_card *card;
    231         struct pci_dev *pci;
    232 
    233         unsigned long port;
    234         struct resource *res_port;
    235         int irq;
    236 
    237         unsigned int revision;          /* chip revision */
    238         unsigned int serial;            /* serial number */
    239         unsigned short model;           /* subsystem id */
    240 
    241         spinlock_t emu_lock;
    242         spinlock_t voice_lock;
    243 
    244         struct snd_ac97 *ac97;
    245         struct snd_pcm *pcm;
    246 
    247         struct emu10k1x_voice voices[3];
    248         struct emu10k1x_voice capture_voice;
    249         u32 spdif_bits[3]; // SPDIF out setup
    250 
    251         struct snd_dma_buffer dma_buffer;
    252 
    253         struct emu10k1x_midi midi;
     230    struct snd_card *card;
     231    struct pci_dev *pci;
     232
     233    unsigned long port;
     234    struct resource *res_port;
     235    int irq;
     236
     237    unsigned int revision;              /* chip revision */
     238    unsigned int serial;            /* serial number */
     239    unsigned short model;               /* subsystem id */
     240
     241    spinlock_t emu_lock;
     242    spinlock_t voice_lock;
     243
     244    struct snd_ac97 *ac97;
     245    struct snd_pcm *pcm;
     246
     247    struct emu10k1x_voice voices[3];
     248    struct emu10k1x_voice capture_voice;
     249    u32 spdif_bits[3]; // SPDIF out setup
     250
     251    struct snd_dma_buffer dma_buffer;
     252
     253    struct emu10k1x_midi midi;
    254254};
    255255
    256256/* hardware definition */
    257257static struct snd_pcm_hardware snd_emu10k1x_playback_hw = {
    258         .info =                 (SNDRV_PCM_INFO_MMAP |
    259                                 SNDRV_PCM_INFO_INTERLEAVED |
    260                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    261                                 SNDRV_PCM_INFO_MMAP_VALID),
    262         .formats =              SNDRV_PCM_FMTBIT_S16_LE,
    263         .rates =                SNDRV_PCM_RATE_48000,
    264         .rate_min =             48000,
    265         .rate_max =             48000,
    266         .channels_min =         2,
    267         .channels_max =         2,
    268         .buffer_bytes_max =     (32*1024),
    269         .period_bytes_min =     64,
    270         .period_bytes_max =     (16*1024),
    271         .periods_min =          2,
    272         .periods_max =          8,
    273         .fifo_size =            0,
     258    .info =                     (SNDRV_PCM_INFO_MMAP |
     259                                SNDRV_PCM_INFO_INTERLEAVED |
     260                                SNDRV_PCM_INFO_BLOCK_TRANSFER |
     261                                SNDRV_PCM_INFO_MMAP_VALID),
     262                                 .formats =             SNDRV_PCM_FMTBIT_S16_LE,
     263                                 .rates =               SNDRV_PCM_RATE_48000,
     264                                 .rate_min =            48000,
     265                                 .rate_max =            48000,
     266                                 .channels_min =                2,
     267                                 .channels_max =                2,
     268                                 .buffer_bytes_max =    (32*1024),
     269                                 .period_bytes_min =    64,
     270                                 .period_bytes_max =    (16*1024),
     271                                 .periods_min =         2,
     272                                 .periods_max =         8,
     273                                 .fifo_size =           0,
    274274};
    275275
    276276static struct snd_pcm_hardware snd_emu10k1x_capture_hw = {
    277         .info =                 (SNDRV_PCM_INFO_MMAP |
    278                                 SNDRV_PCM_INFO_INTERLEAVED |
    279                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    280                                 SNDRV_PCM_INFO_MMAP_VALID),
    281         .formats =              SNDRV_PCM_FMTBIT_S16_LE,
    282         .rates =                SNDRV_PCM_RATE_48000,
    283         .rate_min =             48000,
    284         .rate_max =             48000,
    285         .channels_min =         2,
    286         .channels_max =         2,
    287         .buffer_bytes_max =     (32*1024),
    288         .period_bytes_min =     64,
    289         .period_bytes_max =     (16*1024),
    290         .periods_min =          2,
    291         .periods_max =          2,
    292         .fifo_size =            0,
     277    .info =                     (SNDRV_PCM_INFO_MMAP |
     278                                SNDRV_PCM_INFO_INTERLEAVED |
     279                                SNDRV_PCM_INFO_BLOCK_TRANSFER |
     280                                SNDRV_PCM_INFO_MMAP_VALID),
     281                                 .formats =             SNDRV_PCM_FMTBIT_S16_LE,
     282                                 .rates =               SNDRV_PCM_RATE_48000,
     283                                 .rate_min =            48000,
     284                                 .rate_max =            48000,
     285                                 .channels_min =                2,
     286                                 .channels_max =                2,
     287                                 .buffer_bytes_max =    (32*1024),
     288                                 .period_bytes_min =    64,
     289                                 .period_bytes_max =    (16*1024),
     290                                 .periods_min =         2,
     291                                 .periods_max =         2,
     292                                 .fifo_size =           0,
    293293};
    294294
    295 static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu, 
    296                                           unsigned int reg,
    297                                           unsigned int chn)
    298 {
    299         unsigned long flags;
    300         unsigned int regptr, val;
    301  
    302         regptr = (reg << 16) | chn;
    303 
    304         spin_lock_irqsave(&emu->emu_lock, flags);
    305         outl(regptr, emu->port + PTR);
    306         val = inl(emu->port + DATA);
    307         spin_unlock_irqrestore(&emu->emu_lock, flags);
    308         return val;
    309 }
    310 
    311 static void snd_emu10k1x_ptr_write(struct emu10k1x *emu, 
    312                                    unsigned int reg,
    313                                    unsigned int chn,
    314                                    unsigned int data)
    315 {
    316         unsigned int regptr;
    317         unsigned long flags;
    318 
    319         regptr = (reg << 16) | chn;
    320 
    321         spin_lock_irqsave(&emu->emu_lock, flags);
    322         outl(regptr, emu->port + PTR);
    323         outl(data, emu->port + DATA);
    324         spin_unlock_irqrestore(&emu->emu_lock, flags);
     295static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu,
     296                                          unsigned int reg,
     297                                          unsigned int chn)
     298{
     299    unsigned long flags;
     300    unsigned int regptr, val;
     301
     302    regptr = (reg << 16) | chn;
     303
     304    spin_lock_irqsave(&emu->emu_lock, flags);
     305    outl(regptr, emu->port + PTR);
     306    val = inl(emu->port + DATA);
     307    spin_unlock_irqrestore(&emu->emu_lock, flags);
     308    return val;
     309}
     310
     311static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
     312                                   unsigned int reg,
     313                                   unsigned int chn,
     314                                   unsigned int data)
     315{
     316    unsigned int regptr;
     317    unsigned long flags;
     318
     319    regptr = (reg << 16) | chn;
     320
     321    spin_lock_irqsave(&emu->emu_lock, flags);
     322    outl(regptr, emu->port + PTR);
     323    outl(data, emu->port + DATA);
     324    spin_unlock_irqrestore(&emu->emu_lock, flags);
    325325}
    326326
    327327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
    328328{
    329         unsigned long flags;
    330         unsigned int enable;
    331  
    332         spin_lock_irqsave(&emu->emu_lock, flags);
    333         enable = inl(emu->port + INTE) | intrenb;
    334         outl(enable, emu->port + INTE);
    335         spin_unlock_irqrestore(&emu->emu_lock, flags);
     329    unsigned long flags;
     330    unsigned int enable;
     331
     332    spin_lock_irqsave(&emu->emu_lock, flags);
     333    enable = inl(emu->port + INTE) | intrenb;
     334    outl(enable, emu->port + INTE);
     335    spin_unlock_irqrestore(&emu->emu_lock, flags);
    336336}
    337337
    338338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
    339339{
    340         unsigned long flags;
    341         unsigned int enable;
    342  
    343         spin_lock_irqsave(&emu->emu_lock, flags);
    344         enable = inl(emu->port + INTE) & ~intrenb;
    345         outl(enable, emu->port + INTE);
    346         spin_unlock_irqrestore(&emu->emu_lock, flags);
     340    unsigned long flags;
     341    unsigned int enable;
     342
     343    spin_lock_irqsave(&emu->emu_lock, flags);
     344    enable = inl(emu->port + INTE) & ~intrenb;
     345    outl(enable, emu->port + INTE);
     346    spin_unlock_irqrestore(&emu->emu_lock, flags);
    347347}
    348348
    349349static void snd_emu10k1x_gpio_write(struct emu10k1x *emu, unsigned int value)
    350350{
    351         unsigned long flags;
    352 
    353         spin_lock_irqsave(&emu->emu_lock, flags);
    354         outl(value, emu->port + GPIO);
    355         spin_unlock_irqrestore(&emu->emu_lock, flags);
     351    unsigned long flags;
     352
     353    spin_lock_irqsave(&emu->emu_lock, flags);
     354    outl(value, emu->port + GPIO);
     355    spin_unlock_irqrestore(&emu->emu_lock, flags);
    356356}
    357357
    358358static void snd_emu10k1x_pcm_free_substream(struct snd_pcm_runtime *runtime)
    359359{
    360         kfree(runtime->private_data);
     360    kfree(runtime->private_data);
    361361}
    362362
    363363static void snd_emu10k1x_pcm_interrupt(struct emu10k1x *emu, struct emu10k1x_voice *voice)
    364364{
    365         struct emu10k1x_pcm *epcm;
    366 
    367         if ((epcm = voice->epcm) == NULL)
    368                 return;
    369         if (epcm->substream == NULL)
    370                 return;
     365    struct emu10k1x_pcm *epcm;
     366
     367    if ((epcm = voice->epcm) == NULL)
     368        return;
     369    if (epcm->substream == NULL)
     370        return;
    371371#if 0
    372         snd_printk(KERN_INFO "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
    373                    epcm->substream->ops->pointer(epcm->substream),
    374                    snd_pcm_lib_period_bytes(epcm->substream),
    375                    snd_pcm_lib_buffer_bytes(epcm->substream));
     372    snd_printk(KERN_INFO "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
     373               epcm->substream->ops->pointer(epcm->substream),
     374               snd_pcm_lib_period_bytes(epcm->substream),
     375               snd_pcm_lib_buffer_bytes(epcm->substream));
    376376#endif
    377         snd_pcm_period_elapsed(epcm->substream);
     377    snd_pcm_period_elapsed(epcm->substream);
    378378}
    379379
     
    381381static int snd_emu10k1x_playback_open(struct snd_pcm_substream *substream)
    382382{
    383         struct emu10k1x *chip = snd_pcm_substream_chip(substream);
    384         struct emu10k1x_pcm *epcm;
    385         struct snd_pcm_runtime *runtime = substream->runtime;
    386         int err;
    387 
    388         if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
    389                 return err;
    390         }
    391         if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
    392                 return err;
    393 
    394         epcm = (struct emu10k1x_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    395         if (epcm == NULL)
    396                 return -ENOMEM;
    397         epcm->emu = chip;
    398         epcm->substream = substream;
    399  
    400         runtime->private_data = epcm;
    401         runtime->private_free = snd_emu10k1x_pcm_free_substream;
    402  
    403         runtime->hw = snd_emu10k1x_playback_hw;
    404 
    405         return 0;
     383    struct emu10k1x *chip = snd_pcm_substream_chip(substream);
     384    struct emu10k1x_pcm *epcm;
     385    struct snd_pcm_runtime *runtime = substream->runtime;
     386    int err;
     387
     388    if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
     389        return err;
     390    }
     391    if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
     392        return err;
     393
     394    epcm = (struct emu10k1x_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
     395    if (epcm == NULL)
     396        return -ENOMEM;
     397    epcm->emu = chip;
     398    epcm->substream = substream;
     399
     400    runtime->private_data = epcm;
     401    runtime->private_free = snd_emu10k1x_pcm_free_substream;
     402
     403    runtime->hw = snd_emu10k1x_playback_hw;
     404
     405    return 0;
    406406}
    407407
     
    409409static int snd_emu10k1x_playback_close(struct snd_pcm_substream *substream)
    410410{
    411         return 0;
     411    return 0;
    412412}
    413413
    414414/* hw_params callback */
    415415static int snd_emu10k1x_pcm_hw_params(struct snd_pcm_substream *substream,
    416                                       struct snd_pcm_hw_params *hw_params)
    417 {
    418         struct snd_pcm_runtime *runtime = substream->runtime;
    419         struct emu10k1x_pcm *epcm = runtime->private_data;
    420 
    421         if (! epcm->voice) {
    422                 epcm->voice = &epcm->emu->voices[substream->pcm->device];
    423                 epcm->voice->use = 1;
    424                 epcm->voice->epcm = epcm;
    425         }
    426 
    427         return snd_pcm_lib_malloc_pages(substream,
    428                                         params_buffer_bytes(hw_params));
     416                                      struct snd_pcm_hw_params *hw_params)
     417{
     418    struct snd_pcm_runtime *runtime = substream->runtime;
     419    struct emu10k1x_pcm *epcm = runtime->private_data;
     420
     421    if (! epcm->voice) {
     422        epcm->voice = &epcm->emu->voices[substream->pcm->device];
     423        epcm->voice->use = 1;
     424        epcm->voice->epcm = epcm;
     425    }
     426
     427    return snd_pcm_lib_malloc_pages(substream,
     428                                    params_buffer_bytes(hw_params));
    429429}
    430430
     
    432432static int snd_emu10k1x_pcm_hw_free(struct snd_pcm_substream *substream)
    433433{
    434         struct snd_pcm_runtime *runtime = substream->runtime;
    435         struct emu10k1x_pcm *epcm;
    436 
    437         if (runtime->private_data == NULL)
    438                 return 0;
    439        
    440         epcm = runtime->private_data;
    441 
    442         if (epcm->voice) {
    443                 epcm->voice->use = 0;
    444                 epcm->voice->epcm = NULL;
    445                 epcm->voice = NULL;
    446         }
    447 
    448         return snd_pcm_lib_free_pages(substream);
     434    struct snd_pcm_runtime *runtime = substream->runtime;
     435    struct emu10k1x_pcm *epcm;
     436
     437    if (runtime->private_data == NULL)
     438        return 0;
     439
     440    epcm = runtime->private_data;
     441
     442    if (epcm->voice) {
     443        epcm->voice->use = 0;
     444        epcm->voice->epcm = NULL;
     445        epcm->voice = NULL;
     446    }
     447
     448    return snd_pcm_lib_free_pages(substream);
    449449}
    450450
     
    452452static int snd_emu10k1x_pcm_prepare(struct snd_pcm_substream *substream)
    453453{
    454         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    455         struct snd_pcm_runtime *runtime = substream->runtime;
    456         struct emu10k1x_pcm *epcm = runtime->private_data;
    457         int voice = epcm->voice->number;
    458         u32 *table_base = (u32 *)(emu->dma_buffer.area+1024*voice);
    459         u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
    460         int i;
    461        
    462         for(i=0; i < runtime->periods; i++) {
    463                 *table_base++=runtime->dma_addr+(i*period_size_bytes);
    464                 *table_base++=period_size_bytes<<16;
    465         }
    466 
    467         snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_ADDR, voice, emu->dma_buffer.addr+1024*voice);
    468         snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_SIZE, voice, (runtime->periods - 1) << 19);
    469         snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_PTR, voice, 0);
    470         snd_emu10k1x_ptr_write(emu, PLAYBACK_POINTER, voice, 0);
    471         snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN1, voice, 0);
    472         snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN2, voice, 0);
    473         snd_emu10k1x_ptr_write(emu, PLAYBACK_DMA_ADDR, voice, runtime->dma_addr);
    474 
    475         snd_emu10k1x_ptr_write(emu, PLAYBACK_PERIOD_SIZE, voice, frames_to_bytes(runtime, runtime->period_size)<<16);
    476 
    477         return 0;
     454    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     455    struct snd_pcm_runtime *runtime = substream->runtime;
     456    struct emu10k1x_pcm *epcm = runtime->private_data;
     457    int voice = epcm->voice->number;
     458    u32 *table_base = (u32 *)(emu->dma_buffer.area+1024*voice);
     459    u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
     460    int i;
     461
     462    for(i=0; i < runtime->periods; i++) {
     463        *table_base++=runtime->dma_addr+(i*period_size_bytes);
     464        *table_base++=period_size_bytes<<16;
     465    }
     466
     467    snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_ADDR, voice, emu->dma_buffer.addr+1024*voice);
     468    snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_SIZE, voice, (runtime->periods - 1) << 19);
     469    snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_PTR, voice, 0);
     470    snd_emu10k1x_ptr_write(emu, PLAYBACK_POINTER, voice, 0);
     471    snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN1, voice, 0);
     472    snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN2, voice, 0);
     473    snd_emu10k1x_ptr_write(emu, PLAYBACK_DMA_ADDR, voice, runtime->dma_addr);
     474
     475    snd_emu10k1x_ptr_write(emu, PLAYBACK_PERIOD_SIZE, voice, frames_to_bytes(runtime, runtime->period_size)<<16);
     476
     477    return 0;
    478478}
    479479
    480480/* trigger callback */
    481481static int snd_emu10k1x_pcm_trigger(struct snd_pcm_substream *substream,
    482                                     int cmd)
    483 {
    484         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    485         struct snd_pcm_runtime *runtime = substream->runtime;
    486         struct emu10k1x_pcm *epcm = runtime->private_data;
    487         int channel = epcm->voice->number;
    488         int result = 0;
    489 
    490 //      snd_printk(KERN_INFO "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream));
    491 
    492         switch (cmd) {
    493         case SNDRV_PCM_TRIGGER_START:
    494                 if(runtime->periods == 2)
    495                         snd_emu10k1x_intr_enable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
    496                 else
    497                         snd_emu10k1x_intr_enable(emu, INTE_CH_0_LOOP << channel);
    498                 epcm->running = 1;
    499                 snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|(TRIGGER_CHANNEL_0<<channel));
    500                 break;
    501         case SNDRV_PCM_TRIGGER_STOP:
    502                 epcm->running = 0;
    503                 snd_emu10k1x_intr_disable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
    504                 snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CHANNEL_0<<channel));
    505                 break;
    506         default:
    507                 result = -EINVAL;
    508                 break;
    509         }
    510         return result;
     482                                    int cmd)
     483{
     484    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     485    struct snd_pcm_runtime *runtime = substream->runtime;
     486    struct emu10k1x_pcm *epcm = runtime->private_data;
     487    int channel = epcm->voice->number;
     488    int result = 0;
     489
     490    //  snd_printk(KERN_INFO "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream));
     491
     492    switch (cmd) {
     493    case SNDRV_PCM_TRIGGER_START:
     494        if(runtime->periods == 2)
     495            snd_emu10k1x_intr_enable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
     496        else
     497            snd_emu10k1x_intr_enable(emu, INTE_CH_0_LOOP << channel);
     498        epcm->running = 1;
     499        snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|(TRIGGER_CHANNEL_0<<channel));
     500        break;
     501    case SNDRV_PCM_TRIGGER_STOP:
     502        epcm->running = 0;
     503        snd_emu10k1x_intr_disable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
     504        snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CHANNEL_0<<channel));
     505        break;
     506    default:
     507        result = -EINVAL;
     508        break;
     509    }
     510    return result;
    511511}
    512512
     
    515515snd_emu10k1x_pcm_pointer(struct snd_pcm_substream *substream)
    516516{
    517         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    518         struct snd_pcm_runtime *runtime = substream->runtime;
    519         struct emu10k1x_pcm *epcm = runtime->private_data;
    520         int channel = epcm->voice->number;
    521         snd_pcm_uframes_t ptr = 0, ptr1 = 0, ptr2= 0,ptr3 = 0,ptr4 = 0;
    522 
    523         if (!epcm->running)
    524                 return 0;
    525 
    526         ptr3 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
    527         ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
    528         ptr4 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
    529 
    530         if(ptr4 == 0 && ptr1 == frames_to_bytes(runtime, runtime->buffer_size))
    531                 return 0;
    532        
    533         if (ptr3 != ptr4)
    534                 ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
    535         ptr2 = bytes_to_frames(runtime, ptr1);
    536         ptr2 += (ptr4 >> 3) * runtime->period_size;
    537         ptr = ptr2;
    538 
    539         if (ptr >= runtime->buffer_size)
    540                 ptr -= runtime->buffer_size;
    541 
    542         return ptr;
     517    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     518    struct snd_pcm_runtime *runtime = substream->runtime;
     519    struct emu10k1x_pcm *epcm = runtime->private_data;
     520    int channel = epcm->voice->number;
     521    snd_pcm_uframes_t ptr = 0, ptr1 = 0, ptr2= 0,ptr3 = 0,ptr4 = 0;
     522
     523    if (!epcm->running)
     524        return 0;
     525
     526    ptr3 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
     527    ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
     528    ptr4 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
     529
     530    if(ptr4 == 0 && ptr1 == frames_to_bytes(runtime, runtime->buffer_size))
     531        return 0;
     532
     533    if (ptr3 != ptr4)
     534        ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
     535    ptr2 = bytes_to_frames(runtime, ptr1);
     536    ptr2 += (ptr4 >> 3) * runtime->period_size;
     537    ptr = ptr2;
     538
     539    if (ptr >= runtime->buffer_size)
     540        ptr -= runtime->buffer_size;
     541
     542    return ptr;
    543543}
    544544
    545545/* operators */
    546546static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
    547         .open =        snd_emu10k1x_playback_open,
    548         .close =       snd_emu10k1x_playback_close,
    549         .ioctl =       snd_pcm_lib_ioctl,
    550         .hw_params =   snd_emu10k1x_pcm_hw_params,
    551         .hw_free =     snd_emu10k1x_pcm_hw_free,
    552         .prepare =     snd_emu10k1x_pcm_prepare,
    553         .trigger =     snd_emu10k1x_pcm_trigger,
    554         .pointer =     snd_emu10k1x_pcm_pointer,
     547    .open =        snd_emu10k1x_playback_open,
     548    .close =       snd_emu10k1x_playback_close,
     549    .ioctl =       snd_pcm_lib_ioctl,
     550    .hw_params =   snd_emu10k1x_pcm_hw_params,
     551    .hw_free =     snd_emu10k1x_pcm_hw_free,
     552    .prepare =     snd_emu10k1x_pcm_prepare,
     553    .trigger =     snd_emu10k1x_pcm_trigger,
     554    .pointer =     snd_emu10k1x_pcm_pointer,
    555555};
    556556
     
    558558static int snd_emu10k1x_pcm_open_capture(struct snd_pcm_substream *substream)
    559559{
    560         struct emu10k1x *chip = snd_pcm_substream_chip(substream);
    561         struct emu10k1x_pcm *epcm;
    562         struct snd_pcm_runtime *runtime = substream->runtime;
    563         int err;
    564 
    565         if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
    566                 return err;
    567         if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
    568                 return err;
    569 
    570         epcm = (struct emu10k1x_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    571         if (epcm == NULL)
    572                 return -ENOMEM;
    573 
    574         epcm->emu = chip;
    575         epcm->substream = substream;
    576 
    577         runtime->private_data = epcm;
    578         runtime->private_free = snd_emu10k1x_pcm_free_substream;
    579 
    580         runtime->hw = snd_emu10k1x_capture_hw;
    581 
    582         return 0;
     560    struct emu10k1x *chip = snd_pcm_substream_chip(substream);
     561    struct emu10k1x_pcm *epcm;
     562    struct snd_pcm_runtime *runtime = substream->runtime;
     563    int err;
     564
     565    if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
     566        return err;
     567    if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
     568        return err;
     569
     570    epcm = (struct emu10k1x_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
     571    if (epcm == NULL)
     572        return -ENOMEM;
     573
     574    epcm->emu = chip;
     575    epcm->substream = substream;
     576
     577    runtime->private_data = epcm;
     578    runtime->private_free = snd_emu10k1x_pcm_free_substream;
     579
     580    runtime->hw = snd_emu10k1x_capture_hw;
     581
     582    return 0;
    583583}
    584584
     
    586586static int snd_emu10k1x_pcm_close_capture(struct snd_pcm_substream *substream)
    587587{
    588         return 0;
     588    return 0;
    589589}
    590590
    591591/* hw_params callback */
    592592static int snd_emu10k1x_pcm_hw_params_capture(struct snd_pcm_substream *substream,
    593                                               struct snd_pcm_hw_params *hw_params)
    594 {
    595         struct snd_pcm_runtime *runtime = substream->runtime;
    596         struct emu10k1x_pcm *epcm = runtime->private_data;
    597 
    598         if (! epcm->voice) {
    599                 if (epcm->emu->capture_voice.use)
    600                         return -EBUSY;
    601                 epcm->voice = &epcm->emu->capture_voice;
    602                 epcm->voice->epcm = epcm;
    603                 epcm->voice->use = 1;
    604         }
    605 
    606         return snd_pcm_lib_malloc_pages(substream,
    607                                         params_buffer_bytes(hw_params));
     593                                              struct snd_pcm_hw_params *hw_params)
     594{
     595    struct snd_pcm_runtime *runtime = substream->runtime;
     596    struct emu10k1x_pcm *epcm = runtime->private_data;
     597
     598    if (! epcm->voice) {
     599        if (epcm->emu->capture_voice.use)
     600            return -EBUSY;
     601        epcm->voice = &epcm->emu->capture_voice;
     602        epcm->voice->epcm = epcm;
     603        epcm->voice->use = 1;
     604    }
     605
     606    return snd_pcm_lib_malloc_pages(substream,
     607                                    params_buffer_bytes(hw_params));
    608608}
    609609
     
    611611static int snd_emu10k1x_pcm_hw_free_capture(struct snd_pcm_substream *substream)
    612612{
    613         struct snd_pcm_runtime *runtime = substream->runtime;
    614 
    615         struct emu10k1x_pcm *epcm;
    616 
    617         if (runtime->private_data == NULL)
    618                 return 0;
    619         epcm = runtime->private_data;
    620 
    621         if (epcm->voice) {
    622                 epcm->voice->use = 0;
    623                 epcm->voice->epcm = NULL;
    624                 epcm->voice = NULL;
    625         }
    626 
    627         return snd_pcm_lib_free_pages(substream);
     613    struct snd_pcm_runtime *runtime = substream->runtime;
     614
     615    struct emu10k1x_pcm *epcm;
     616
     617    if (runtime->private_data == NULL)
     618        return 0;
     619    epcm = runtime->private_data;
     620
     621    if (epcm->voice) {
     622        epcm->voice->use = 0;
     623        epcm->voice->epcm = NULL;
     624        epcm->voice = NULL;
     625    }
     626
     627    return snd_pcm_lib_free_pages(substream);
    628628}
    629629
     
    631631static int snd_emu10k1x_pcm_prepare_capture(struct snd_pcm_substream *substream)
    632632{
    633         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    634         struct snd_pcm_runtime *runtime = substream->runtime;
    635 
    636         snd_emu10k1x_ptr_write(emu, CAPTURE_DMA_ADDR, 0, runtime->dma_addr);
    637         snd_emu10k1x_ptr_write(emu, CAPTURE_BUFFER_SIZE, 0, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
    638         snd_emu10k1x_ptr_write(emu, CAPTURE_POINTER, 0, 0);
    639         snd_emu10k1x_ptr_write(emu, CAPTURE_UNKNOWN, 0, 0);
    640 
    641         return 0;
     633    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     634    struct snd_pcm_runtime *runtime = substream->runtime;
     635
     636    snd_emu10k1x_ptr_write(emu, CAPTURE_DMA_ADDR, 0, runtime->dma_addr);
     637    snd_emu10k1x_ptr_write(emu, CAPTURE_BUFFER_SIZE, 0, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
     638    snd_emu10k1x_ptr_write(emu, CAPTURE_POINTER, 0, 0);
     639    snd_emu10k1x_ptr_write(emu, CAPTURE_UNKNOWN, 0, 0);
     640
     641    return 0;
    642642}
    643643
    644644/* trigger_capture callback */
    645645static int snd_emu10k1x_pcm_trigger_capture(struct snd_pcm_substream *substream,
    646                                             int cmd)
    647 {
    648         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    649         struct snd_pcm_runtime *runtime = substream->runtime;
    650         struct emu10k1x_pcm *epcm = runtime->private_data;
    651         int result = 0;
    652 
    653         switch (cmd) {
    654         case SNDRV_PCM_TRIGGER_START:
    655                 snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP |
    656                                         INTE_CAP_0_HALF_LOOP);
    657                 snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|TRIGGER_CAPTURE);
    658                 epcm->running = 1;
    659                 break;
    660         case SNDRV_PCM_TRIGGER_STOP:
    661                 epcm->running = 0;
    662                 snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP |
    663                                           INTE_CAP_0_HALF_LOOP);
    664                 snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CAPTURE));
    665                 break;
    666         default:
    667                 result = -EINVAL;
    668                 break;
    669         }
    670         return result;
     646                                            int cmd)
     647{
     648    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     649    struct snd_pcm_runtime *runtime = substream->runtime;
     650    struct emu10k1x_pcm *epcm = runtime->private_data;
     651    int result = 0;
     652
     653    switch (cmd) {
     654    case SNDRV_PCM_TRIGGER_START:
     655        snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP |
     656                                INTE_CAP_0_HALF_LOOP);
     657        snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|TRIGGER_CAPTURE);
     658        epcm->running = 1;
     659        break;
     660    case SNDRV_PCM_TRIGGER_STOP:
     661        epcm->running = 0;
     662        snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP |
     663                                  INTE_CAP_0_HALF_LOOP);
     664        snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CAPTURE));
     665        break;
     666    default:
     667        result = -EINVAL;
     668        break;
     669    }
     670    return result;
    671671}
    672672
     
    675675snd_emu10k1x_pcm_pointer_capture(struct snd_pcm_substream *substream)
    676676{
    677         struct emu10k1x *emu = snd_pcm_substream_chip(substream);
    678         struct snd_pcm_runtime *runtime = substream->runtime;
    679         struct emu10k1x_pcm *epcm = runtime->private_data;
    680         snd_pcm_uframes_t ptr;
    681 
    682         if (!epcm->running)
    683                 return 0;
    684 
    685         ptr = bytes_to_frames(runtime, snd_emu10k1x_ptr_read(emu, CAPTURE_POINTER, 0));
    686         if (ptr >= runtime->buffer_size)
    687                 ptr -= runtime->buffer_size;
    688 
    689         return ptr;
     677    struct emu10k1x *emu = snd_pcm_substream_chip(substream);
     678    struct snd_pcm_runtime *runtime = substream->runtime;
     679    struct emu10k1x_pcm *epcm = runtime->private_data;
     680    snd_pcm_uframes_t ptr;
     681
     682    if (!epcm->running)
     683        return 0;
     684
     685    ptr = bytes_to_frames(runtime, snd_emu10k1x_ptr_read(emu, CAPTURE_POINTER, 0));
     686    if (ptr >= runtime->buffer_size)
     687        ptr -= runtime->buffer_size;
     688
     689    return ptr;
    690690}
    691691
    692692static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
    693         .open =        snd_emu10k1x_pcm_open_capture,
    694         .close =       snd_emu10k1x_pcm_close_capture,
    695         .ioctl =       snd_pcm_lib_ioctl,
    696         .hw_params =   snd_emu10k1x_pcm_hw_params_capture,
    697         .hw_free =     snd_emu10k1x_pcm_hw_free_capture,
    698         .prepare =     snd_emu10k1x_pcm_prepare_capture,
    699         .trigger =     snd_emu10k1x_pcm_trigger_capture,
    700         .pointer =     snd_emu10k1x_pcm_pointer_capture,
     693    .open =        snd_emu10k1x_pcm_open_capture,
     694    .close =       snd_emu10k1x_pcm_close_capture,
     695    .ioctl =       snd_pcm_lib_ioctl,
     696    .hw_params =   snd_emu10k1x_pcm_hw_params_capture,
     697    .hw_free =     snd_emu10k1x_pcm_hw_free_capture,
     698    .prepare =     snd_emu10k1x_pcm_prepare_capture,
     699    .trigger =     snd_emu10k1x_pcm_trigger_capture,
     700    .pointer =     snd_emu10k1x_pcm_pointer_capture,
    701701};
    702702
    703703static unsigned short snd_emu10k1x_ac97_read(struct snd_ac97 *ac97,
    704                                              unsigned short reg)
    705 {
    706         struct emu10k1x *emu = ac97->private_data;
    707         unsigned long flags;
    708         unsigned short val;
    709  
    710         spin_lock_irqsave(&emu->emu_lock, flags);
    711         outb(reg, emu->port + AC97ADDRESS);
    712         val = inw(emu->port + AC97DATA);
    713         spin_unlock_irqrestore(&emu->emu_lock, flags);
    714         return val;
     704                                             unsigned short reg)
     705{
     706    struct emu10k1x *emu = ac97->private_data;
     707    unsigned long flags;
     708    unsigned short val;
     709
     710    spin_lock_irqsave(&emu->emu_lock, flags);
     711    outb(reg, emu->port + AC97ADDRESS);
     712    val = inw(emu->port + AC97DATA);
     713    spin_unlock_irqrestore(&emu->emu_lock, flags);
     714    return val;
    715715}
    716716
    717717static void snd_emu10k1x_ac97_write(struct snd_ac97 *ac97,
    718                                     unsigned short reg, unsigned short val)
    719 {
    720         struct emu10k1x *emu = ac97->private_data;
    721         unsigned long flags;
    722  
    723         spin_lock_irqsave(&emu->emu_lock, flags);
    724         outb(reg, emu->port + AC97ADDRESS);
    725         outw(val, emu->port + AC97DATA);
    726         spin_unlock_irqrestore(&emu->emu_lock, flags);
     718                                    unsigned short reg, unsigned short val)
     719{
     720    struct emu10k1x *emu = ac97->private_data;
     721    unsigned long flags;
     722
     723    spin_lock_irqsave(&emu->emu_lock, flags);
     724    outb(reg, emu->port + AC97ADDRESS);
     725    outw(val, emu->port + AC97DATA);
     726    spin_unlock_irqrestore(&emu->emu_lock, flags);
    727727}
    728728
    729729static int snd_emu10k1x_ac97(struct emu10k1x *chip)
    730730{
    731         struct snd_ac97_bus *pbus;
    732         struct snd_ac97_template ac97;
    733         int err;
    734         static struct snd_ac97_bus_ops ops = {
    735                 .write = snd_emu10k1x_ac97_write,
    736                 .read = snd_emu10k1x_ac97_read,
    737         };
    738  
    739         if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
    740                 return err;
    741         pbus->no_vra = 1; /* we don't need VRA */
    742 
    743         memset(&ac97, 0, sizeof(ac97));
    744         ac97.private_data = chip;
    745         ac97.scaps = AC97_SCAP_NO_SPDIF;
    746         return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
     731    struct snd_ac97_bus *pbus;
     732    struct snd_ac97_template ac97;
     733    int err;
     734    static struct snd_ac97_bus_ops ops = {
     735        .write = snd_emu10k1x_ac97_write,
     736        .read = snd_emu10k1x_ac97_read,
     737    };
     738
     739    if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
     740        return err;
     741    pbus->no_vra = 1; /* we don't need VRA */
     742
     743    memset(&ac97, 0, sizeof(ac97));
     744    ac97.private_data = chip;
     745    ac97.scaps = AC97_SCAP_NO_SPDIF;
     746    return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
    747747}
    748748
    749749static int snd_emu10k1x_free(struct emu10k1x *chip)
    750750{
    751         snd_emu10k1x_ptr_write(chip, TRIGGER_CHANNEL, 0, 0);
    752         // disable interrupts
    753         outl(0, chip->port + INTE);
    754         // disable audio
    755         outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
    756 
    757         // release the i/o port
    758         release_and_free_resource(chip->res_port);
    759 
    760         // release the irq
    761         if (chip->irq >= 0)
    762                 free_irq(chip->irq, (void *)chip);
    763 
    764         // release the DMA
    765         if (chip->dma_buffer.area) {
    766                 snd_dma_free_pages(&chip->dma_buffer);
    767         }
    768 
    769         pci_disable_device(chip->pci);
    770 
    771         // release the data
    772         kfree(chip);
    773         return 0;
     751    snd_emu10k1x_ptr_write(chip, TRIGGER_CHANNEL, 0, 0);
     752    // disable interrupts
     753    outl(0, chip->port + INTE);
     754    // disable audio
     755    outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
     756
     757    // release the i/o port
     758    release_and_free_resource(chip->res_port);
     759
     760    // release the irq
     761    if (chip->irq >= 0)
     762        free_irq(chip->irq, (void *)chip);
     763
     764    // release the DMA
     765    if (chip->dma_buffer.area) {
     766        snd_dma_free_pages(&chip->dma_buffer);
     767    }
     768
     769    pci_disable_device(chip->pci);
     770
     771    // release the data
     772    kfree(chip);
     773    return 0;
    774774}
    775775
    776776static int snd_emu10k1x_dev_free(struct snd_device *device)
    777777{
    778         struct emu10k1x *chip = device->device_data;
    779         return snd_emu10k1x_free(chip);
    780 }
    781 
    782 static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id,
    783                                           struct pt_regs *regs)
    784 {
    785         unsigned int status;
    786 
    787         struct emu10k1x *chip = dev_id;
    788         struct emu10k1x_voice *pvoice = chip->voices;
    789         int i;
    790         int mask;
    791 
    792         status = inl(chip->port + IPR);
    793 
    794         if (! status)
    795                 return IRQ_NONE;
    796 
    797         // capture interrupt
    798         if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
    799                 struct emu10k1x_voice *pvoice = &chip->capture_voice;
    800                 if (pvoice->use)
    801                         snd_emu10k1x_pcm_interrupt(chip, pvoice);
    802                 else
    803                         snd_emu10k1x_intr_disable(chip,
    804                                                   INTE_CAP_0_LOOP |
    805                                                   INTE_CAP_0_HALF_LOOP);
    806         }
    807                
    808         mask = IPR_CH_0_LOOP|IPR_CH_0_HALF_LOOP;
    809         for (i = 0; i < 3; i++) {
    810                 if (status & mask) {
    811                         if (pvoice->use)
    812                                 snd_emu10k1x_pcm_interrupt(chip, pvoice);
    813                         else
    814                                 snd_emu10k1x_intr_disable(chip, mask);
    815                 }
    816                 pvoice++;
    817                 mask <<= 1;
    818         }
    819                
    820         if (status & (IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY)) {
    821                 if (chip->midi.interrupt)
    822                         chip->midi.interrupt(chip, status);
    823                 else
    824                         snd_emu10k1x_intr_disable(chip, INTE_MIDITXENABLE|INTE_MIDIRXENABLE);
    825         }
    826                
    827         // acknowledge the interrupt if necessary
    828         outl(status, chip->port + IPR);
    829 
    830         // snd_printk(KERN_INFO "interrupt %08x\n", status);
    831         return IRQ_HANDLED;
     778    struct emu10k1x *chip = device->device_data;
     779    return snd_emu10k1x_free(chip);
     780}
     781
     782static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
     783{
     784    unsigned int status;
     785
     786    struct emu10k1x *chip = dev_id;
     787    struct emu10k1x_voice *pvoice = chip->voices;
     788    int i;
     789    int mask;
     790
     791    status = inl(chip->port + IPR);
     792
     793    if (! status)
     794        return IRQ_NONE;
     795
     796    // capture interrupt
     797    if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
     798        struct emu10k1x_voice *pvoice = &chip->capture_voice;
     799        if (pvoice->use)
     800            snd_emu10k1x_pcm_interrupt(chip, pvoice);
     801        else
     802            snd_emu10k1x_intr_disable(chip,
     803                                      INTE_CAP_0_LOOP |
     804                                      INTE_CAP_0_HALF_LOOP);
     805    }
     806
     807    mask = IPR_CH_0_LOOP|IPR_CH_0_HALF_LOOP;
     808    for (i = 0; i < 3; i++) {
     809        if (status & mask) {
     810            if (pvoice->use)
     811                snd_emu10k1x_pcm_interrupt(chip, pvoice);
     812            else
     813                snd_emu10k1x_intr_disable(chip, mask);
     814        }
     815        pvoice++;
     816        mask <<= 1;
     817    }
     818
     819    if (status & (IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY)) {
     820        if (chip->midi.interrupt)
     821            chip->midi.interrupt(chip, status);
     822        else
     823            snd_emu10k1x_intr_disable(chip, INTE_MIDITXENABLE|INTE_MIDIRXENABLE);
     824    }
     825
     826    // acknowledge the interrupt if necessary
     827    outl(status, chip->port + IPR);
     828
     829    // snd_printk(KERN_INFO "interrupt %08x\n", status);
     830    return IRQ_HANDLED;
    832831}
    833832
    834833static int __devinit snd_emu10k1x_pcm(struct emu10k1x *emu, int device, struct snd_pcm **rpcm)
    835834{
    836         struct snd_pcm *pcm;
    837         int err;
    838         int capture = 0;
    839  
    840         if (rpcm)
    841                 *rpcm = NULL;
    842         if (device == 0)
    843                 capture = 1;
    844        
    845         if ((err = snd_pcm_new(emu->card, "emu10k1x", device, 1, capture, &pcm)) < 0)
    846                 return err;
    847  
    848         pcm->private_data = emu;
    849        
    850         switch(device) {
    851         case 0:
    852                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
    853                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1x_capture_ops);
    854                 break;
    855         case 1:
    856         case 2:
    857                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
    858                 break;
    859         }
    860 
    861         pcm->info_flags = 0;
    862         pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
    863         switch(device) {
    864         case 0:
    865                 strcpy(pcm->name, "EMU10K1X Front");
    866                 break;
    867         case 1:
    868                 strcpy(pcm->name, "EMU10K1X Rear");
    869                 break;
    870         case 2:
    871                 strcpy(pcm->name, "EMU10K1X Center/LFE");
    872                 break;
    873         }
    874         emu->pcm = pcm;
    875 
    876         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    877                                               snd_dma_pci_data(emu->pci),
    878                                               32*1024, 32*1024);
    879  
    880         if (rpcm)
    881                 *rpcm = pcm;
    882  
    883         return 0;
     835    struct snd_pcm *pcm;
     836    int err;
     837    int capture = 0;
     838
     839    if (rpcm)
     840        *rpcm = NULL;
     841    if (device == 0)
     842        capture = 1;
     843
     844    if ((err = snd_pcm_new(emu->card, "emu10k1x", device, 1, capture, &pcm)) < 0)
     845        return err;
     846
     847    pcm->private_data = emu;
     848
     849    switch(device) {
     850    case 0:
     851        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
     852        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1x_capture_ops);
     853        break;
     854    case 1:
     855    case 2:
     856        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
     857        break;
     858    }
     859
     860    pcm->info_flags = 0;
     861    pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
     862    switch(device) {
     863    case 0:
     864        strcpy(pcm->name, "EMU10K1X Front");
     865        break;
     866    case 1:
     867        strcpy(pcm->name, "EMU10K1X Rear");
     868        break;
     869    case 2:
     870        strcpy(pcm->name, "EMU10K1X Center/LFE");
     871        break;
     872    }
     873    emu->pcm = pcm;
     874
     875    snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
     876                                          snd_dma_pci_data(emu->pci),
     877                                          32*1024, 32*1024);
     878
     879    if (rpcm)
     880        *rpcm = pcm;
     881
     882    return 0;
    884883}
    885884
    886885static int __devinit snd_emu10k1x_create(struct snd_card *card,
    887                                         struct pci_dev *pci,
    888                                         struct emu10k1x **rchip)
    889 {
    890         struct emu10k1x *chip;
    891         int err;
    892         int ch;
    893         static struct snd_device_ops ops = {
    894                 .dev_free = snd_emu10k1x_dev_free,
    895         };
    896  
    897         *rchip = NULL;
    898  
    899         if ((err = pci_enable_device(pci)) < 0)
    900                 return err;
    901         pci_set_dma_mask(pci, 0x0fffffff);
    902  
    903         chip = (struct emu10k1x *)kzalloc(sizeof(*chip), GFP_KERNEL);
    904         if (chip == NULL) {
    905                 pci_disable_device(pci);
    906                 return -ENOMEM;
    907         }
    908  
    909         chip->card = card;
    910         chip->pci = pci;
    911         chip->irq = -1;
    912 
    913         spin_lock_init(&chip->emu_lock);
    914         spin_lock_init(&chip->voice_lock);
    915  
    916         chip->port = pci_resource_start(pci, 0);
    917         if ((chip->res_port = request_region(chip->port, 8,
    918                                              "EMU10K1X")) == NULL) {
    919                 snd_printk(KERN_ERR "emu10k1x: cannot allocate the port 0x%lx\n", chip->port);
    920                 snd_emu10k1x_free(chip);
    921                 return -EBUSY;
    922         }
    923 
    924         if (request_irq(pci->irq, snd_emu10k1x_interrupt,
    925                         SA_INTERRUPT|SA_SHIRQ, "EMU10K1X",
    926                         (void *)chip)) {
    927                 snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq);
    928                 snd_emu10k1x_free(chip);
    929                 return -EBUSY;
    930         }
    931         chip->irq = pci->irq;
    932  
    933         if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
    934                                4 * 1024, &chip->dma_buffer) < 0) {
    935                 snd_emu10k1x_free(chip);
    936                 return -ENOMEM;
    937         }
    938 
    939         pci_set_master(pci);
    940         /* read revision & serial */
    941         pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision);
    942         pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
    943         pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
    944         snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
    945                    chip->revision, chip->serial);
    946 
    947         outl(0, chip->port + INTE);     
    948 
    949         for(ch = 0; ch < 3; ch++) {
    950                 chip->voices[ch].emu = chip;
    951                 chip->voices[ch].number = ch;
    952         }
    953 
    954         /*
    955         *  Init to 0x02109204 :
    956         *  Clock accuracy    = 0     (1000ppm)
    957         *  Sample Rate       = 2     (48kHz)
    958         *  Audio Channel     = 1     (Left of 2)
    959         *  Source Number     = 0     (Unspecified)
    960         *  Generation Status = 1     (Original for Cat Code 12)
    961         *  Cat Code          = 12    (Digital Signal Mixer)
    962         *  Mode              = 0     (Mode 0)
    963         *  Emphasis          = 0     (None)
    964         *  CP                = 1     (Copyright unasserted)
    965         *  AN                = 0     (Audio data)
    966         *  P                 = 0     (Consumer)
    967         */
    968         snd_emu10k1x_ptr_write(chip, SPCS0, 0,
    969                                chip->spdif_bits[0] =
    970                                SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    971                                SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    972                                SPCS_GENERATIONSTATUS | 0x00001200 |
    973                                0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    974         snd_emu10k1x_ptr_write(chip, SPCS1, 0,
    975                                chip->spdif_bits[1] =
    976                                SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    977                                SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    978                                SPCS_GENERATIONSTATUS | 0x00001200 |
    979                                0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    980         snd_emu10k1x_ptr_write(chip, SPCS2, 0,
    981                                chip->spdif_bits[2] =
    982                                SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    983                                SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
    984                                SPCS_GENERATIONSTATUS | 0x00001200 |
    985                                0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
    986 
    987         snd_emu10k1x_ptr_write(chip, SPDIF_SELECT, 0, 0x700); // disable SPDIF
    988         snd_emu10k1x_ptr_write(chip, ROUTING, 0, 0x1003F); // routing
    989         snd_emu10k1x_gpio_write(chip, 0x1080); // analog mode
    990 
    991         outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
    992 
    993         if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
    994                                   chip, &ops)) < 0) {
    995                 snd_emu10k1x_free(chip);
    996                 return err;
    997         }
    998         *rchip = chip;
    999         return 0;
    1000 }
    1001 
    1002 static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry, 
    1003                                        struct snd_info_buffer *buffer)
    1004 {
    1005         struct emu10k1x *emu = entry->private_data;
    1006         unsigned long value,value1,value2;
    1007         unsigned long flags;
    1008         int i;
    1009 
    1010         snd_iprintf(buffer, "Registers:\n\n");
    1011         for(i = 0; i < 0x20; i+=4) {
    1012                 spin_lock_irqsave(&emu->emu_lock, flags);
    1013                 value = inl(emu->port + i);
    1014                 spin_unlock_irqrestore(&emu->emu_lock, flags);
    1015                 snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
    1016         }
    1017         snd_iprintf(buffer, "\nRegisters\n\n");
    1018         for(i = 0; i <= 0x48; i++) {
    1019                 value = snd_emu10k1x_ptr_read(emu, i, 0);
    1020                 if(i < 0x10 || (i >= 0x20 && i < 0x40)) {
    1021                         value1 = snd_emu10k1x_ptr_read(emu, i, 1);
    1022                         value2 = snd_emu10k1x_ptr_read(emu, i, 2);
    1023                         snd_iprintf(buffer, "%02X: %08lX %08lX %08lX\n", i, value, value1, value2);
    1024                 } else {
    1025                         snd_iprintf(buffer, "%02X: %08lX\n", i, value);
    1026                 }
    1027         }
    1028 }
    1029 
    1030 static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry, 
    1031                                         struct snd_info_buffer *buffer)
    1032 {
    1033         struct emu10k1x *emu = entry->private_data;
    1034         char line[64];
    1035         unsigned int reg, channel_id , val;
     886                                        struct pci_dev *pci,
     887                                        struct emu10k1x **rchip)
     888{
     889    struct emu10k1x *chip;
     890    int err;
     891    int ch;
     892    static struct snd_device_ops ops = {
     893        .dev_free = snd_emu10k1x_dev_free,
     894    };
     895
     896    *rchip = NULL;
     897
     898    if ((err = pci_enable_device(pci)) < 0)
     899        return err;
     900    pci_set_dma_mask(pci, 0x0fffffff);
     901
     902    chip = (struct emu10k1x *)kzalloc(sizeof(*chip), GFP_KERNEL);
     903    if (chip == NULL) {
     904        pci_disable_device(pci);
     905        return -ENOMEM;
     906    }
     907
     908    chip->card = card;
     909    chip->pci = pci;
     910    chip->irq = -1;
     911
     912    spin_lock_init(&chip->emu_lock);
     913    spin_lock_init(&chip->voice_lock);
     914
     915    chip->port = pci_resource_start(pci, 0);
     916    if ((chip->res_port = request_region(chip->port, 8,
     917                                         "EMU10K1X")) == NULL) {
     918        snd_printk(KERN_ERR "emu10k1x: cannot allocate the port 0x%lx\n", chip->port);
     919        snd_emu10k1x_free(chip);
     920        return -EBUSY;
     921    }
     922
     923    if (request_irq(pci->irq, snd_emu10k1x_interrupt,
     924                    SA_INTERRUPT|SA_SHIRQ, "EMU10K1X",
     925                    (void *)chip)) {
     926        snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq);
     927        snd_emu10k1x_free(chip);
     928        return -EBUSY;
     929    }
     930    chip->irq = pci->irq;
     931
     932    if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
     933                           4 * 1024, &chip->dma_buffer) < 0) {
     934        snd_emu10k1x_free(chip);
     935        return -ENOMEM;
     936    }
     937
     938    pci_set_master(pci);
     939    /* read revision & serial */
     940    pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision);
     941    pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
     942    pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
     943    snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
     944               chip->revision, chip->serial);
     945
     946    outl(0, chip->port + INTE);
     947
     948    for(ch = 0; ch < 3; ch++) {
     949        chip->voices[ch].emu = chip;
     950        chip->voices[ch].number = ch;
     951    }
     952
     953    /*
     954    *  Init to 0x02109204 :
     955    *  Clock accuracy    = 0     (1000ppm)
     956    *  Sample Rate       = 2     (48kHz)
     957    *  Audio Channel     = 1     (Left of 2)
     958    *  Source Number     = 0     (Unspecified)
     959    *  Generation Status = 1     (Original for Cat Code 12)
     960    *  Cat Code          = 12    (Digital Signal Mixer)
     961    *  Mode              = 0     (Mode 0)
     962    *  Emphasis          = 0     (None)
     963    *  CP                = 1     (Copyright unasserted)
     964    *  AN                = 0     (Audio data)
     965    *  P                 = 0     (Consumer)
     966    */
     967    snd_emu10k1x_ptr_write(chip, SPCS0, 0,
     968                           chip->spdif_bits[0] =
     969                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
     970                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     971                           SPCS_GENERATIONSTATUS | 0x00001200 |
     972                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
     973    snd_emu10k1x_ptr_write(chip, SPCS1, 0,
     974                           chip->spdif_bits[1] =
     975                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
     976                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     977                           SPCS_GENERATIONSTATUS | 0x00001200 |
     978                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
     979    snd_emu10k1x_ptr_write(chip, SPCS2, 0,
     980                           chip->spdif_bits[2] =
     981                           SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
     982                           SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
     983                           SPCS_GENERATIONSTATUS | 0x00001200 |
     984                           0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
     985
     986    snd_emu10k1x_ptr_write(chip, SPDIF_SELECT, 0, 0x700); // disable SPDIF
     987    snd_emu10k1x_ptr_write(chip, ROUTING, 0, 0x1003F); // routing
     988    snd_emu10k1x_gpio_write(chip, 0x1080); // analog mode
     989
     990    outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
     991
     992    if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
     993                              chip, &ops)) < 0) {
     994        snd_emu10k1x_free(chip);
     995        return err;
     996    }
     997    *rchip = chip;
     998    return 0;
     999}
     1000
     1001static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry,
     1002                                       struct snd_info_buffer *buffer)
     1003{
     1004    struct emu10k1x *emu = entry->private_data;
     1005    unsigned long value,value1,value2;
     1006    unsigned long flags;
     1007    int i;
     1008
     1009    snd_iprintf(buffer, "Registers:\n\n");
     1010    for(i = 0; i < 0x20; i+=4) {
     1011        spin_lock_irqsave(&emu->emu_lock, flags);
     1012        value = inl(emu->port + i);
     1013        spin_unlock_irqrestore(&emu->emu_lock, flags);
     1014        snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
     1015    }
     1016    snd_iprintf(buffer, "\nRegisters\n\n");
     1017    for(i = 0; i <= 0x48; i++) {
     1018        value = snd_emu10k1x_ptr_read(emu, i, 0);
     1019        if(i < 0x10 || (i >= 0x20 && i < 0x40)) {
     1020            value1 = snd_emu10k1x_ptr_read(emu, i, 1);
     1021            value2 = snd_emu10k1x_ptr_read(emu, i, 2);
     1022            snd_iprintf(buffer, "%02X: %08lX %08lX %08lX\n", i, value, value1, value2);
     1023        } else {
     1024            snd_iprintf(buffer, "%02X: %08lX\n", i, value);
     1025        }
     1026    }
     1027}
     1028
     1029static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
     1030                                        struct snd_info_buffer *buffer)
     1031{
     1032    struct emu10k1x *emu = entry->private_data;
     1033    char line[64];
     1034    unsigned int reg, channel_id , val;
    10361035#if 0
    1037         while (!snd_info_get_line(buffer, line, sizeof(line))) {
    1038                 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
    1039                         continue;
    1040 
    1041                 if ((reg < 0x49) && (reg >=0) && (val <= 0xffffffff)
    1042                     && (channel_id >=0) && (channel_id <= 2) )
    1043                         snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
    1044         }
     1036    while (!snd_info_get_line(buffer, line, sizeof(line))) {
     1037        if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
     1038            continue;
     1039
     1040        if ((reg < 0x49) && (reg >=0) && (val <= 0xffffffff)
     1041            && (channel_id >=0) && (channel_id <= 2) )
     1042            snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
     1043    }
    10451044#endif
    10461045}
     
    10481047static int __devinit snd_emu10k1x_proc_init(struct emu10k1x * emu)
    10491048{
    1050         struct snd_info_entry *entry;
    1051        
    1052         if(! snd_card_proc_new(emu->card, "emu10k1x_regs", &entry)) {
    1053                 snd_info_set_text_ops(entry, emu, 1024, snd_emu10k1x_proc_reg_read);
    1054                 entry->c.text.write_size = 64;
    1055                 entry->c.text.write = snd_emu10k1x_proc_reg_write;
    1056                 entry->mode |= S_IWUSR;
    1057                 entry->private_data = emu;
    1058         }
    1059        
    1060         return 0;
     1049    struct snd_info_entry *entry;
     1050
     1051    if(! snd_card_proc_new(emu->card, "emu10k1x_regs", &entry)) {
     1052        snd_info_set_text_ops(entry, emu, 1024, snd_emu10k1x_proc_reg_read);
     1053        entry->c.text.write_size = 64;
     1054        entry->c.text.write = snd_emu10k1x_proc_reg_write;
     1055        entry->mode |= S_IWUSR;
     1056        entry->private_data = emu;
     1057    }
     1058
     1059    return 0;
    10611060}
    10621061
    10631062static int snd_emu10k1x_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    10641063{
    1065         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
    1066         uinfo->count = 1;
    1067         uinfo->value.integer.min = 0;
    1068         uinfo->value.integer.max = 1;
    1069         return 0;
     1064    uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     1065    uinfo->count = 1;
     1066    uinfo->value.integer.min = 0;
     1067    uinfo->value.integer.max = 1;
     1068    return 0;
    10701069}
    10711070
    10721071static int snd_emu10k1x_shared_spdif_get(struct snd_kcontrol *kcontrol,
    1073                                         struct snd_ctl_elem_value *ucontrol)
    1074 {
    1075         struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
    1076 
    1077         ucontrol->value.integer.value[0] = (snd_emu10k1x_ptr_read(emu, SPDIF_SELECT, 0) == 0x700) ? 0 : 1;
    1078 
    1079         return 0;
     1072                                        struct snd_ctl_elem_value *ucontrol)
     1073{
     1074    struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
     1075
     1076    ucontrol->value.integer.value[0] = (snd_emu10k1x_ptr_read(emu, SPDIF_SELECT, 0) == 0x700) ? 0 : 1;
     1077
     1078    return 0;
    10801079}
    10811080
    10821081static int snd_emu10k1x_shared_spdif_put(struct snd_kcontrol *kcontrol,
    1083                                         struct snd_ctl_elem_value *ucontrol)
    1084 {
    1085         struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
    1086         unsigned int val;
    1087         int change = 0;
    1088 
    1089         val = ucontrol->value.integer.value[0] ;
    1090 
    1091         if (val) {
    1092                 // enable spdif output
    1093                 snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x000);
    1094                 snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x700);
    1095                 snd_emu10k1x_gpio_write(emu, 0x1000);
    1096         } else {
    1097                 // disable spdif output
    1098                 snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x700);
    1099                 snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x1003F);
    1100                 snd_emu10k1x_gpio_write(emu, 0x1080);
    1101         }
    1102         return change;
     1082                                        struct snd_ctl_elem_value *ucontrol)
     1083{
     1084    struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
     1085    unsigned int val;
     1086    int change = 0;
     1087
     1088    val = ucontrol->value.integer.value[0] ;
     1089
     1090    if (val) {
     1091        // enable spdif output
     1092        snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x000);
     1093        snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x700);
     1094        snd_emu10k1x_gpio_write(emu, 0x1000);
     1095    } else {
     1096        // disable spdif output
     1097        snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x700);
     1098        snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x1003F);
     1099        snd_emu10k1x_gpio_write(emu, 0x1080);
     1100    }
     1101    return change;
    11031102}
    11041103
    11051104static struct snd_kcontrol_new snd_emu10k1x_shared_spdif __devinitdata =
    11061105{
    1107         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
    1108         .name =         "Analog/Digital Output Jack",
    1109         .info =         snd_emu10k1x_shared_spdif_info,
    1110         .get =          snd_emu10k1x_shared_spdif_get,
    1111         .put =          snd_emu10k1x_shared_spdif_put
     1106    .iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
     1107    .name =             "Analog/Digital Output Jack",
     1108    .info =             snd_emu10k1x_shared_spdif_info,
     1109    .get =              snd_emu10k1x_shared_spdif_get,
     1110    .put =              snd_emu10k1x_shared_spdif_put
    11121111};
    11131112
    11141113static int snd_emu10k1x_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    11151114{
    1116         uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
    1117         uinfo->count = 1;
    1118         return 0;
     1115    uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
     1116    uinfo->count = 1;
     1117    return 0;
    11191118}
    11201119
    11211120static int snd_emu10k1x_spdif_get(struct snd_kcontrol *kcontrol,
    1122                                   struct snd_ctl_elem_value *ucontrol)
    1123 {
    1124         struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
    1125         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    1126 
    1127         ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
    1128         ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
    1129         ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
    1130         ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
    1131         return 0;
     1121                                  struct snd_ctl_elem_value *ucontrol)
     1122{
     1123    struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
     1124    unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
     1125
     1126    ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
     1127    ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
     1128    ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
     1129    ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
     1130    return 0;
    11321131}
    11331132
    11341133static int snd_emu10k1x_spdif_get_mask(struct snd_kcontrol *kcontrol,
    1135                                        struct snd_ctl_elem_value *ucontrol)
    1136 {
    1137         ucontrol->value.iec958.status[0] = 0xff;
    1138         ucontrol->value.iec958.status[1] = 0xff;
    1139         ucontrol->value.iec958.status[2] = 0xff;
    1140         ucontrol->value.iec958.status[3] = 0xff;
    1141         return 0;
     1134                                       struct snd_ctl_elem_value *ucontrol)
     1135{
     1136    ucontrol->value.iec958.status[0] = 0xff;
     1137    ucontrol->value.iec958.status[1] = 0xff;
     1138    ucontrol->value.iec958.status[2] = 0xff;
     1139    ucontrol->value.iec958.status[3] = 0xff;
     1140    return 0;
    11421141}
    11431142
    11441143static int snd_emu10k1x_spdif_put(struct snd_kcontrol *kcontrol,
    1145                                   struct snd_ctl_elem_value *ucontrol)
    1146 {
    1147         struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
    1148         unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    1149         int change;
    1150         unsigned int val;
    1151 
    1152         val = (ucontrol->value.iec958.status[0] << 0) |
    1153                 (ucontrol->value.iec958.status[1] << 8) |
    1154                 (ucontrol->value.iec958.status[2] << 16) |
    1155                 (ucontrol->value.iec958.status[3] << 24);
    1156         change = val != emu->spdif_bits[idx];
    1157         if (change) {
    1158                 snd_emu10k1x_ptr_write(emu, SPCS0 + idx, 0, val);
    1159                 emu->spdif_bits[idx] = val;
    1160         }
    1161         return change;
     1144                                  struct snd_ctl_elem_value *ucontrol)
     1145{
     1146    struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
     1147    unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
     1148    int change;
     1149    unsigned int val;
     1150
     1151    val = (ucontrol->value.iec958.status[0] << 0) |
     1152        (ucontrol->value.iec958.status[1] << 8) |
     1153        (ucontrol->value.iec958.status[2] << 16) |
     1154        (ucontrol->value.iec958.status[3] << 24);
     1155    change = val != emu->spdif_bits[idx];
     1156    if (change) {
     1157        snd_emu10k1x_ptr_write(emu, SPCS0 + idx, 0, val);
     1158        emu->spdif_bits[idx] = val;
     1159    }
     1160    return change;
    11621161}
    11631162
    11641163static struct snd_kcontrol_new snd_emu10k1x_spdif_mask_control =
    11651164{
    1166         .access =       SNDRV_CTL_ELEM_ACCESS_READ,
    1167         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
    1168         .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
    1169         .count =        3,
    1170         .info =         snd_emu10k1x_spdif_info,
    1171         .get =          snd_emu10k1x_spdif_get_mask
     1165    .access =   SNDRV_CTL_ELEM_ACCESS_READ,
     1166    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1167    .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
     1168    .count =    3,
     1169    .info =         snd_emu10k1x_spdif_info,
     1170    .get =          snd_emu10k1x_spdif_get_mask
    11721171};
    11731172
    11741173static struct snd_kcontrol_new snd_emu10k1x_spdif_control =
    11751174{
    1176         .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
    1177         .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
    1178         .count =        3,
    1179         .info =         snd_emu10k1x_spdif_info,
    1180         .get =          snd_emu10k1x_spdif_get,
    1181         .put =          snd_emu10k1x_spdif_put
     1175    .iface =    SNDRV_CTL_ELEM_IFACE_PCM,
     1176    .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
     1177    .count =    3,
     1178    .info =         snd_emu10k1x_spdif_info,
     1179    .get =          snd_emu10k1x_spdif_get,
     1180    .put =          snd_emu10k1x_spdif_put
    11821181};
    11831182
    11841183static int __devinit snd_emu10k1x_mixer(struct emu10k1x *emu)
    11851184{
    1186         int err;
    1187         struct snd_kcontrol *kctl;
    1188         struct snd_card *card = emu->card;
    1189 
    1190         if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_mask_control, emu)) == NULL)
    1191                 return -ENOMEM;
    1192         if ((err = snd_ctl_add(card, kctl)))
    1193                 return err;
    1194         if ((kctl = snd_ctl_new1(&snd_emu10k1x_shared_spdif, emu)) == NULL)
    1195                 return -ENOMEM;
    1196         if ((err = snd_ctl_add(card, kctl)))
    1197                 return err;
    1198         if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_control, emu)) == NULL)
    1199                 return -ENOMEM;
    1200         if ((err = snd_ctl_add(card, kctl)))
    1201                 return err;
    1202 
    1203         return 0;
     1185    int err;
     1186    struct snd_kcontrol *kctl;
     1187    struct snd_card *card = emu->card;
     1188
     1189    if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_mask_control, emu)) == NULL)
     1190        return -ENOMEM;
     1191    if ((err = snd_ctl_add(card, kctl)))
     1192        return err;
     1193    if ((kctl = snd_ctl_new1(&snd_emu10k1x_shared_spdif, emu)) == NULL)
     1194        return -ENOMEM;
     1195    if ((err = snd_ctl_add(card, kctl)))
     1196        return err;
     1197    if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_control, emu)) == NULL)
     1198        return -ENOMEM;
     1199    if ((err = snd_ctl_add(card, kctl)))
     1200        return err;
     1201
     1202    return 0;
    12041203}
    12051204
     
    12091208static inline unsigned char mpu401_read(struct emu10k1x *emu, struct emu10k1x_midi *mpu, int idx)
    12101209{
    1211         return (unsigned char)snd_emu10k1x_ptr_read(emu, mpu->port + idx, 0);
     1210    return (unsigned char)snd_emu10k1x_ptr_read(emu, mpu->port + idx, 0);
    12121211}
    12131212
    12141213static inline void mpu401_write(struct emu10k1x *emu, struct emu10k1x_midi *mpu, int data, int idx)
    12151214{
    1216         snd_emu10k1x_ptr_write(emu, mpu->port + idx, 0, data);
     1215    snd_emu10k1x_ptr_write(emu, mpu->port + idx, 0, data);
    12171216}
    12181217
     
    12311230static void mpu401_clear_rx(struct emu10k1x *emu, struct emu10k1x_midi *mpu)
    12321231{
    1233         int timeout = 100000;
    1234         for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--)
    1235                 mpu401_read_data(emu, mpu);
     1232    int timeout = 100000;
     1233    for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--)
     1234        mpu401_read_data(emu, mpu);
    12361235#ifdef CONFIG_SND_DEBUG
    1237         if (timeout <= 0)
    1238                 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
     1236    if (timeout <= 0)
     1237        snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
    12391238#endif
    12401239}
     
    12421241/*
    12431242
    1244  */
     1243*/
    12451244
    12461245static void do_emu10k1x_midi_interrupt(struct emu10k1x *emu,
    1247                                        struct emu10k1x_midi *midi, unsigned int status)
    1248 {
    1249         unsigned char byte;
    1250 
    1251         if (midi->rmidi == NULL) {
    1252                 snd_emu10k1x_intr_disable(emu, midi->tx_enable | midi->rx_enable);
    1253                 return;
    1254         }
    1255 
    1256         spin_lock(&midi->input_lock);
    1257         if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) {
    1258                 if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
    1259                         mpu401_clear_rx(emu, midi);
    1260                 } else {
    1261                         byte = mpu401_read_data(emu, midi);
    1262                         if (midi->substream_input)
    1263                                 snd_rawmidi_receive(midi->substream_input, &byte, 1);
    1264                 }
    1265         }
    1266         spin_unlock(&midi->input_lock);
    1267 
    1268         spin_lock(&midi->output_lock);
    1269         if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) {
    1270                 if (midi->substream_output &&
    1271                     snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
    1272                         mpu401_write_data(emu, midi, byte);
    1273                 } else {
    1274                         snd_emu10k1x_intr_disable(emu, midi->tx_enable);
    1275                 }
    1276         }
    1277         spin_unlock(&midi->output_lock);
     1246                                       struct emu10k1x_midi *midi, unsigned int status)
     1247{
     1248    unsigned char byte;
     1249
     1250    if (midi->rmidi == NULL) {
     1251        snd_emu10k1x_intr_disable(emu, midi->tx_enable | midi->rx_enable);
     1252        return;
     1253    }
     1254
     1255    spin_lock(&midi->input_lock);
     1256    if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) {
     1257        if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
     1258            mpu401_clear_rx(emu, midi);
     1259        } else {
     1260            byte = mpu401_read_data(emu, midi);
     1261            if (midi->substream_input)
     1262                snd_rawmidi_receive(midi->substream_input, &byte, 1);
     1263        }
     1264    }
     1265    spin_unlock(&midi->input_lock);
     1266
     1267    spin_lock(&midi->output_lock);
     1268    if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) {
     1269        if (midi->substream_output &&
     1270            snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
     1271            mpu401_write_data(emu, midi, byte);
     1272        } else {
     1273            snd_emu10k1x_intr_disable(emu, midi->tx_enable);
     1274        }
     1275    }
     1276    spin_unlock(&midi->output_lock);
    12781277}
    12791278
    12801279static void snd_emu10k1x_midi_interrupt(struct emu10k1x *emu, unsigned int status)
    12811280{
    1282         do_emu10k1x_midi_interrupt(emu, &emu->midi, status);
    1283 }
    1284 
    1285 static void snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
    1286                                   struct emu10k1x_midi *midi, unsigned char cmd, int ack)
    1287 {
    1288         unsigned long flags;
    1289         int timeout, ok;
    1290 
    1291         spin_lock_irqsave(&midi->input_lock, flags);
    1292         mpu401_write_data(emu, midi, 0x00);
    1293         /* mpu401_clear_rx(emu, midi); */
    1294 
    1295         mpu401_write_cmd(emu, midi, cmd);
    1296         if (ack) {
    1297                 ok = 0;
    1298                 timeout = 10000;
    1299                 while (!ok && timeout-- > 0) {
    1300                         if (mpu401_input_avail(emu, midi)) {
    1301                                 if (mpu401_read_data(emu, midi) == MPU401_ACK)
    1302                                         ok = 1;
    1303                         }
    1304                 }
    1305                 if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK)
    1306                         ok = 1;
    1307         } else {
    1308                 ok = 1;
    1309         }
    1310         spin_unlock_irqrestore(&midi->input_lock, flags);
    1311         if (!ok)
    1312                 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
    1313                            cmd, emu->port,
    1314                            mpu401_read_stat(emu, midi),
    1315                            mpu401_read_data(emu, midi));
     1281    do_emu10k1x_midi_interrupt(emu, &emu->midi, status);
     1282}
     1283
     1284static int snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
     1285                                 struct emu10k1x_midi *midi, unsigned char cmd, int ack)
     1286{
     1287    unsigned long flags;
     1288    int timeout, ok;
     1289
     1290    spin_lock_irqsave(&midi->input_lock, flags);
     1291    mpu401_write_data(emu, midi, 0x00);
     1292    /* mpu401_clear_rx(emu, midi); */
     1293
     1294    mpu401_write_cmd(emu, midi, cmd);
     1295    if (ack) {
     1296        ok = 0;
     1297        timeout = 10000;
     1298        while (!ok && timeout-- > 0) {
     1299            if (mpu401_input_avail(emu, midi)) {
     1300                if (mpu401_read_data(emu, midi) == MPU401_ACK)
     1301                    ok = 1;
     1302            }
     1303        }
     1304        if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK)
     1305            ok = 1;
     1306    } else {
     1307        ok = 1;
     1308    }
     1309    spin_unlock_irqrestore(&midi->input_lock, flags);
     1310    if (!ok) {
     1311        snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
     1312                   cmd, emu->port,
     1313                   mpu401_read_stat(emu, midi),
     1314                   mpu401_read_data(emu, midi));
     1315        return 1;
     1316    }
     1317    return 0;
    13161318}
    13171319
    13181320static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream)
    13191321{
    1320         struct emu10k1x *emu;
    1321         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1322         unsigned long flags;
    1323        
    1324         emu = midi->emu;
    1325         snd_assert(emu, return -ENXIO);
    1326         spin_lock_irqsave(&midi->open_lock, flags);
    1327         midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT;
    1328         midi->substream_input = substream;
    1329         if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
    1330                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1331                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1);
    1332                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
    1333         } else {
    1334                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1335         }
    1336         return 0;
     1322    struct emu10k1x *emu;
     1323    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1324    unsigned long flags;
     1325
     1326    emu = midi->emu;
     1327    snd_assert(emu, return -ENXIO);
     1328    spin_lock_irqsave(&midi->open_lock, flags);
     1329    midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT;
     1330    midi->substream_input = substream;
     1331    if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
     1332        spin_unlock_irqrestore(&midi->open_lock, flags);
     1333        if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
     1334            goto error_out;
     1335        if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
     1336            goto error_out;
     1337    } else {
     1338        spin_unlock_irqrestore(&midi->open_lock, flags);
     1339    }
     1340    return 0;
     1341
     1342    error_out:
     1343        return -EIO;
    13371344}
    13381345
    13391346static int snd_emu10k1x_midi_output_open(struct snd_rawmidi_substream *substream)
    13401347{
    1341         struct emu10k1x *emu;
    1342         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1343         unsigned long flags;
    1344 
    1345         emu = midi->emu;
    1346         snd_assert(emu, return -ENXIO);
    1347         spin_lock_irqsave(&midi->open_lock, flags);
    1348         midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT;
    1349         midi->substream_output = substream;
    1350         if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
    1351                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1352                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1);
    1353                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
    1354         } else {
    1355                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1356         }
    1357         return 0;
     1348    struct emu10k1x *emu;
     1349    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1350    unsigned long flags;
     1351
     1352    emu = midi->emu;
     1353    snd_assert(emu, return -ENXIO);
     1354    spin_lock_irqsave(&midi->open_lock, flags);
     1355    midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT;
     1356    midi->substream_output = substream;
     1357    if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
     1358        spin_unlock_irqrestore(&midi->open_lock, flags);
     1359        if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
     1360            goto error_out;
     1361        if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
     1362            goto error_out;
     1363    } else {
     1364        spin_unlock_irqrestore(&midi->open_lock, flags);
     1365    }
     1366    return 0;
     1367
     1368    error_out:
     1369        return -EIO;
    13581370}
    13591371
    13601372static int snd_emu10k1x_midi_input_close(struct snd_rawmidi_substream *substream)
    13611373{
    1362         struct emu10k1x *emu;
    1363         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1364         unsigned long flags;
    1365 
    1366         emu = midi->emu;
    1367         snd_assert(emu, return -ENXIO);
    1368         spin_lock_irqsave(&midi->open_lock, flags);
    1369         snd_emu10k1x_intr_disable(emu, midi->rx_enable);
    1370         midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT;
    1371         midi->substream_input = NULL;
    1372         if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
    1373                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1374                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
    1375         } else {
    1376                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1377         }
    1378         return 0;
     1374    struct emu10k1x *emu;
     1375    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1376    unsigned long flags;
     1377    int err = 0;
     1378
     1379    emu = midi->emu;
     1380    snd_assert(emu, return -ENXIO);
     1381    spin_lock_irqsave(&midi->open_lock, flags);
     1382    snd_emu10k1x_intr_disable(emu, midi->rx_enable);
     1383    midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT;
     1384    midi->substream_input = NULL;
     1385    if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
     1386        spin_unlock_irqrestore(&midi->open_lock, flags);
     1387        err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
     1388    } else {
     1389        spin_unlock_irqrestore(&midi->open_lock, flags);
     1390    }
     1391    return err;
    13791392}
    13801393
    13811394static int snd_emu10k1x_midi_output_close(struct snd_rawmidi_substream *substream)
    13821395{
    1383         struct emu10k1x *emu;
    1384         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1385         unsigned long flags;
    1386 
    1387         emu = midi->emu;
    1388         snd_assert(emu, return -ENXIO);
    1389         spin_lock_irqsave(&midi->open_lock, flags);
    1390         snd_emu10k1x_intr_disable(emu, midi->tx_enable);
    1391         midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT;
    1392         midi->substream_output = NULL;
    1393         if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
    1394                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1395                 snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
    1396         } else {
    1397                 spin_unlock_irqrestore(&midi->open_lock, flags);
    1398         }
    1399         return 0;
     1396    struct emu10k1x *emu;
     1397    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1398    unsigned long flags;
     1399    int err = 0;
     1400
     1401    emu = midi->emu;
     1402    snd_assert(emu, return -ENXIO);
     1403    spin_lock_irqsave(&midi->open_lock, flags);
     1404    snd_emu10k1x_intr_disable(emu, midi->tx_enable);
     1405    midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT;
     1406    midi->substream_output = NULL;
     1407    if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
     1408        spin_unlock_irqrestore(&midi->open_lock, flags);
     1409        err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
     1410    } else {
     1411        spin_unlock_irqrestore(&midi->open_lock, flags);
     1412    }
     1413    return err;
    14001414}
    14011415
    14021416static void snd_emu10k1x_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
    14031417{
    1404         struct emu10k1x *emu;
    1405         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1406         emu = midi->emu;
    1407         snd_assert(emu, return);
    1408 
    1409         if (up)
    1410                 snd_emu10k1x_intr_enable(emu, midi->rx_enable);
    1411         else
    1412                 snd_emu10k1x_intr_disable(emu, midi->rx_enable);
     1418    struct emu10k1x *emu;
     1419    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1420    emu = midi->emu;
     1421    snd_assert(emu, return);
     1422
     1423    if (up)
     1424        snd_emu10k1x_intr_enable(emu, midi->rx_enable);
     1425    else
     1426        snd_emu10k1x_intr_disable(emu, midi->rx_enable);
    14131427}
    14141428
    14151429static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
    14161430{
    1417         struct emu10k1x *emu;
    1418         struct emu10k1x_midi *midi = substream->rmidi->private_data;
    1419         unsigned long flags;
    1420 
    1421         emu = midi->emu;
    1422         snd_assert(emu, return);
    1423 
    1424         if (up) {
    1425                 int max = 4;
    1426                 unsigned char byte;
    1427        
    1428                 /* try to send some amount of bytes here before interrupts */
    1429                 spin_lock_irqsave(&midi->output_lock, flags);
    1430                 while (max > 0) {
    1431                         if (mpu401_output_ready(emu, midi)) {
    1432                                 if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT) ||
    1433                                     snd_rawmidi_transmit(substream, &byte, 1) != 1) {
    1434                                         /* no more data */
    1435                                         spin_unlock_irqrestore(&midi->output_lock, flags);
    1436                                         return;
    1437                                 }
    1438                                 mpu401_write_data(emu, midi, byte);
    1439                                 max--;
    1440                         } else {
    1441                                 break;
    1442                         }
    1443                 }
    1444                 spin_unlock_irqrestore(&midi->output_lock, flags);
    1445                 snd_emu10k1x_intr_enable(emu, midi->tx_enable);
    1446         } else {
    1447                 snd_emu10k1x_intr_disable(emu, midi->tx_enable);
    1448         }
     1431    struct emu10k1x *emu;
     1432    struct emu10k1x_midi *midi = substream->rmidi->private_data;
     1433    unsigned long flags;
     1434
     1435    emu = midi->emu;
     1436    snd_assert(emu, return);
     1437
     1438    if (up) {
     1439        int max = 4;
     1440        unsigned char byte;
     1441
     1442        /* try to send some amount of bytes here before interrupts */
     1443        spin_lock_irqsave(&midi->output_lock, flags);
     1444        while (max > 0) {
     1445            if (mpu401_output_ready(emu, midi)) {
     1446                if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT) ||
     1447                    snd_rawmidi_transmit(substream, &byte, 1) != 1) {
     1448                    /* no more data */
     1449                    spin_unlock_irqrestore(&midi->output_lock, flags);
     1450                    return;
     1451                }
     1452                mpu401_write_data(emu, midi, byte);
     1453                max--;
     1454            } else {
     1455                break;
     1456            }
     1457        }
     1458        spin_unlock_irqrestore(&midi->output_lock, flags);
     1459        snd_emu10k1x_intr_enable(emu, midi->tx_enable);
     1460    } else {
     1461        snd_emu10k1x_intr_disable(emu, midi->tx_enable);
     1462    }
    14491463}
    14501464
    14511465/*
    14521466
    1453  */
     1467*/
    14541468
    14551469static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
    14561470{
    1457         .open =         snd_emu10k1x_midi_output_open,
    1458         .close =        snd_emu10k1x_midi_output_close,
    1459         .trigger =      snd_emu10k1x_midi_output_trigger,
     1471    .open =             snd_emu10k1x_midi_output_open,
     1472    .close =    snd_emu10k1x_midi_output_close,
     1473    .trigger =  snd_emu10k1x_midi_output_trigger,
    14601474};
    14611475
    14621476static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
    14631477{
    1464         .open =         snd_emu10k1x_midi_input_open,
    1465         .close =        snd_emu10k1x_midi_input_close,
    1466         .trigger =      snd_emu10k1x_midi_input_trigger,
     1478    .open =             snd_emu10k1x_midi_input_open,
     1479    .close =    snd_emu10k1x_midi_input_close,
     1480    .trigger =  snd_emu10k1x_midi_input_trigger,
    14671481};
    14681482
    14691483static void snd_emu10k1x_midi_free(struct snd_rawmidi *rmidi)
    14701484{
    1471         struct emu10k1x_midi *midi = rmidi->private_data;
    1472         midi->interrupt = NULL;
    1473         midi->rmidi = NULL;
     1485    struct emu10k1x_midi *midi = rmidi->private_data;
     1486    midi->interrupt = NULL;
     1487    midi->rmidi = NULL;
    14741488}
    14751489
    14761490static int __devinit emu10k1x_midi_init(struct emu10k1x *emu,
    1477                                         struct emu10k1x_midi *midi, int device, char *name)
    1478 {
    1479         struct snd_rawmidi *rmidi;
    1480         int err;
    1481 
    1482         if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
    1483                 return err;
    1484         midi->emu = emu;
    1485         spin_lock_init(&midi->open_lock);
    1486         spin_lock_init(&midi->input_lock);
    1487         spin_lock_init(&midi->output_lock);
    1488         strcpy(rmidi->name, name);
    1489         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1x_midi_output);
    1490         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1x_midi_input);
    1491         rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
    1492                              SNDRV_RAWMIDI_INFO_INPUT |
    1493                              SNDRV_RAWMIDI_INFO_DUPLEX;
    1494         rmidi->private_data = midi;
    1495         rmidi->private_free = snd_emu10k1x_midi_free;
    1496         midi->rmidi = rmidi;
    1497         return 0;
     1491                                        struct emu10k1x_midi *midi, int device, char *name)
     1492{
     1493    struct snd_rawmidi *rmidi;
     1494    int err;
     1495
     1496    if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
     1497        return err;
     1498    midi->emu = emu;
     1499    spin_lock_init(&midi->open_lock);
     1500    spin_lock_init(&midi->input_lock);
     1501    spin_lock_init(&midi->output_lock);
     1502    strcpy(rmidi->name, name);
     1503    snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1x_midi_output);
     1504    snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1x_midi_input);
     1505    rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
     1506        SNDRV_RAWMIDI_INFO_INPUT |
     1507        SNDRV_RAWMIDI_INFO_DUPLEX;
     1508    rmidi->private_data = midi;
     1509    rmidi->private_free = snd_emu10k1x_midi_free;
     1510    midi->rmidi = rmidi;
     1511    return 0;
    14981512}
    14991513
    15001514static int __devinit snd_emu10k1x_midi(struct emu10k1x *emu)
    15011515{
    1502         struct emu10k1x_midi *midi = &emu->midi;
    1503         int err;
    1504 
    1505         if ((err = emu10k1x_midi_init(emu, midi, 0, "EMU10K1X MPU-401 (UART)")) < 0)
    1506                 return err;
    1507 
    1508         midi->tx_enable = INTE_MIDITXENABLE;
    1509         midi->rx_enable = INTE_MIDIRXENABLE;
    1510         midi->port = MUDATA;
    1511         midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
    1512         midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
    1513         midi->interrupt = snd_emu10k1x_midi_interrupt;
    1514         return 0;
     1516    struct emu10k1x_midi *midi = &emu->midi;
     1517    int err;
     1518
     1519    if ((err = emu10k1x_midi_init(emu, midi, 0, "EMU10K1X MPU-401 (UART)")) < 0)
     1520        return err;
     1521
     1522    midi->tx_enable = INTE_MIDITXENABLE;
     1523    midi->rx_enable = INTE_MIDIRXENABLE;
     1524    midi->port = MUDATA;
     1525    midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
     1526    midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
     1527    midi->interrupt = snd_emu10k1x_midi_interrupt;
     1528    return 0;
    15151529}
    15161530
    15171531static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
    1518                                         const struct pci_device_id *pci_id)
    1519 {
    1520         static int dev;
    1521         struct snd_card *card;
    1522         struct emu10k1x *chip;
    1523         int err;
    1524 
    1525         if (dev >= SNDRV_CARDS)
    1526                 return -ENODEV;
    1527         if (!enable[dev]) {
    1528                 dev++;
    1529                 return -ENOENT;
    1530         }
    1531 
    1532         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
    1533         if (card == NULL)
    1534                 return -ENOMEM;
    1535 
    1536         if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
    1537                 snd_card_free(card);
    1538                 return err;
    1539         }
    1540 
    1541         if ((err = snd_emu10k1x_pcm(chip, 0, NULL)) < 0) {
    1542                 snd_card_free(card);
    1543                 return err;
    1544         }
    1545         if ((err = snd_emu10k1x_pcm(chip, 1, NULL)) < 0) {
    1546                 snd_card_free(card);
    1547                 return err;
    1548         }
    1549         if ((err = snd_emu10k1x_pcm(chip, 2, NULL)) < 0) {
    1550                 snd_card_free(card);
    1551                 return err;
    1552         }
    1553 
    1554         if ((err = snd_emu10k1x_ac97(chip)) < 0) {
    1555                 snd_card_free(card);
    1556                 return err;
    1557         }
    1558 
    1559         if ((err = snd_emu10k1x_mixer(chip)) < 0) {
    1560                 snd_card_free(card);
    1561                 return err;
    1562         }
    1563        
    1564         if ((err = snd_emu10k1x_midi(chip)) < 0) {
    1565                 snd_card_free(card);
    1566                 return err;
    1567         }
    1568 
    1569         snd_emu10k1x_proc_init(chip);
    1570 
    1571         strcpy(card->driver, "EMU10K1X");
    1572         strcpy(card->shortname, "Dell Sound Blaster Live!");
    1573         sprintf(card->longname, "%s at 0x%lx irq %i",
    1574                 card->shortname, chip->port, chip->irq);
    1575 
    1576         if ((err = snd_card_register(card)) < 0) {
    1577                 snd_card_free(card);
    1578                 return err;
    1579         }
    1580 
    1581         pci_set_drvdata(pci, card);
    1582         dev++;
    1583         return 0;
     1532                                        const struct pci_device_id *pci_id)
     1533{
     1534    static int dev;
     1535    struct snd_card *card;
     1536    struct emu10k1x *chip;
     1537    int err;
     1538
     1539    if (dev >= SNDRV_CARDS)
     1540        return -ENODEV;
     1541    if (!enable[dev]) {
     1542        dev++;
     1543        return -ENOENT;
     1544    }
     1545
     1546    card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
     1547    if (card == NULL)
     1548        return -ENOMEM;
     1549
     1550    if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
     1551        snd_card_free(card);
     1552        return err;
     1553    }
     1554
     1555    if ((err = snd_emu10k1x_pcm(chip, 0, NULL)) < 0) {
     1556        snd_card_free(card);
     1557        return err;
     1558    }
     1559    if ((err = snd_emu10k1x_pcm(chip, 1, NULL)) < 0) {
     1560        snd_card_free(card);
     1561        return err;
     1562    }
     1563    if ((err = snd_emu10k1x_pcm(chip, 2, NULL)) < 0) {
     1564        snd_card_free(card);
     1565        return err;
     1566    }
     1567
     1568    if ((err = snd_emu10k1x_ac97(chip)) < 0) {
     1569        snd_card_free(card);
     1570        return err;
     1571    }
     1572
     1573    if ((err = snd_emu10k1x_mixer(chip)) < 0) {
     1574        snd_card_free(card);
     1575        return err;
     1576    }
     1577
     1578    if ((err = snd_emu10k1x_midi(chip)) < 0) {
     1579        snd_card_free(card);
     1580        return err;
     1581    }
     1582
     1583    snd_emu10k1x_proc_init(chip);
     1584
     1585    strcpy(card->driver, "EMU10K1X");
     1586    strcpy(card->shortname, "Dell Sound Blaster Live!");
     1587    sprintf(card->longname, "%s at 0x%lx irq %i",
     1588            card->shortname, chip->port, chip->irq);
     1589
     1590    if ((err = snd_card_register(card)) < 0) {
     1591        snd_card_free(card);
     1592        return err;
     1593    }
     1594
     1595    pci_set_drvdata(pci, card);
     1596    dev++;
     1597    return 0;
    15841598}
    15851599
    15861600static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
    15871601{
    1588         snd_card_free(pci_get_drvdata(pci));
    1589         pci_set_drvdata(pci, NULL);
     1602    snd_card_free(pci_get_drvdata(pci));
     1603    pci_set_drvdata(pci, NULL);
    15901604}
    15911605
    15921606// PCI IDs
    15931607static struct pci_device_id snd_emu10k1x_ids[] = {
    1594         { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },    /* Dell OEM version (EMU10K1) */
    1595         { 0, }
     1608    { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },        /* Dell OEM version (EMU10K1) */
     1609    { 0, }
    15961610};
    15971611MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
     
    15991613// pci_driver definition
    16001614static struct pci_driver driver = {
    1601         .name = "EMU10K1X",
    1602         .id_table = snd_emu10k1x_ids,
    1603         .probe = snd_emu10k1x_probe,
    1604         .remove = snd_emu10k1x_remove,
     1615    .name = "EMU10K1X",
     1616    .id_table = snd_emu10k1x_ids,
     1617    .probe = snd_emu10k1x_probe,
     1618    .remove = snd_emu10k1x_remove,
    16051619};
    16061620
     
    16081622static int __init alsa_card_emu10k1x_init(void)
    16091623{
    1610         int err;
    1611 
    1612         if ((err = pci_register_driver(&driver)) > 0)
    1613                 return err;
    1614 
    1615         return 0;
     1624    int err;
     1625
     1626    if ((err = pci_register_driver(&driver)) > 0)
     1627        return err;
     1628
     1629    return 0;
    16161630}
    16171631
     
    16191633static void __exit alsa_card_emu10k1x_exit(void)
    16201634{
    1621         pci_unregister_driver(&driver);
     1635    pci_unregister_driver(&driver);
    16221636}
    16231637
  • GPL/trunk/alsa-kernel/pci/emu10k1/emufx.c

    r34 r84  
    33 *                   Creative Labs, Inc.
    44 *  Routines for effect processor FX8010
     5 *
     6 *  Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
     7 *      Added EMU 1010 support.
    58 *
    69 *  BUGS:
     
    2932#include <linux/delay.h>
    3033#include <linux/slab.h>
     34
    3135#include <sound/core.h>
     36#include <sound/tlv.h>
    3237#include <sound/emu10k1.h>
    33 
    3438
    3539#if 0           /* for testing purposes - digital out -> capture */
     
    262266};
    263267
     268/* dB gain = (float) 20 * log10( float(db_table_value) / 0x8000000 ) */
    264269static const u32 db_table[101] = {
    265270    0x00000000, 0x01571f82, 0x01674b41, 0x01783a1b, 0x0189f540,
     
    286291};
    287292
     293/* EMU10k1/EMU10k2 DSP control db gain */
     294static DECLARE_TLV_DB_SCALE(snd_emu10k1_db_scale1, -4000, 40, 1);
     295
    288296static const u32 onoff_table[2] = {
    289297    0x00000000, 0x00000001
     
    310318 */
    311319
    312 static int snd_emu10k1_gpr_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    313 {
    314     struct snd_emu10k1_fx8010_ctl *ctl = (struct snd_emu10k1_fx8010_ctl *)kcontrol->private_value;
     320static int snd_emu10k1_gpr_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     321{
     322    struct snd_emu10k1_fx8010_ctl *ctl =
     323        (struct snd_emu10k1_fx8010_ctl *) kcontrol->private_value;
    315324
    316325    if (ctl->min == 0 && ctl->max == 1)
     
    324333}
    325334
    326 static int snd_emu10k1_gpr_ctl_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     335static int snd_emu10k1_gpr_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    327336{
    328337    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    329     struct snd_emu10k1_fx8010_ctl *ctl = (struct snd_emu10k1_fx8010_ctl *)kcontrol->private_value;
     338    struct snd_emu10k1_fx8010_ctl *ctl =
     339        (struct snd_emu10k1_fx8010_ctl *) kcontrol->private_value;
    330340    unsigned long flags;
    331341    unsigned int i;
     
    338348}
    339349
    340 static int snd_emu10k1_gpr_ctl_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     350static int snd_emu10k1_gpr_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    341351{
    342352    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    343     struct snd_emu10k1_fx8010_ctl *ctl = (struct snd_emu10k1_fx8010_ctl *)kcontrol->private_value;
     353    struct snd_emu10k1_fx8010_ctl *ctl =
     354        (struct snd_emu10k1_fx8010_ctl *) kcontrol->private_value;
    344355    unsigned long flags;
    345356    unsigned int nval, val;
     
    365376            break;
    366377        case EMU10K1_GPR_TRANSLATION_BASS:
    367             snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error);
     378            if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
     379                change = -EIO;
     380                goto __error;
     381            }
    368382            for (j = 0; j < 5; j++)
    369383                snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]);
    370384            break;
    371385        case EMU10K1_GPR_TRANSLATION_TREBLE:
    372             snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error);
     386            if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
     387                change = -EIO;
     388                goto __error;
     389            }
    373390            for (j = 0; j < 5; j++)
    374391                snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]);
     
    413430    unsigned long flags;
    414431
    415     snd_runtime_check(emu, return -EINVAL);
    416     snd_runtime_check(handler, return -EINVAL);
    417432    irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
    418433    if (irq == NULL)
     
    443458    unsigned long flags;
    444459
    445     snd_runtime_check(irq, return -EINVAL);
    446460    spin_lock_irqsave(&emu->fx8010.irq_lock, flags);
    447461    if ((tmp = emu->fx8010.irq_handlers) == irq) {
     
    466480 *************************************************************************/
    467481
    468 static void snd_emu10k1_write_op(emu10k1_fx8010_code_t *icode, unsigned int *ptr,
    469                                 u32 op, u32 r, u32 a, u32 x, u32 y)
     482static void snd_emu10k1_write_op(struct snd_emu10k1_fx8010_code *icode,
     483                                 unsigned int *ptr,
     484                                 u32 op, u32 r, u32 a, u32 x, u32 y)
    470485{
    471486    u_int32_t *code;
    472487    snd_assert(*ptr < 512, return);
    473     code = (u_int32_t *)icode->code + (*ptr) * 2;
     488    code = (u_int32_t __force *)icode->code + (*ptr) * 2;
    474489    set_bit(*ptr, icode->code_valid);
    475490    code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff);
     
    481496    snd_emu10k1_write_op(icode, ptr, op, r, a, x, y)
    482497
    483 static void snd_emu10k1_audigy_write_op(emu10k1_fx8010_code_t *icode, unsigned int *ptr,
    484                                        u32 op, u32 r, u32 a, u32 x, u32 y)
     498static void snd_emu10k1_audigy_write_op(struct snd_emu10k1_fx8010_code *icode,
     499                                        unsigned int *ptr,
     500                                        u32 op, u32 r, u32 a, u32 x, u32 y)
    485501{
    486502    u_int32_t *code;
    487503    snd_assert(*ptr < 1024, return);
    488     code = (u_int32_t *)icode->code + (*ptr) * 2;
     504    code = (u_int32_t __force *)icode->code + (*ptr) * 2;
    489505    set_bit(*ptr, icode->code_valid);
    490506    code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff);
     
    496512    snd_emu10k1_audigy_write_op(icode, ptr, op, r, a, x, y)
    497513
    498 void snd_emu10k1_efx_write(struct snd_emu10k1 *emu, unsigned int pc, unsigned int data)
     514static void snd_emu10k1_efx_write(struct snd_emu10k1 *emu, unsigned int pc, unsigned int data)
    499515{
    500516    pc += emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
     
    508524}
    509525
    510 static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     526static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu,
     527                                struct snd_emu10k1_fx8010_code *icode)
    511528{
    512529    int gpr;
     
    523540}
    524541
    525 static int snd_emu10k1_gpr_peek(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     542static int snd_emu10k1_gpr_peek(struct snd_emu10k1 *emu,
     543                                struct snd_emu10k1_fx8010_code *icode)
    526544{
    527545    int gpr;
     
    537555}
    538556
    539 static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     557static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu,
     558                                 struct snd_emu10k1_fx8010_code *icode)
    540559{
    541560    int tram;
     
    559578}
    560579
    561 static int snd_emu10k1_tram_peek(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     580static int snd_emu10k1_tram_peek(struct snd_emu10k1 *emu,
     581                                 struct snd_emu10k1_fx8010_code *icode)
    562582{
    563583    int tram;
     
    581601}
    582602
    583 static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     603static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu,
     604                                 struct snd_emu10k1_fx8010_code *icode)
    584605{
    585606    u32 pc, lo, hi;
     
    597618}
    598619
    599 static int snd_emu10k1_code_peek(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     620static int snd_emu10k1_code_peek(struct snd_emu10k1 *emu,
     621                                 struct snd_emu10k1_fx8010_code *icode)
    600622{
    601623    u32 pc;
     
    612634}
    613635
    614 static struct snd_emu10k1_fx8010_ctl *snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, snd_ctl_elem_id_t *id)
     636static struct snd_emu10k1_fx8010_ctl *
     637snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct snd_ctl_elem_id *id)
    615638{
    616639    struct snd_emu10k1_fx8010_ctl *ctl;
    617     snd_kcontrol_t *kcontrol;
     640    struct snd_kcontrol *kcontrol;
    618641    struct list_head *list;
    619642
     
    629652}
    630653
    631 static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     654static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu,
     655                                       struct snd_emu10k1_fx8010_code *icode)
    632656{
    633657    unsigned int i;
    634     snd_ctl_elem_id_t *_id, id;
    635     emu10k1_fx8010_control_gpr_t *_gctl;
    636     emu10k1_fx8010_control_gpr_t *gctl;
     658    struct snd_ctl_elem_id __user *_id;
     659    struct snd_ctl_elem_id id;
     660    struct snd_emu10k1_fx8010_control_gpr __user *_gctl;
     661    struct snd_emu10k1_fx8010_control_gpr *gctl;
    637662    int err;
    638663
     
    682707}
    683708
    684 static void snd_emu10k1_ctl_private_free(snd_kcontrol_t *kctl)
     709static void snd_emu10k1_ctl_private_free(struct snd_kcontrol *kctl)
    685710{
    686711    struct snd_emu10k1_fx8010_ctl *ctl;
     
    692717}
    693718
    694 static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     719static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
     720                                    struct snd_emu10k1_fx8010_code *icode)
    695721{
    696722    unsigned int i, j;
    697     emu10k1_fx8010_control_gpr_t *_gctl;
    698     emu10k1_fx8010_control_gpr_t *gctl;
     723    struct snd_emu10k1_fx8010_control_gpr __user *_gctl;
     724    struct snd_emu10k1_fx8010_control_gpr *gctl;
    699725    struct snd_emu10k1_fx8010_ctl *ctl, *nctl;
    700     snd_kcontrol_new_t knew;
    701     snd_kcontrol_t *kctl;
    702     snd_ctl_elem_value_t *val;
     726    struct snd_kcontrol_new knew;
     727    struct snd_kcontrol *kctl;
     728    struct snd_ctl_elem_value *val;
    703729    int err = 0;
    704730
    705     val = (snd_ctl_elem_value_t *)kmalloc(sizeof(*val), GFP_KERNEL);
     731    val = kmalloc(sizeof(*val), GFP_KERNEL);
    706732    gctl = kmalloc(sizeof(*gctl), GFP_KERNEL);
    707733    nctl = kmalloc(sizeof(*nctl), GFP_KERNEL);
     
    717743            goto __error;
    718744        }
    719         snd_runtime_check(gctl->id.iface == SNDRV_CTL_ELEM_IFACE_MIXER ||
    720                           gctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM, err = -EINVAL; goto __error);
    721         snd_runtime_check(gctl->id.name[0] != '\0', err = -EINVAL; goto __error);
     745        if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
     746            gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
     747            err = -EINVAL;
     748            goto __error;
     749        }
     750        if (! gctl->id.name[0]) {
     751            err = -EINVAL;
     752            goto __error;
     753        }
    722754        ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
    723755        memset(&knew, 0, sizeof(knew));
     
    728760        knew.subdevice = gctl->id.subdevice;
    729761        knew.info = snd_emu10k1_gpr_ctl_info;
     762        if (gctl->tlv.p) {
     763            knew.tlv.p = gctl->tlv.p;
     764            knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
     765                SNDRV_CTL_ELEM_ACCESS_TLV_READ;
     766        }
    730767        knew.get = snd_emu10k1_gpr_ctl_get;
    731768        knew.put = snd_emu10k1_gpr_ctl_put;
     
    742779        nctl->translation = gctl->translation;
    743780        if (ctl == NULL) {
    744             ctl = (struct snd_emu10k1_fx8010_ctl *)kmalloc(sizeof(*ctl), GFP_KERNEL);
     781            ctl = kmalloc(sizeof(*ctl), GFP_KERNEL);
    745782            if (ctl == NULL) {
    746783                err = -ENOMEM;
     
    773810}
    774811
    775 static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     812static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu,
     813                                    struct snd_emu10k1_fx8010_code *icode)
    776814{
    777815    unsigned int i;
    778     snd_ctl_elem_id_t *_id, id;
     816    struct snd_ctl_elem_id id;
     817    struct snd_ctl_elem_id __user *_id;
    779818    struct snd_emu10k1_fx8010_ctl *ctl;
    780     snd_card_t *card = emu->card;
     819    struct snd_card *card = emu->card;
    781820
    782821    for (i = 0, _id = icode->gpr_del_controls;
    783822         i < icode->gpr_del_control_count; i++, _id++) {
    784         snd_runtime_check(copy_from_user(&id, _id, sizeof(id)) == 0, return -EFAULT);
     823        if (copy_from_user(&id, _id, sizeof(id)))
     824            return -EFAULT;
    785825        down_write(&card->controls_rwsem);
    786826        ctl = snd_emu10k1_look_for_ctl(emu, &id);
     
    792832}
    793833
    794 static int snd_emu10k1_list_controls(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     834static int snd_emu10k1_list_controls(struct snd_emu10k1 *emu,
     835                                     struct snd_emu10k1_fx8010_code *icode)
    795836{
    796837    unsigned int i = 0, j;
    797838    unsigned int total = 0;
    798     emu10k1_fx8010_control_gpr_t *gctl;
    799     emu10k1_fx8010_control_gpr_t *_gctl;
     839    struct snd_emu10k1_fx8010_control_gpr *gctl;
     840    struct snd_emu10k1_fx8010_control_gpr __user *_gctl;
    800841    struct snd_emu10k1_fx8010_ctl *ctl;
    801     snd_ctl_elem_id_t *id;
     842    struct snd_ctl_elem_id *id;
    802843    struct list_head *list;
    803844
     
    840881}
    841882
    842 static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     883static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,
     884                                  struct snd_emu10k1_fx8010_code *icode)
    843885{
    844886    int err = 0;
     
    871913}
    872914
    873 static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu, emu10k1_fx8010_code_t *icode)
     915static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu,
     916                                  struct snd_emu10k1_fx8010_code *icode)
    874917{
    875918    int err;
     
    889932}
    890933
    891 static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu, emu10k1_fx8010_pcm_t *ipcm)
     934static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu,
     935                                 struct snd_emu10k1_fx8010_pcm_rec *ipcm)
    892936{
    893937    unsigned int i;
     
    934978}
    935979
    936 static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu, emu10k1_fx8010_pcm_t *ipcm)
     980static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu,
     981                                 struct snd_emu10k1_fx8010_pcm_rec *ipcm)
    937982{
    938983    unsigned int i;
     
    9681013#define SND_EMU10K1_CAPTURE_CHANNELS    4
    9691014
    970 static void __devinit snd_emu10k1_init_mono_control(emu10k1_fx8010_control_gpr_t *ctl, const char *name, int gpr, int defval)
     1015static void __devinit
     1016snd_emu10k1_init_mono_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
     1017                              const char *name, int gpr, int defval)
    9711018{
    9721019    ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     
    9761023    ctl->min = 0;
    9771024    ctl->max = 100;
     1025    ctl->tlv.p = snd_emu10k1_db_scale1;
    9781026    ctl->translation = EMU10K1_GPR_TRANSLATION_TABLE100;
    9791027}
    9801028
    981 static void __devinit snd_emu10k1_init_stereo_control(emu10k1_fx8010_control_gpr_t *ctl, const char *name, int gpr, int defval)
     1029static void __devinit
     1030snd_emu10k1_init_stereo_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
     1031                                const char *name, int gpr, int defval)
    9821032{
    9831033    ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     
    9881038    ctl->min = 0;
    9891039    ctl->max = 100;
     1040    ctl->tlv.p = snd_emu10k1_db_scale1;
    9901041    ctl->translation = EMU10K1_GPR_TRANSLATION_TABLE100;
    9911042}
    9921043
    993 static void __devinit snd_emu10k1_init_mono_onoff_control(emu10k1_fx8010_control_gpr_t *ctl, const char *name, int gpr, int defval)
     1044static void __devinit
     1045snd_emu10k1_init_mono_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
     1046                                    const char *name, int gpr, int defval)
    9941047{
    9951048    ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     
    10021055}
    10031056
    1004 static void __devinit snd_emu10k1_init_stereo_onoff_control(emu10k1_fx8010_control_gpr_t *ctl, const char *name, int gpr, int defval)
     1057static void __devinit
     1058snd_emu10k1_init_stereo_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
     1059                                      const char *name, int gpr, int defval)
    10051060{
    10061061    ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     
    10141069}
    10151070
     1071static int snd_emu10k1_audigy_dsp_convert_32_to_2x16(
     1072                                                     struct snd_emu10k1_fx8010_code *icode,
     1073                                                     u32 *ptr, int tmp, int bit_shifter16,
     1074                                                     int reg_in, int reg_out)
     1075{
     1076    A_OP(icode, ptr, iACC3, A_GPR(tmp + 1), reg_in, A_C_00000000, A_C_00000000);
     1077    A_OP(icode, ptr, iANDXOR, A_GPR(tmp), A_GPR(tmp + 1), A_GPR(bit_shifter16 - 1), A_C_00000000);
     1078    A_OP(icode, ptr, iTSTNEG, A_GPR(tmp + 2), A_GPR(tmp), A_C_80000000, A_GPR(bit_shifter16 - 2));
     1079    A_OP(icode, ptr, iANDXOR, A_GPR(tmp + 2), A_GPR(tmp + 2), A_C_80000000, A_C_00000000);
     1080    A_OP(icode, ptr, iANDXOR, A_GPR(tmp), A_GPR(tmp), A_GPR(bit_shifter16 - 3), A_C_00000000);
     1081    A_OP(icode, ptr, iMACINT0, A_GPR(tmp), A_C_00000000, A_GPR(tmp), A_C_00010000);
     1082    A_OP(icode, ptr, iANDXOR, reg_out, A_GPR(tmp), A_C_ffffffff, A_GPR(tmp + 2));
     1083    A_OP(icode, ptr, iACC3, reg_out + 1, A_GPR(tmp + 1), A_C_00000000, A_C_00000000);
     1084    return 1;
     1085}
    10161086
    10171087/*
     
    10221092{
    10231093    int err, i, z, gpr, nctl;
     1094    int bit_shifter16;
    10241095    const int playback = 10;
    10251096    const int capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS * 2); /* we reserve 10 voices */
     
    10271098    const int tmp = 0x88;
    10281099    u32 ptr;
    1029     emu10k1_fx8010_code_t *icode = NULL;
    1030     emu10k1_fx8010_control_gpr_t *controls = NULL, *ctl;
     1100    struct snd_emu10k1_fx8010_code *icode = NULL;
     1101    struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    10311102    u32 *gpr_map;
    10321103    mm_segment_t seg;
    10331104
    1034     spin_lock_init(&emu->fx8010.irq_lock);
    1035     INIT_LIST_HEAD(&emu->fx8010.gpr_ctl);
    1036 
    1037     if ((icode = (emu10k1_fx8010_code_t *)kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL ||
    1038         (icode->gpr_map = (u_int32_t __user *)kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
    1039         (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, sizeof(*controls), GFP_KERNEL)) == NULL) {
     1105    if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL ||
     1106        (icode->gpr_map = (u_int32_t __user *)
     1107         kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
     1108                GFP_KERNEL)) == NULL ||
     1109        (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1110                            sizeof(*controls), GFP_KERNEL)) == NULL) {
    10401111        err = -ENOMEM;
    10411112        goto __err;
    10421113    }
    1043     gpr_map = (u32 *)icode->gpr_map;
     1114    gpr_map = (u32 __force *)icode->gpr_map;
    10441115
    10451116    icode->tram_data_map = icode->gpr_map + 512;
     
    10591130    nctl = 0;
    10601131    gpr = stereo_mix + 10;
     1132    gpr_map[gpr++] = 0x00007fff;
     1133    gpr_map[gpr++] = 0x00008000;
     1134    gpr_map[gpr++] = 0x0000ffff;
     1135    bit_shifter16 = gpr;
    10611136
    10621137    /* stop FX processor */
    10631138    snd_emu10k1_ptr_write(emu, A_DBG, 0, (emu->fx8010.dbg = 0) | A_DBG_SINGLE_STEP);
    10641139
     1140#if 1
    10651141    /* PCM front Playback Volume (independent from stereo mix) */
    10661142    A_OP(icode, &ptr, iMAC0, A_GPR(playback), A_C_00000000, A_GPR(gpr), A_FXBUS(FXBUS_PCM_LEFT_FRONT));
     
    11021178    gpr += 2;
    11031179
    1104     /* Music Playback */
     1180    /* Synth Playback */
    11051181    A_OP(icode, &ptr, iMAC0, A_GPR(stereo_mix+0), A_GPR(stereo_mix+0), A_GPR(gpr), A_FXBUS(FXBUS_MIDI_LEFT));
    11061182    A_OP(icode, &ptr, iMAC0, A_GPR(stereo_mix+1), A_GPR(stereo_mix+1), A_GPR(gpr+1), A_FXBUS(FXBUS_MIDI_RIGHT));
    1107     snd_emu10k1_init_stereo_control(&controls[nctl++], "Music Playback Volume", gpr, 100);
     1183    snd_emu10k1_init_stereo_control(&controls[nctl++], "Synth Playback Volume", gpr, 100);
    11081184    gpr += 2;
    11091185
     
    11141190    gpr += 2;
    11151191
    1116     /* Music Capture */
     1192    /* Synth Capture */
    11171193    A_OP(icode, &ptr, iMAC0, A_GPR(capture+0), A_GPR(capture+0), A_GPR(gpr), A_FXBUS(FXBUS_MIDI_LEFT));
    11181194    A_OP(icode, &ptr, iMAC0, A_GPR(capture+1), A_GPR(capture+1), A_GPR(gpr+1), A_FXBUS(FXBUS_MIDI_RIGHT));
    1119     snd_emu10k1_init_stereo_control(&controls[nctl++], "Music Capture Volume", gpr, 0);
     1195    snd_emu10k1_init_stereo_control(&controls[nctl++], "Synth Capture Volume", gpr, 0);
    11201196    gpr += 2;
    11211197
     
    11261202    A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
    11271203
    1128     /* AC'97 Playback Volume - used only for mic */
     1204    /* emu1212 DSP 0 and DSP 1 Capture */
     1205    if (emu->card_capabilities->emu1010) {
     1206        A_OP(icode, &ptr, iMAC0, A_GPR(capture+0), A_GPR(capture+0), A_GPR(gpr), A_P16VIN(0x0));
     1207        A_OP(icode, &ptr, iMAC0, A_GPR(capture+1), A_GPR(capture+1), A_GPR(gpr+1), A_P16VIN(0x1));
     1208        snd_emu10k1_init_stereo_control(&controls[nctl++], "EMU Capture Volume", gpr, 0);
     1209        gpr += 2;
     1210    }
     1211    /* AC'97 Playback Volume - used only for mic (renamed later) */
    11291212    A_ADD_VOLUME_IN(stereo_mix, gpr, A_EXTIN_AC97_L);
    11301213    A_ADD_VOLUME_IN(stereo_mix+1, gpr+1, A_EXTIN_AC97_R);
     
    11581241    A_ADD_VOLUME_IN(stereo_mix, gpr, A_EXTIN_OPT_SPDIF_L);
    11591242    A_ADD_VOLUME_IN(stereo_mix+1, gpr+1, A_EXTIN_OPT_SPDIF_R);
    1160     snd_emu10k1_init_stereo_control(&controls[nctl++], "IEC958 Optical Playback Volume", gpr, 0);
     1243    snd_emu10k1_init_stereo_control(&controls[nctl++], SNDRV_CTL_NAME_IEC958("Optical ",PLAYBACK,VOLUME), gpr, 0);
    11611244    gpr += 2;
    11621245    /* Optical SPDIF Capture Volume */
    11631246    A_ADD_VOLUME_IN(capture, gpr, A_EXTIN_OPT_SPDIF_L);
    11641247    A_ADD_VOLUME_IN(capture+1, gpr+1, A_EXTIN_OPT_SPDIF_R);
    1165     snd_emu10k1_init_stereo_control(&controls[nctl++], "IEC958 Optical Capture Volume", gpr, 0);
     1248    snd_emu10k1_init_stereo_control(&controls[nctl++], SNDRV_CTL_NAME_IEC958("Optical ",CAPTURE,VOLUME), gpr, 0);
    11661249    gpr += 2;
    11671250
     
    12651348    A_OP(icode, &ptr, iACC3, A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + 4), A_GPR(playback + 4), A_C_00000000, A_C_00000000); /* center */
    12661349    A_OP(icode, &ptr, iACC3, A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + 5), A_GPR(playback + 5), A_C_00000000, A_C_00000000); /* LFE */
    1267 
    12681350    if (emu->card_capabilities->spk71) {
    12691351        A_OP(icode, &ptr, iACC3, A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + 6), A_GPR(playback + 6), A_C_00000000, A_C_00000000); /* side left */
    12701352        A_OP(icode, &ptr, iACC3, A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + 7), A_GPR(playback + 7), A_C_00000000, A_C_00000000); /* side right */
    12711353    }
     1354
    12721355
    12731356    ctl = &controls[nctl + 0];
     
    13501433    A_OP(icode, &ptr, iMAC0, A_GPR(playback+6+SND_EMU10K1_PLAYBACK_CHANNELS), A_C_00000000, A_GPR(gpr), A_GPR(playback+6+SND_EMU10K1_PLAYBACK_CHANNELS));
    13511434    A_OP(icode, &ptr, iMAC0, A_GPR(playback+7+SND_EMU10K1_PLAYBACK_CHANNELS), A_C_00000000, A_GPR(gpr), A_GPR(playback+7+SND_EMU10K1_PLAYBACK_CHANNELS));
    1352     snd_emu10k1_init_stereo_control(&controls[nctl++], "Wave Master Playback Volume", gpr, 0);
    1353     //snd_emu10k1_init_mono_control(&controls[nctl++], "Wave Master Playback Volume", gpr, 0);
     1435    snd_emu10k1_init_mono_control(&controls[nctl++], "Wave Master Playback Volume", gpr, 0);
    13541436    gpr += 2;
    13551437
     
    13591441    A_PUT_OUTPUT(A_EXTOUT_ACENTER, playback+4 + SND_EMU10K1_PLAYBACK_CHANNELS);
    13601442    A_PUT_OUTPUT(A_EXTOUT_ALFE, playback+5 + SND_EMU10K1_PLAYBACK_CHANNELS);
    1361 
    13621443    if (emu->card_capabilities->spk71)
    13631444        A_PUT_STEREO_OUTPUT(A_EXTOUT_ASIDE_L, A_EXTOUT_ASIDE_R, playback+6 + SND_EMU10K1_PLAYBACK_CHANNELS);
     
    13681449    /* digital outputs */
    13691450    /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */
     1451    if (emu->card_capabilities->emu1010) {
     1452        /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */
     1453        snd_printk("EMU outputs on\n");
     1454        for (z = 0; z < 8; z++) {
     1455            A_OP(icode, &ptr, iACC3, A_EMU32OUTL(z), A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + z), A_C_00000000, A_C_00000000);
     1456        }
     1457    }
    13701458
    13711459    /* IEC958 Optical Raw Playback Switch */
     
    13901478        }
    13911479    }
    1392     snd_emu10k1_init_stereo_onoff_control(controls + nctl++, "IEC958 Optical Raw Playback Switch", gpr, 0);
     1480    snd_emu10k1_init_stereo_onoff_control(controls + nctl++, SNDRV_CTL_NAME_IEC958("Optical Raw ",PLAYBACK,SWITCH), gpr, 0);
    13931481    gpr += 2;
    13941482
     
    13981486
    13991487    /* ADC buffer */
     1488#ifdef EMU10K1_CAPTURE_DIGITAL_OUT
     1489    A_PUT_STEREO_OUTPUT(A_EXTOUT_ADC_CAP_L, A_EXTOUT_ADC_CAP_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS);
     1490#else
    14001491    A_PUT_OUTPUT(A_EXTOUT_ADC_CAP_L, capture);
    14011492    A_PUT_OUTPUT(A_EXTOUT_ADC_CAP_R, capture+1);
    1402 
    1403     /* EFX capture - capture the 16 EXTINs */
    1404     for (z = 0; z < 16; z++) {
    1405         A_OP(icode, &ptr, iACC3, A_FXBUS2(z), A_C_00000000, A_C_00000000, A_EXTIN(z));
    1406     }
    1407 
     1493#endif
     1494
     1495    if (emu->card_capabilities->emu1010) {
     1496        snd_printk("EMU inputs on\n");
     1497        /* Capture 8 channels of S32_LE sound */
     1498
     1499        /* printk("emufx.c: gpr=0x%x, tmp=0x%x\n",gpr, tmp); */
     1500        /* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */
     1501        /* A_P16VIN(0) is delayed by one sample,
     1502         * so all other A_P16VIN channels will need to also be delayed
     1503         */
     1504        /* Left ADC in. 1 of 2 */
     1505        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_P16VIN(0x0), A_FXBUS2(0) );
     1506        /* Right ADC in 1 of 2 */
     1507        gpr_map[gpr++] = 0x00000000;
     1508        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(2) );
     1509        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x1), A_C_00000000, A_C_00000000);
     1510        gpr_map[gpr++] = 0x00000000;
     1511        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(4) );
     1512        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x2), A_C_00000000, A_C_00000000);
     1513        gpr_map[gpr++] = 0x00000000;
     1514        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(6) );
     1515        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x3), A_C_00000000, A_C_00000000);
     1516        /* For 96kHz mode */
     1517        /* Left ADC in. 2 of 2 */
     1518        gpr_map[gpr++] = 0x00000000;
     1519        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(0x8) );
     1520        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x4), A_C_00000000, A_C_00000000);
     1521        /* Right ADC in 2 of 2 */
     1522        gpr_map[gpr++] = 0x00000000;
     1523        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(0xa) );
     1524        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x5), A_C_00000000, A_C_00000000);
     1525        gpr_map[gpr++] = 0x00000000;
     1526        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(0xc) );
     1527        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x6), A_C_00000000, A_C_00000000);
     1528        gpr_map[gpr++] = 0x00000000;
     1529        snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, bit_shifter16, A_GPR(gpr - 1), A_FXBUS2(0xe) );
     1530        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 1), A_P16VIN(0x7), A_C_00000000, A_C_00000000);
     1531
     1532#if 0
     1533        for (z = 4; z < 8; z++) {
     1534            A_OP(icode, &ptr, iACC3, A_FXBUS2(z), A_C_00000000, A_C_00000000, A_C_00000000);
     1535        }
     1536        for (z = 0xc; z < 0x10; z++) {
     1537            A_OP(icode, &ptr, iACC3, A_FXBUS2(z), A_C_00000000, A_C_00000000, A_C_00000000);
     1538        }
     1539#endif
     1540    } else {
     1541
     1542        /* EFX capture - capture the 16 EXTINs */
     1543        /* Capture 16 channels of S16_LE sound */
     1544        for (z = 0; z < 16; z++) {
     1545            A_OP(icode, &ptr, iACC3, A_FXBUS2(z), A_C_00000000, A_C_00000000, A_EXTIN(z));
     1546        }
     1547    }
     1548
     1549#endif /* JCD test */
    14081550    /*
    14091551     * ok, set up done..
     
    14211563    seg = snd_enter_user();
    14221564    icode->gpr_add_control_count = nctl;
    1423     icode->gpr_add_controls = (emu10k1_fx8010_control_gpr_t __user *)controls;
     1565    icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
    14241566    err = snd_emu10k1_icode_poke(emu, icode);
    14251567    snd_leave_user(seg);
     
    14281570    kfree(controls);
    14291571    if (icode != NULL) {
    1430         kfree((void *)icode->gpr_map);
     1572        kfree((void __force *)icode->gpr_map);
    14311573        kfree(icode);
    14321574    }
     
    14411583/* when volume = max, then copy only to avoid volume modification */
    14421584/* with iMAC0 (negative values) */
    1443 static void __devinit _volume(emu10k1_fx8010_code_t *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1585static void __devinit _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    14441586{
    14451587    OP(icode, ptr, iMAC0, dst, C_00000000, src, vol);
     
    14481590    OP(icode, ptr, iACC3, dst, src, C_00000000, C_00000000);
    14491591}
    1450 static void __devinit _volume_add(emu10k1_fx8010_code_t *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1592static void __devinit _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    14511593{
    14521594    OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    14561598    OP(icode, ptr, iMAC0, dst, dst, src, vol);
    14571599}
    1458 static void __devinit _volume_out(emu10k1_fx8010_code_t *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1600static void __devinit _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    14591601{
    14601602    OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    14911633    int err, i, z, gpr, tmp, playback, capture;
    14921634    u32 ptr;
    1493     emu10k1_fx8010_code_t *icode;
    1494     emu10k1_fx8010_pcm_t *ipcm = NULL;
    1495     emu10k1_fx8010_control_gpr_t *controls = NULL, *ctl;
     1635    struct snd_emu10k1_fx8010_code *icode;
     1636    struct snd_emu10k1_fx8010_pcm_rec *ipcm = NULL;
     1637    struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    14961638    u32 *gpr_map;
    14971639    mm_segment_t seg;
    14981640
    1499     spin_lock_init(&emu->fx8010.irq_lock);
    1500     INIT_LIST_HEAD(&emu->fx8010.gpr_ctl);
    1501 
    1502     if ((icode = (emu10k1_fx8010_code_t *)kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL)
     1641    if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL)
    15031642        return -ENOMEM;
    1504     if ((icode->gpr_map = (u_int32_t __user *)kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
    1505         (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, sizeof(emu10k1_fx8010_control_gpr_t), GFP_KERNEL)) == NULL ||
    1506         (ipcm = (emu10k1_fx8010_pcm_t *)kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) {
     1643    if ((icode->gpr_map = (u_int32_t __user *)
     1644         kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t),
     1645                 GFP_KERNEL)) == NULL ||
     1646        (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1647                            sizeof(struct snd_emu10k1_fx8010_control_gpr),
     1648                            GFP_KERNEL)) == NULL ||
     1649        (ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) {
    15071650        err = -ENOMEM;
    15081651        goto __err;
    15091652    }
    1510     gpr_map = (u32 *)icode->gpr_map;
     1653    gpr_map = (u32 __force *)icode->gpr_map;
    15111654
    15121655    icode->tram_data_map = icode->gpr_map + 256;
     
    15651708    ipcm->etram[1] = 1;
    15661709
    1567         gpr_map[gpr + 0] = 0xfffff000;
    1568         gpr_map[gpr + 1] = 0xffff0000;
    1569         gpr_map[gpr + 2] = 0x70000000;
    1570         gpr_map[gpr + 3] = 0x00000007;
    1571         gpr_map[gpr + 4] = 0x001f << 11;
    1572         gpr_map[gpr + 5] = 0x001c << 11;
    1573         gpr_map[gpr + 6] = (0x22  - 0x01) - 1;  /* skip at 01 to 22 */
    1574         gpr_map[gpr + 7] = (0x22  - 0x06) - 1;  /* skip at 06 to 22 */
    1575         gpr_map[gpr + 8] = 0x2000000 + (2<<11);
    1576         gpr_map[gpr + 9] = 0x4000000 + (2<<11);
    1577         gpr_map[gpr + 10] = 1<<11;
    1578         gpr_map[gpr + 11] = (0x24 - 0x0a) - 1;  /* skip at 0a to 24 */
    1579         gpr_map[gpr + 12] = 0;
     1710    gpr_map[gpr + 0] = 0xfffff000;
     1711    gpr_map[gpr + 1] = 0xffff0000;
     1712    gpr_map[gpr + 2] = 0x70000000;
     1713    gpr_map[gpr + 3] = 0x00000007;
     1714    gpr_map[gpr + 4] = 0x001f << 11;
     1715    gpr_map[gpr + 5] = 0x001c << 11;
     1716    gpr_map[gpr + 6] = (0x22  - 0x01) - 1;      /* skip at 01 to 22 */
     1717    gpr_map[gpr + 7] = (0x22  - 0x06) - 1;      /* skip at 06 to 22 */
     1718    gpr_map[gpr + 8] = 0x2000000 + (2<<11);
     1719    gpr_map[gpr + 9] = 0x4000000 + (2<<11);
     1720    gpr_map[gpr + 10] = 1<<11;
     1721    gpr_map[gpr + 11] = (0x24 - 0x0a) - 1;      /* skip at 0a to 24 */
     1722    gpr_map[gpr + 12] = 0;
    15801723
    15811724    /* if the trigger flag is not set, skip */
     
    16581801    gpr += 4;
    16591802
    1660     /* Music Playback Volume */
     1803    /* Synth Playback Volume */
    16611804    for (z = 0; z < 2; z++)
    16621805        VOLUME_ADD(icode, &ptr, playback + z, 2 + z, gpr + z);
    1663     snd_emu10k1_init_stereo_control(controls + i++, "Music Playback Volume", gpr, 100);
    1664     gpr += 2;
    1665 
    1666     /* Music Capture Volume + Switch */
     1806    snd_emu10k1_init_stereo_control(controls + i++, "Synth Playback Volume", gpr, 100);
     1807    gpr += 2;
     1808
     1809    /* Synth Capture Volume + Switch */
    16671810    for (z = 0; z < 2; z++) {
    16681811        SWITCH(icode, &ptr, tmp + 0, 2 + z, gpr + 2 + z);
    16691812        VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
    16701813    }
    1671     snd_emu10k1_init_stereo_control(controls + i++, "Music Capture Volume", gpr, 0);
    1672     snd_emu10k1_init_stereo_onoff_control(controls + i++, "Music Capture Switch", gpr + 2, 0);
     1814    snd_emu10k1_init_stereo_control(controls + i++, "Synth Capture Volume", gpr, 0);
     1815    snd_emu10k1_init_stereo_onoff_control(controls + i++, "Synth Capture Switch", gpr + 2, 0);
    16731816    gpr += 4;
    16741817
     
    17301873        for (z = 0; z < 2; z++)
    17311874            VOLUME_ADDIN(icode, &ptr, playback + z, EXTIN_SPDIF_CD_L + z, gpr + z);
    1732         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 TTL Playback Volume", gpr, 0);
     1875        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("TTL ",PLAYBACK,VOLUME), gpr, 0);
    17331876        gpr += 2;
    17341877
     
    17381881            VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
    17391882        }
    1740         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 TTL Capture Volume", gpr, 0);
    1741         snd_emu10k1_init_stereo_onoff_control(controls + i++, "IEC958 TTL Capture Switch", gpr + 2, 0);
     1883        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("TTL ",CAPTURE,VOLUME), gpr, 0);
     1884        snd_emu10k1_init_stereo_onoff_control(controls + i++, SNDRV_CTL_NAME_IEC958("TTL ",CAPTURE,SWITCH), gpr + 2, 0);
    17421885        gpr += 4;
    17431886    }
     
    17641907        for (z = 0; z < 2; z++)
    17651908            VOLUME_ADDIN(icode, &ptr, playback + z, EXTIN_TOSLINK_L + z, gpr + z);
    1766         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 LiveDrive Playback Volume", gpr, 0);
     1909        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("LiveDrive ",PLAYBACK,VOLUME), gpr, 0);
    17671910        gpr += 2;
    17681911
     
    17721915            VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
    17731916        }
    1774         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 LiveDrive Capture Volume", gpr, 0);
    1775         snd_emu10k1_init_stereo_onoff_control(controls + i++, "IEC958 LiveDrive Capture Switch", gpr + 2, 0);
     1917        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("LiveDrive ",CAPTURE,VOLUME), gpr, 0);
     1918        snd_emu10k1_init_stereo_onoff_control(controls + i++, SNDRV_CTL_NAME_IEC958("LiveDrive ",CAPTURE,SWITCH), gpr + 2, 0);
    17761919        gpr += 4;
    17771920    }
     
    17981941        for (z = 0; z < 2; z++)
    17991942            VOLUME_ADDIN(icode, &ptr, playback + z, EXTIN_COAX_SPDIF_L + z, gpr + z);
    1800         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 Coaxial Playback Volume", gpr, 0);
     1943        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("Coaxial ",PLAYBACK,VOLUME), gpr, 0);
    18011944        gpr += 2;
    18021945
     
    18061949            VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
    18071950        }
    1808         snd_emu10k1_init_stereo_control(controls + i++, "IEC958 Coaxial Capture Volume", gpr, 0);
    1809         snd_emu10k1_init_stereo_onoff_control(controls + i++, "IEC958 Coaxial Capture Switch", gpr + 2, 0);
     1951        snd_emu10k1_init_stereo_control(controls + i++, SNDRV_CTL_NAME_IEC958("Coaxial ",CAPTURE,VOLUME), gpr, 0);
     1952        snd_emu10k1_init_stereo_onoff_control(controls + i++, SNDRV_CTL_NAME_IEC958("Coaxial ",CAPTURE,SWITCH), gpr + 2, 0);
    18101953        gpr += 4;
    18111954    }
     
    19342077        }
    19352078
    1936         snd_emu10k1_init_stereo_onoff_control(controls + i++, "IEC958 Optical Raw Playback Switch", gpr, 0);
     2079        snd_emu10k1_init_stereo_onoff_control(controls + i++, SNDRV_CTL_NAME_IEC958("Optical Raw ",PLAYBACK,SWITCH), gpr, 0);
    19372080        gpr += 2;
    19382081    }
     
    20352178    seg = snd_enter_user();
    20362179    icode->gpr_add_control_count = i;
    2037     icode->gpr_add_controls = (emu10k1_fx8010_control_gpr_t __user *)controls;
     2180    icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
    20382181    err = snd_emu10k1_icode_poke(emu, icode);
    20392182    snd_leave_user(seg);
     
    20442187    kfree(controls);
    20452188    if (icode != NULL) {
    2046         kfree((void *)icode->gpr_map);
     2189        kfree((void __force *)icode->gpr_map);
    20472190        kfree(icode);
    20482191    }
     
    20522195int __devinit snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
    20532196{
     2197    spin_lock_init(&emu->fx8010.irq_lock);
     2198    INIT_LIST_HEAD(&emu->fx8010.gpr_ctl);
    20542199    if (emu->audigy)
    20552200        return _snd_emu10k1_audigy_init_efx(emu);
     
    20672212}
    20682213
    2069 #if 0 // FIXME: who use them?
     2214#if 0 /* FIXME: who use them? */
    20702215int snd_emu10k1_fx8010_tone_control_activate(struct snd_emu10k1 *emu, int output)
    20712216{
    2072     snd_runtime_check(output >= 0 && output < 6, return -EINVAL);
     2217    if (output < 0 || output >= 6)
     2218        return -EINVAL;
    20732219    snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1);
    20742220    return 0;
     
    20772223int snd_emu10k1_fx8010_tone_control_deactivate(struct snd_emu10k1 *emu, int output)
    20782224{
    2079     snd_runtime_check(output >= 0 && output < 6, return -EINVAL);
     2225    if (output < 0 || output >= 6)
     2226        return -EINVAL;
    20802227    snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0);
    20812228    return 0;
     
    20972244        size = 0x2000 << size_reg;
    20982245    }
    2099     if (emu->fx8010.etram_pages.bytes == size)
     2246    if ((emu->fx8010.etram_pages.bytes / 2) == size)
    21002247        return 0;
    21012248    spin_lock_irq(&emu->emu_lock);
     
    21252272}
    21262273
    2127 static int snd_emu10k1_fx8010_open(snd_hwdep_t * hw, struct file *file)
     2274static int snd_emu10k1_fx8010_open(struct snd_hwdep * hw, struct file *file)
    21282275{
    21292276    return 0;
     
    21382285}
    21392286
    2140 static int snd_emu10k1_fx8010_info(struct snd_emu10k1 *emu, emu10k1_fx8010_info_t *info)
     2287static int snd_emu10k1_fx8010_info(struct snd_emu10k1 *emu,
     2288                                   struct snd_emu10k1_fx8010_info *info)
    21412289{
    21422290    char **fxbus, **extin, **extout;
     
    21642312}
    21652313
    2166 static int snd_emu10k1_fx8010_ioctl(snd_hwdep_t * hw, struct file *file, unsigned int cmd, unsigned long arg)
     2314static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg)
    21672315{
    21682316    struct snd_emu10k1 *emu = hw->private_data;
    2169     emu10k1_fx8010_info_t *info;
    2170     emu10k1_fx8010_code_t *icode;
    2171     emu10k1_fx8010_pcm_t *ipcm;
     2317    struct snd_emu10k1_fx8010_info *info;
     2318    struct snd_emu10k1_fx8010_code *icode;
     2319    struct snd_emu10k1_fx8010_pcm_rec *ipcm;
    21722320    unsigned int addr;
     2321    void __user *argp = (void __user *)arg;
    21732322    int res;
    21742323
    21752324    switch (cmd) {
    21762325    case SNDRV_EMU10K1_IOCTL_INFO:
    2177         info = (emu10k1_fx8010_info_t *)kmalloc(sizeof(*info), GFP_KERNEL);
     2326        info = kmalloc(sizeof(*info), GFP_KERNEL);
    21782327        if (!info)
    21792328            return -ENOMEM;
     
    21822331            return res;
    21832332        }
    2184         if (copy_to_user((void *)arg, info, sizeof(*info))) {
     2333        if (copy_to_user(argp, info, sizeof(*info))) {
    21852334            kfree(info);
    21862335            return -EFAULT;
     
    21912340        if (!capable(CAP_SYS_ADMIN))
    21922341            return -EPERM;
    2193         icode = (emu10k1_fx8010_code_t *)kmalloc(sizeof(*icode), GFP_KERNEL);
     2342        icode = kmalloc(sizeof(*icode), GFP_KERNEL);
    21942343        if (icode == NULL)
    21952344            return -ENOMEM;
    2196         if (copy_from_user(icode, (void *)arg, sizeof(*icode))) {
     2345        if (copy_from_user(icode, argp, sizeof(*icode))) {
    21972346            kfree(icode);
    21982347            return -EFAULT;
     
    22022351        return res;
    22032352    case SNDRV_EMU10K1_IOCTL_CODE_PEEK:
    2204         icode = (emu10k1_fx8010_code_t *)kmalloc(sizeof(*icode), GFP_KERNEL);
     2353        icode = kmalloc(sizeof(*icode), GFP_KERNEL);
    22052354        if (icode == NULL)
    22062355            return -ENOMEM;
    2207         if (copy_from_user(icode, (void *)arg, sizeof(*icode))) {
     2356        if (copy_from_user(icode, argp, sizeof(*icode))) {
    22082357            kfree(icode);
    22092358            return -EFAULT;
    22102359        }
    22112360        res = snd_emu10k1_icode_peek(emu, icode);
    2212         if (res == 0 && copy_to_user((void *)arg, icode, sizeof(*icode))) {
     2361        if (res == 0 && copy_to_user(argp, icode, sizeof(*icode))) {
    22132362            kfree(icode);
    22142363            return -EFAULT;
     
    22172366        return res;
    22182367    case SNDRV_EMU10K1_IOCTL_PCM_POKE:
    2219         ipcm = (emu10k1_fx8010_pcm_t *)kmalloc(sizeof(*ipcm), GFP_KERNEL);
     2368        ipcm = kmalloc(sizeof(*ipcm), GFP_KERNEL);
    22202369        if (ipcm == NULL)
    22212370            return -ENOMEM;
    2222         if (copy_from_user(ipcm, (void *)arg, sizeof(*ipcm))) {
     2371        if (copy_from_user(ipcm, argp, sizeof(*ipcm))) {
    22232372            kfree(ipcm);
    22242373            return -EFAULT;
     
    22282377        return res;
    22292378    case SNDRV_EMU10K1_IOCTL_PCM_PEEK:
    2230         ipcm = (emu10k1_fx8010_pcm_t *)kzalloc(sizeof(*ipcm), GFP_KERNEL);
     2379        ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL);
    22312380        if (ipcm == NULL)
    22322381            return -ENOMEM;
    2233         if (copy_from_user(ipcm, (void *)arg, sizeof(*ipcm))) {
     2382        if (copy_from_user(ipcm, argp, sizeof(*ipcm))) {
    22342383            kfree(ipcm);
    22352384            return -EFAULT;
    22362385        }
    22372386        res = snd_emu10k1_ipcm_peek(emu, ipcm);
    2238         if (res == 0 && copy_to_user((void *)arg, ipcm, sizeof(*ipcm))) {
     2387        if (res == 0 && copy_to_user(argp, ipcm, sizeof(*ipcm))) {
    22392388            kfree(ipcm);
    22402389            return -EFAULT;
     
    22452394        if (!capable(CAP_SYS_ADMIN))
    22462395            return -EPERM;
    2247         if (get_user(addr, (unsigned int *)arg))
     2396        if (get_user(addr, (unsigned int __user *)argp))
    22482397            return -EFAULT;
    22492398        down(&emu->fx8010.lock);
     
    22832432        if (!capable(CAP_SYS_ADMIN))
    22842433            return -EPERM;
    2285         if (get_user(addr, (unsigned int *)arg))
     2434        if (get_user(addr, (unsigned int __user *)argp))
    22862435            return -EFAULT;
    22872436        if (addr > 0x1ff)
     
    23022451        else
    23032452            addr = snd_emu10k1_ptr_read(emu, DBG, 0);
    2304         if (put_user(addr, (unsigned int *)arg))
     2453        if (put_user(addr, (unsigned int __user *)argp))
    23052454            return -EFAULT;
    23062455        return 0;
     
    23092458}
    23102459
    2311 static int snd_emu10k1_fx8010_release(snd_hwdep_t * hw, struct file *file)
     2460static int snd_emu10k1_fx8010_release(struct snd_hwdep * hw, struct file *file)
    23122461{
    23132462    return 0;
    23142463}
    23152464
    2316 int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, snd_hwdep_t ** rhwdep)
    2317 {
    2318     snd_hwdep_t *hw;
     2465int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct snd_hwdep ** rhwdep)
     2466{
     2467    struct snd_hwdep *hw;
    23192468    int err;
    23202469
     
    23332482    return 0;
    23342483}
     2484
     2485#ifdef CONFIG_PM
     2486int __devinit snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
     2487{
     2488    int len;
     2489
     2490    len = emu->audigy ? 0x200 : 0x100;
     2491    emu->saved_gpr = kmalloc(len * 4, GFP_KERNEL);
     2492    if (! emu->saved_gpr)
     2493        return -ENOMEM;
     2494    len = emu->audigy ? 0x100 : 0xa0;
     2495    emu->tram_val_saved = kmalloc(len * 4, GFP_KERNEL);
     2496    emu->tram_addr_saved = kmalloc(len * 4, GFP_KERNEL);
     2497    if (! emu->tram_val_saved || ! emu->tram_addr_saved)
     2498        return -ENOMEM;
     2499    len = emu->audigy ? 2 * 1024 : 2 * 512;
     2500    emu->saved_icode = vmalloc(len * 4);
     2501    if (! emu->saved_icode)
     2502        return -ENOMEM;
     2503    return 0;
     2504}
     2505
     2506void snd_emu10k1_efx_free_pm_buffer(struct snd_emu10k1 *emu)
     2507{
     2508    kfree(emu->saved_gpr);
     2509    kfree(emu->tram_val_saved);
     2510    kfree(emu->tram_addr_saved);
     2511    vfree(emu->saved_icode);
     2512}
     2513
     2514/*
     2515 * save/restore GPR, TRAM and codes
     2516 */
     2517void snd_emu10k1_efx_suspend(struct snd_emu10k1 *emu)
     2518{
     2519    int i, len;
     2520
     2521    len = emu->audigy ? 0x200 : 0x100;
     2522    for (i = 0; i < len; i++)
     2523        emu->saved_gpr[i] = snd_emu10k1_ptr_read(emu, emu->gpr_base + i, 0);
     2524
     2525    len = emu->audigy ? 0x100 : 0xa0;
     2526    for (i = 0; i < len; i++) {
     2527        emu->tram_val_saved[i] = snd_emu10k1_ptr_read(emu, TANKMEMDATAREGBASE + i, 0);
     2528        emu->tram_addr_saved[i] = snd_emu10k1_ptr_read(emu, TANKMEMADDRREGBASE + i, 0);
     2529        if (emu->audigy) {
     2530            emu->tram_addr_saved[i] >>= 12;
     2531            emu->tram_addr_saved[i] |=
     2532                snd_emu10k1_ptr_read(emu, A_TANKMEMCTLREGBASE + i, 0) << 20;
     2533        }
     2534    }
     2535
     2536    len = emu->audigy ? 2 * 1024 : 2 * 512;
     2537    for (i = 0; i < len; i++)
     2538        emu->saved_icode[i] = snd_emu10k1_efx_read(emu, i);
     2539}
     2540
     2541void snd_emu10k1_efx_resume(struct snd_emu10k1 *emu)
     2542{
     2543    int i, len;
     2544
     2545    /* set up TRAM */
     2546    if (emu->fx8010.etram_pages.bytes > 0) {
     2547        unsigned size, size_reg = 0;
     2548        size = emu->fx8010.etram_pages.bytes / 2;
     2549        size = (size - 1) >> 13;
     2550        while (size) {
     2551            size >>= 1;
     2552            size_reg++;
     2553        }
     2554        outl(HCFG_LOCKTANKCACHE_MASK | inl(emu->port + HCFG), emu->port + HCFG);
     2555        snd_emu10k1_ptr_write(emu, TCB, 0, emu->fx8010.etram_pages.addr);
     2556        snd_emu10k1_ptr_write(emu, TCBS, 0, size_reg);
     2557        outl(inl(emu->port + HCFG) & ~HCFG_LOCKTANKCACHE_MASK, emu->port + HCFG);
     2558    }
     2559
     2560    if (emu->audigy)
     2561        snd_emu10k1_ptr_write(emu, A_DBG, 0, emu->fx8010.dbg | A_DBG_SINGLE_STEP);
     2562    else
     2563        snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg | EMU10K1_DBG_SINGLE_STEP);
     2564
     2565    len = emu->audigy ? 0x200 : 0x100;
     2566    for (i = 0; i < len; i++)
     2567        snd_emu10k1_ptr_write(emu, emu->gpr_base + i, 0, emu->saved_gpr[i]);
     2568
     2569    len = emu->audigy ? 0x100 : 0xa0;
     2570    for (i = 0; i < len; i++) {
     2571        snd_emu10k1_ptr_write(emu, TANKMEMDATAREGBASE + i, 0,
     2572                              emu->tram_val_saved[i]);
     2573        if (! emu->audigy)
     2574            snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + i, 0,
     2575                                  emu->tram_addr_saved[i]);
     2576        else {
     2577            snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + i, 0,
     2578                                  emu->tram_addr_saved[i] << 12);
     2579            snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + i, 0,
     2580                                  emu->tram_addr_saved[i] >> 20);
     2581        }
     2582    }
     2583
     2584    len = emu->audigy ? 2 * 1024 : 2 * 512;
     2585    for (i = 0; i < len; i++)
     2586        snd_emu10k1_efx_write(emu, i, emu->saved_icode[i]);
     2587
     2588    /* start FX processor when the DSP code is updated */
     2589    if (emu->audigy)
     2590        snd_emu10k1_ptr_write(emu, A_DBG, 0, emu->fx8010.dbg);
     2591    else
     2592        snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg);
     2593}
     2594#endif
  • GPL/trunk/alsa-kernel/pci/emu10k1/emumixer.c

    r34 r84  
    55 *  Routines for control of EMU10K1 chips / mixer routines
    66 *  Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
     7 *
     8 *  Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
     9 *      Added EMU 1010 support.
    710 *
    811 *  BUGS:
     
    3639#define AC97_ID_STAC9758        0x83847658
    3740
    38 static int snd_emu10k1_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     41static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    3942{
    4043    uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
     
    4346}
    4447
    45 static int snd_emu10k1_spdif_get(snd_kcontrol_t * kcontrol,
    46                                  snd_ctl_elem_value_t * ucontrol)
     48static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
     49                                 struct snd_ctl_elem_value *ucontrol)
    4750{
    4851    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    5962}
    6063
    61 static int snd_emu10k1_spdif_get_mask(snd_kcontrol_t * kcontrol,
    62                                       snd_ctl_elem_value_t * ucontrol)
     64static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
     65                                      struct snd_ctl_elem_value *ucontrol)
    6366{
    6467    ucontrol->value.iec958.status[0] = 0xff;
     
    6972}
    7073
    71 static int snd_audigy_spdif_output_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     74static char *emu1010_src_texts[] = {
     75    "Silence",
     76    "Dock Mic A",
     77    "Dock Mic B",
     78    "Dock ADC1 Left",
     79    "Dock ADC1 Right",
     80    "Dock ADC2 Left",
     81    "Dock ADC2 Right",
     82    "Dock ADC3 Left",
     83    "Dock ADC3 Right",
     84    "0202 ADC Left",
     85    "0202 ADC Right",
     86    "0202 SPDIF Left",
     87    "0202 SPDIF Right",
     88    "ADAT 0",
     89    "ADAT 1",
     90    "ADAT 2",
     91    "ADAT 3",
     92    "ADAT 4",
     93    "ADAT 5",
     94    "ADAT 6",
     95    "ADAT 7",
     96    "DSP 0",
     97    "DSP 1",
     98    "DSP 2",
     99    "DSP 3",
     100    "DSP 4",
     101    "DSP 5",
     102    "DSP 6",
     103    "DSP 7",
     104    "DSP 8",
     105    "DSP 9",
     106    "DSP 10",
     107    "DSP 11",
     108    "DSP 12",
     109    "DSP 13",
     110    "DSP 14",
     111    "DSP 15",
     112    "DSP 16",
     113    "DSP 17",
     114    "DSP 18",
     115    "DSP 19",
     116    "DSP 20",
     117    "DSP 21",
     118    "DSP 22",
     119    "DSP 23",
     120    "DSP 24",
     121    "DSP 25",
     122    "DSP 26",
     123    "DSP 27",
     124    "DSP 28",
     125    "DSP 29",
     126    "DSP 30",
     127    "DSP 31",
     128};
     129
     130static unsigned int emu1010_src_regs[] = {
     131    EMU_SRC_SILENCE,/* 0 */
     132    EMU_SRC_DOCK_MIC_A1, /* 1 */
     133    EMU_SRC_DOCK_MIC_B1, /* 2 */
     134    EMU_SRC_DOCK_ADC1_LEFT1, /* 3 */
     135    EMU_SRC_DOCK_ADC1_RIGHT1, /* 4 */
     136    EMU_SRC_DOCK_ADC2_LEFT1, /* 5 */
     137    EMU_SRC_DOCK_ADC2_RIGHT1, /* 6 */
     138    EMU_SRC_DOCK_ADC3_LEFT1, /* 7 */
     139    EMU_SRC_DOCK_ADC3_RIGHT1, /* 8 */
     140    EMU_SRC_HAMOA_ADC_LEFT1, /* 9 */
     141    EMU_SRC_HAMOA_ADC_RIGHT1, /* 10 */
     142    EMU_SRC_HANA_SPDIF_LEFT1, /* 11 */
     143    EMU_SRC_HANA_SPDIF_RIGHT1, /* 12 */
     144    EMU_SRC_HANA_ADAT, /* 13 */
     145    EMU_SRC_HANA_ADAT+1, /* 14 */
     146    EMU_SRC_HANA_ADAT+2, /* 15 */
     147    EMU_SRC_HANA_ADAT+3, /* 16 */
     148    EMU_SRC_HANA_ADAT+4, /* 17 */
     149    EMU_SRC_HANA_ADAT+5, /* 18 */
     150    EMU_SRC_HANA_ADAT+6, /* 19 */
     151    EMU_SRC_HANA_ADAT+7, /* 20 */
     152    EMU_SRC_ALICE_EMU32A, /* 21 */
     153    EMU_SRC_ALICE_EMU32A+1, /* 22 */
     154    EMU_SRC_ALICE_EMU32A+2, /* 23 */
     155    EMU_SRC_ALICE_EMU32A+3, /* 24 */
     156    EMU_SRC_ALICE_EMU32A+4, /* 25 */
     157    EMU_SRC_ALICE_EMU32A+5, /* 26 */
     158    EMU_SRC_ALICE_EMU32A+6, /* 27 */
     159    EMU_SRC_ALICE_EMU32A+7, /* 28 */
     160    EMU_SRC_ALICE_EMU32A+8, /* 29 */
     161    EMU_SRC_ALICE_EMU32A+9, /* 30 */
     162    EMU_SRC_ALICE_EMU32A+0xa, /* 31 */
     163    EMU_SRC_ALICE_EMU32A+0xb, /* 32 */
     164    EMU_SRC_ALICE_EMU32A+0xc, /* 33 */
     165    EMU_SRC_ALICE_EMU32A+0xd, /* 34 */
     166    EMU_SRC_ALICE_EMU32A+0xe, /* 35 */
     167    EMU_SRC_ALICE_EMU32A+0xf, /* 36 */
     168    EMU_SRC_ALICE_EMU32B, /* 37 */
     169    EMU_SRC_ALICE_EMU32B+1, /* 38 */
     170    EMU_SRC_ALICE_EMU32B+2, /* 39 */
     171    EMU_SRC_ALICE_EMU32B+3, /* 40 */
     172    EMU_SRC_ALICE_EMU32B+4, /* 41 */
     173    EMU_SRC_ALICE_EMU32B+5, /* 42 */
     174    EMU_SRC_ALICE_EMU32B+6, /* 43 */
     175    EMU_SRC_ALICE_EMU32B+7, /* 44 */
     176    EMU_SRC_ALICE_EMU32B+8, /* 45 */
     177    EMU_SRC_ALICE_EMU32B+9, /* 46 */
     178    EMU_SRC_ALICE_EMU32B+0xa, /* 47 */
     179    EMU_SRC_ALICE_EMU32B+0xb, /* 48 */
     180    EMU_SRC_ALICE_EMU32B+0xc, /* 49 */
     181    EMU_SRC_ALICE_EMU32B+0xd, /* 50 */
     182    EMU_SRC_ALICE_EMU32B+0xe, /* 51 */
     183    EMU_SRC_ALICE_EMU32B+0xf, /* 52 */
     184};
     185
     186static unsigned int emu1010_output_dst[] = {
     187    EMU_DST_DOCK_DAC1_LEFT1, /* 0 */
     188    EMU_DST_DOCK_DAC1_RIGHT1, /* 1 */
     189    EMU_DST_DOCK_DAC2_LEFT1, /* 2 */
     190    EMU_DST_DOCK_DAC2_RIGHT1, /* 3 */
     191    EMU_DST_DOCK_DAC3_LEFT1, /* 4 */
     192    EMU_DST_DOCK_DAC3_RIGHT1, /* 5 */
     193    EMU_DST_DOCK_DAC4_LEFT1, /* 6 */
     194    EMU_DST_DOCK_DAC4_RIGHT1, /* 7 */
     195    EMU_DST_DOCK_PHONES_LEFT1, /* 8 */
     196    EMU_DST_DOCK_PHONES_RIGHT1, /* 9 */
     197    EMU_DST_DOCK_SPDIF_LEFT1, /* 10 */
     198    EMU_DST_DOCK_SPDIF_RIGHT1, /* 11 */
     199    EMU_DST_HANA_SPDIF_LEFT1, /* 12 */
     200    EMU_DST_HANA_SPDIF_RIGHT1, /* 13 */
     201    EMU_DST_HAMOA_DAC_LEFT1, /* 14 */
     202    EMU_DST_HAMOA_DAC_RIGHT1, /* 15 */
     203    EMU_DST_HANA_ADAT, /* 16 */
     204    EMU_DST_HANA_ADAT+1, /* 17 */
     205    EMU_DST_HANA_ADAT+2, /* 18 */
     206    EMU_DST_HANA_ADAT+3, /* 19 */
     207    EMU_DST_HANA_ADAT+4, /* 20 */
     208    EMU_DST_HANA_ADAT+5, /* 21 */
     209    EMU_DST_HANA_ADAT+6, /* 22 */
     210    EMU_DST_HANA_ADAT+7, /* 23 */
     211};
     212
     213static unsigned int emu1010_input_dst[] = {
     214    EMU_DST_ALICE2_EMU32_0,
     215    EMU_DST_ALICE2_EMU32_1,
     216    EMU_DST_ALICE2_EMU32_2,
     217    EMU_DST_ALICE2_EMU32_3,
     218    EMU_DST_ALICE2_EMU32_4,
     219    EMU_DST_ALICE2_EMU32_5,
     220    EMU_DST_ALICE2_EMU32_6,
     221    EMU_DST_ALICE2_EMU32_7,
     222    EMU_DST_ALICE2_EMU32_8,
     223    EMU_DST_ALICE2_EMU32_9,
     224    EMU_DST_ALICE2_EMU32_A,
     225    EMU_DST_ALICE2_EMU32_B,
     226    EMU_DST_ALICE2_EMU32_C,
     227    EMU_DST_ALICE2_EMU32_D,
     228    EMU_DST_ALICE2_EMU32_E,
     229    EMU_DST_ALICE2_EMU32_F,
     230    EMU_DST_ALICE_I2S0_LEFT,
     231    EMU_DST_ALICE_I2S0_RIGHT,
     232    EMU_DST_ALICE_I2S1_LEFT,
     233    EMU_DST_ALICE_I2S1_RIGHT,
     234    EMU_DST_ALICE_I2S2_LEFT,
     235    EMU_DST_ALICE_I2S2_RIGHT,
     236};
     237
     238static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     239{
     240    uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     241    uinfo->count = 1;
     242    uinfo->value.enumerated.items = 53;
     243    if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     244        uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     245    strcpy(uinfo->value.enumerated.name, emu1010_src_texts[uinfo->value.enumerated.item]);
     246    return 0;
     247}
     248
     249static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
     250                                         struct snd_ctl_elem_value *ucontrol)
     251{
     252    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     253    int channel;
     254
     255    channel = (kcontrol->private_value) & 0xff;
     256    ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel];
     257    return 0;
     258}
     259
     260static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
     261                                         struct snd_ctl_elem_value *ucontrol)
     262{
     263    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     264    int change = 0;
     265    unsigned int val;
     266    int channel;
     267
     268    channel = (kcontrol->private_value) & 0xff;
     269    if (emu->emu1010.output_source[channel] != ucontrol->value.enumerated.item[0]) {
     270        val = emu->emu1010.output_source[channel] = ucontrol->value.enumerated.item[0];
     271        change = 1;
     272        snd_emu1010_fpga_link_dst_src_write(emu,
     273                                            emu1010_output_dst[channel], emu1010_src_regs[val]);
     274    }
     275    return change;
     276}
     277
     278static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
     279                                        struct snd_ctl_elem_value *ucontrol)
     280{
     281    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     282    int channel;
     283
     284    channel = (kcontrol->private_value) & 0xff;
     285    ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
     286    return 0;
     287}
     288
     289static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
     290                                        struct snd_ctl_elem_value *ucontrol)
     291{
     292    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     293    int change = 0;
     294    unsigned int val;
     295    int channel;
     296
     297    channel = (kcontrol->private_value) & 0xff;
     298    if (emu->emu1010.input_source[channel] != ucontrol->value.enumerated.item[0]) {
     299        val = emu->emu1010.input_source[channel] = ucontrol->value.enumerated.item[0];
     300        change = 1;
     301        snd_emu1010_fpga_link_dst_src_write(emu,
     302                                            emu1010_input_dst[channel], emu1010_src_regs[val]);
     303    }
     304    return change;
     305}
     306
     307#define EMU1010_SOURCE_OUTPUT(xname,chid) \
     308    {                                                           \
     309    .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
     310    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,          \
     311    .info =  snd_emu1010_input_output_source_info,              \
     312    .get =   snd_emu1010_output_source_get,                     \
     313    .put =   snd_emu1010_output_source_put,                     \
     314    .private_value = chid                                       \
     315    }
     316
     317static struct snd_kcontrol_new snd_emu1010_output_enum_ctls[] __devinitdata = {
     318    EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Switch", 0),
     319    EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Switch", 1),
     320    EMU1010_SOURCE_OUTPUT("Dock DAC2 Left Playback Switch", 2),
     321    EMU1010_SOURCE_OUTPUT("Dock DAC2 Right Playback Switch", 3),
     322    EMU1010_SOURCE_OUTPUT("Dock DAC3 Left Playback Switch", 4),
     323    EMU1010_SOURCE_OUTPUT("Dock DAC3 Right Playback Switch", 5),
     324    EMU1010_SOURCE_OUTPUT("Dock DAC4 Left Playback Switch", 6),
     325    EMU1010_SOURCE_OUTPUT("Dock DAC4 Right Playback Switch", 7),
     326    EMU1010_SOURCE_OUTPUT("Dock Phones Left Playback Switch", 8),
     327    EMU1010_SOURCE_OUTPUT("Dock Phones Right Playback Switch", 9),
     328    EMU1010_SOURCE_OUTPUT("Dock SPDIF Left Playback Switch", 0xa),
     329    EMU1010_SOURCE_OUTPUT("Dock SPDIF Right Playback Switch", 0xb),
     330    EMU1010_SOURCE_OUTPUT("1010 SPDIF Left Playback Switch", 0xc),
     331    EMU1010_SOURCE_OUTPUT("1010 SPDIF Right Playback Switch", 0xd),
     332    EMU1010_SOURCE_OUTPUT("0202 DAC Left Playback Switch", 0xe),
     333    EMU1010_SOURCE_OUTPUT("0202 DAC Right Playback Switch", 0xf),
     334    EMU1010_SOURCE_OUTPUT("1010 ADAT 0 Playback Switch", 0x10),
     335    EMU1010_SOURCE_OUTPUT("1010 ADAT 1 Playback Switch", 0x11),
     336    EMU1010_SOURCE_OUTPUT("1010 ADAT 2 Playback Switch", 0x12),
     337    EMU1010_SOURCE_OUTPUT("1010 ADAT 3 Playback Switch", 0x13),
     338    EMU1010_SOURCE_OUTPUT("1010 ADAT 4 Playback Switch", 0x14),
     339    EMU1010_SOURCE_OUTPUT("1010 ADAT 5 Playback Switch", 0x15),
     340    EMU1010_SOURCE_OUTPUT("1010 ADAT 6 Playback Switch", 0x16),
     341    EMU1010_SOURCE_OUTPUT("1010 ADAT 7 Playback Switch", 0x17),
     342};
     343
     344#define EMU1010_SOURCE_INPUT(xname,chid) \
     345    {                                                           \
     346    .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
     347    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,          \
     348    .info =  snd_emu1010_input_output_source_info,              \
     349    .get =   snd_emu1010_input_source_get,                      \
     350    .put =   snd_emu1010_input_source_put,                      \
     351    .private_value = chid                                       \
     352    }
     353
     354static struct snd_kcontrol_new snd_emu1010_input_enum_ctls[] __devinitdata = {
     355    EMU1010_SOURCE_INPUT("DSP 0 Capture Switch", 0),
     356    EMU1010_SOURCE_INPUT("DSP 1 Capture Switch", 1),
     357    EMU1010_SOURCE_INPUT("DSP 2 Capture Switch", 2),
     358    EMU1010_SOURCE_INPUT("DSP 3 Capture Switch", 3),
     359    EMU1010_SOURCE_INPUT("DSP 4 Capture Switch", 4),
     360    EMU1010_SOURCE_INPUT("DSP 5 Capture Switch", 5),
     361    EMU1010_SOURCE_INPUT("DSP 6 Capture Switch", 6),
     362    EMU1010_SOURCE_INPUT("DSP 7 Capture Switch", 7),
     363    EMU1010_SOURCE_INPUT("DSP 8 Capture Switch", 8),
     364    EMU1010_SOURCE_INPUT("DSP 9 Capture Switch", 9),
     365    EMU1010_SOURCE_INPUT("DSP A Capture Switch", 0xa),
     366    EMU1010_SOURCE_INPUT("DSP B Capture Switch", 0xb),
     367    EMU1010_SOURCE_INPUT("DSP C Capture Switch", 0xc),
     368    EMU1010_SOURCE_INPUT("DSP D Capture Switch", 0xd),
     369    EMU1010_SOURCE_INPUT("DSP E Capture Switch", 0xe),
     370    EMU1010_SOURCE_INPUT("DSP F Capture Switch", 0xf),
     371    EMU1010_SOURCE_INPUT("DSP 10 Capture Switch", 0x10),
     372    EMU1010_SOURCE_INPUT("DSP 11 Capture Switch", 0x11),
     373    EMU1010_SOURCE_INPUT("DSP 12 Capture Switch", 0x12),
     374    EMU1010_SOURCE_INPUT("DSP 13 Capture Switch", 0x13),
     375    EMU1010_SOURCE_INPUT("DSP 14 Capture Switch", 0x14),
     376    EMU1010_SOURCE_INPUT("DSP 15 Capture Switch", 0x15),
     377};
     378
     379
     380
     381
     382static int snd_emu1010_adc_pads_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     383{
     384    uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     385    uinfo->count = 1;
     386    uinfo->value.integer.min = 0;
     387    uinfo->value.integer.max = 1;
     388    return 0;
     389}
     390
     391static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     392{
     393    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     394    unsigned int mask = kcontrol->private_value & 0xff;
     395    ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
     396    return 0;
     397}
     398
     399static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     400{
     401    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     402    unsigned int mask = kcontrol->private_value & 0xff;
     403    unsigned int val, cache;
     404    val = ucontrol->value.integer.value[0];
     405    cache = emu->emu1010.adc_pads;
     406    if (val == 1)
     407        cache = cache | mask;
     408    else
     409        cache = cache & ~mask;
     410    if (cache != emu->emu1010.adc_pads) {
     411        snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache );
     412        emu->emu1010.adc_pads = cache;
     413    }
     414
     415    return 0;
     416}
     417
     418
     419
     420#define EMU1010_ADC_PADS(xname,chid) \
     421    {                                                           \
     422    .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
     423    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,          \
     424    .info =  snd_emu1010_adc_pads_info,                 \
     425    .get =   snd_emu1010_adc_pads_get,                  \
     426    .put =   snd_emu1010_adc_pads_put,                  \
     427    .private_value = chid                                       \
     428    }
     429
     430static struct snd_kcontrol_new snd_emu1010_adc_pads[] __devinitdata = {
     431    EMU1010_ADC_PADS("ADC1 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD1),
     432    EMU1010_ADC_PADS("ADC2 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD2),
     433    EMU1010_ADC_PADS("ADC3 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD3),
     434    EMU1010_ADC_PADS("ADC1 14dB PAD 0202 Capture Switch", EMU_HANA_0202_ADC_PAD1),
     435};
     436
     437static int snd_emu1010_dac_pads_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     438{
     439    uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     440    uinfo->count = 1;
     441    uinfo->value.integer.min = 0;
     442    uinfo->value.integer.max = 1;
     443    return 0;
     444}
     445
     446static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     447{
     448    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     449    unsigned int mask = kcontrol->private_value & 0xff;
     450    ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
     451    return 0;
     452}
     453
     454static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     455{
     456    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     457    unsigned int mask = kcontrol->private_value & 0xff;
     458    unsigned int val, cache;
     459    val = ucontrol->value.integer.value[0];
     460    cache = emu->emu1010.dac_pads;
     461    if (val == 1)
     462        cache = cache | mask;
     463    else
     464        cache = cache & ~mask;
     465    if (cache != emu->emu1010.dac_pads) {
     466        snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache );
     467        emu->emu1010.dac_pads = cache;
     468    }
     469
     470    return 0;
     471}
     472
     473
     474
     475#define EMU1010_DAC_PADS(xname,chid) \
     476    {                                                           \
     477    .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
     478    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,          \
     479    .info =  snd_emu1010_dac_pads_info,                 \
     480    .get =   snd_emu1010_dac_pads_get,                  \
     481    .put =   snd_emu1010_dac_pads_put,                  \
     482    .private_value = chid                                       \
     483    }
     484
     485static struct snd_kcontrol_new snd_emu1010_dac_pads[] __devinitdata = {
     486    EMU1010_DAC_PADS("DAC1 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD1),
     487    EMU1010_DAC_PADS("DAC2 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD2),
     488    EMU1010_DAC_PADS("DAC3 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD3),
     489    EMU1010_DAC_PADS("DAC4 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD4),
     490    EMU1010_DAC_PADS("DAC1 0202 14dB PAD Playback Switch", EMU_HANA_0202_DAC_PAD1),
     491};
     492
     493
     494static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol,
     495                                           struct snd_ctl_elem_info *uinfo)
     496{
     497    static char *texts[2] = {
     498        "44100", "48000"
     499    };
     500
     501    uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     502    uinfo->count = 1;
     503    uinfo->value.enumerated.items = 2;
     504    if (uinfo->value.enumerated.item > 1)
     505        uinfo->value.enumerated.item = 1;
     506    strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     507    return 0;
     508}
     509
     510static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol,
     511                                          struct snd_ctl_elem_value *ucontrol)
     512{
     513    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     514
     515    ucontrol->value.enumerated.item[0] = emu->emu1010.internal_clock;
     516    return 0;
     517}
     518
     519static int snd_emu1010_internal_clock_put(struct snd_kcontrol *kcontrol,
     520                                          struct snd_ctl_elem_value *ucontrol)
     521{
     522    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     523    unsigned int val;
     524    int change = 0;
     525
     526    val = ucontrol->value.enumerated.item[0] ;
     527    change = (emu->emu1010.internal_clock != val);
     528    if (change) {
     529        emu->emu1010.internal_clock = val;
     530        switch (val) {
     531        case 0:
     532            /* 44100 */
     533            /* Mute all */
     534            snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
     535            /* Default fallback clock 48kHz */
     536            snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_44_1K );
     537            /* Word Clock source, Internal 44.1kHz x1 */
     538            snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
     539                                   EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_1X );
     540            /* Set LEDs on Audio Dock */
     541            snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
     542                                   EMU_HANA_DOCK_LEDS_2_44K | EMU_HANA_DOCK_LEDS_2_LOCK );
     543            /* Allow DLL to settle */
     544            msleep(10);
     545            /* Unmute all */
     546            snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
     547            break;
     548        case 1:
     549            /* 48000 */
     550            /* Mute all */
     551            snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
     552            /* Default fallback clock 48kHz */
     553            snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K );
     554            /* Word Clock source, Internal 48kHz x1 */
     555            snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
     556                                   EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_1X );
     557            /* Set LEDs on Audio Dock */
     558            snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
     559                                   EMU_HANA_DOCK_LEDS_2_48K | EMU_HANA_DOCK_LEDS_2_LOCK );
     560            /* Allow DLL to settle */
     561            msleep(10);
     562            /* Unmute all */
     563            snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
     564            break;
     565        }
     566    }
     567    return change;
     568}
     569
     570static struct snd_kcontrol_new snd_emu1010_internal_clock =
     571{
     572    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE,
     573    .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     574    .name =         "Clock Internal Rate",
     575    .count =    1,
     576    .info =         snd_emu1010_internal_clock_info,
     577    .get =          snd_emu1010_internal_clock_get,
     578    .put =          snd_emu1010_internal_clock_put
     579};
     580
     581
     582#if 0
     583static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    72584{
    73585    static char *texts[] = {"44100", "48000", "96000"};
     
    82594}
    83595
    84 static int snd_audigy_spdif_output_rate_get(snd_kcontrol_t * kcontrol,
    85                                             snd_ctl_elem_value_t * ucontrol)
     596static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
     597                                            struct snd_ctl_elem_value *ucontrol)
    86598{
    87599    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    109621}
    110622
    111 static int snd_audigy_spdif_output_rate_put(snd_kcontrol_t * kcontrol,
    112                                             snd_ctl_elem_value_t * ucontrol)
     623static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
     624                                            struct snd_ctl_elem_value *ucontrol)
    113625{
    114626    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    143655}
    144656
    145 static snd_kcontrol_new_t snd_audigy_spdif_output_rate =
    146 {
    147     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    148     "Audigy SPDIF Output Sample Rate", 0,
    149     SNDRV_CTL_ELEM_ACCESS_READWRITE,
    150     1,
    151     snd_audigy_spdif_output_rate_info,
    152     snd_audigy_spdif_output_rate_get,
    153     snd_audigy_spdif_output_rate_put, 0
    154 };
    155 
    156 static int snd_emu10k1_spdif_put(snd_kcontrol_t * kcontrol,
    157                                  snd_ctl_elem_value_t * ucontrol)
     657static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
     658{
     659    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE,
     660    .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     661    .name =         "Audigy SPDIF Output Sample Rate",
     662    .count =    1,
     663    .info =         snd_audigy_spdif_output_rate_info,
     664    .get =          snd_audigy_spdif_output_rate_get,
     665    .put =          snd_audigy_spdif_output_rate_put
     666};
     667#endif
     668
     669static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
     670                                 struct snd_ctl_elem_value *ucontrol)
    158671{
    159672    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    177690}
    178691
    179 static snd_kcontrol_new_t snd_emu10k1_spdif_mask_control =
    180 {
    181     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    182     SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
    183     0,SNDRV_CTL_ELEM_ACCESS_READ,4,
    184     snd_emu10k1_spdif_info,
    185     snd_emu10k1_spdif_get_mask,0,0
    186 };
    187 
    188 static snd_kcontrol_new_t snd_emu10k1_spdif_control =
    189 {
    190     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    191     SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),0,0,4,
    192     snd_emu10k1_spdif_info,
    193     snd_emu10k1_spdif_get,
    194     snd_emu10k1_spdif_put,0
    195 };
     692static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
     693{
     694    .access =   SNDRV_CTL_ELEM_ACCESS_READ,
     695    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     696    .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
     697    .count =    4,
     698    .info =         snd_emu10k1_spdif_info,
     699    .get =          snd_emu10k1_spdif_get_mask
     700};
     701
     702static struct snd_kcontrol_new snd_emu10k1_spdif_control =
     703{
     704    .iface =    SNDRV_CTL_ELEM_IFACE_PCM,
     705    .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
     706    .count =    4,
     707    .info =         snd_emu10k1_spdif_info,
     708    .get =          snd_emu10k1_spdif_get,
     709    .put =          snd_emu10k1_spdif_put
     710};
     711
    196712
    197713static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
     
    225741/* PCM stream controls */
    226742
    227 static int snd_emu10k1_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     743static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    228744{
    229745    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    235751}
    236752
    237 static int snd_emu10k1_send_routing_get(snd_kcontrol_t * kcontrol,
    238                                         snd_ctl_elem_value_t * ucontrol)
    239 {
    240     unsigned long flags;
    241     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    242     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     753static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
     754                                        struct snd_ctl_elem_value *ucontrol)
     755{
     756    unsigned long flags;
     757    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     758    struct snd_emu10k1_pcm_mixer *mix =
     759        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    243760    int voice, idx;
    244761    int num_efx = emu->audigy ? 8 : 4;
     
    254771}
    255772
    256 static int snd_emu10k1_send_routing_put(snd_kcontrol_t * kcontrol,
    257                                         snd_ctl_elem_value_t * ucontrol)
    258 {
    259     unsigned long flags;
    260     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    261     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     773static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
     774                                        struct snd_ctl_elem_value *ucontrol)
     775{
     776    unsigned long flags;
     777    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     778    struct snd_emu10k1_pcm_mixer *mix =
     779        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    262780    int change = 0, voice, idx, val;
    263781    int num_efx = emu->audigy ? 8 : 4;
     
    288806}
    289807
    290 static snd_kcontrol_new_t snd_emu10k1_send_routing_control =
    291 {
    292     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    293     "EMU10K1 PCM Send Routing",0,
    294     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,32,
    295     snd_emu10k1_send_routing_info,
    296     snd_emu10k1_send_routing_get,
    297     snd_emu10k1_send_routing_put,0
    298 };
    299 
    300 static int snd_emu10k1_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     808static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
     809{
     810    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     811    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     812    .name =         "EMU10K1 PCM Send Routing",
     813    .count =    32,
     814    .info =         snd_emu10k1_send_routing_info,
     815    .get =          snd_emu10k1_send_routing_get,
     816    .put =          snd_emu10k1_send_routing_put
     817};
     818
     819static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    301820{
    302821    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    308827}
    309828
    310 static int snd_emu10k1_send_volume_get(snd_kcontrol_t * kcontrol,
    311                                        snd_ctl_elem_value_t * ucontrol)
    312 {
    313     unsigned long flags;
    314     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    315     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     829static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
     830                                       struct snd_ctl_elem_value *ucontrol)
     831{
     832    unsigned long flags;
     833    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     834    struct snd_emu10k1_pcm_mixer *mix =
     835        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    316836    int idx;
    317837    int num_efx = emu->audigy ? 8 : 4;
     
    324844}
    325845
    326 static int snd_emu10k1_send_volume_put(snd_kcontrol_t * kcontrol,
    327                                        snd_ctl_elem_value_t * ucontrol)
    328 {
    329     unsigned long flags;
    330     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    331     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     846static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
     847                                       struct snd_ctl_elem_value *ucontrol)
     848{
     849    unsigned long flags;
     850    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     851    struct snd_emu10k1_pcm_mixer *mix =
     852        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    332853    int change = 0, idx, val;
    333854    int num_efx = emu->audigy ? 8 : 4;
     
    356877}
    357878
    358 static snd_kcontrol_new_t snd_emu10k1_send_volume_control =
    359 {
    360     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    361     "EMU10K1 PCM Send Volume",0,
    362     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,32,
    363     snd_emu10k1_send_volume_info,
    364     snd_emu10k1_send_volume_get,
    365     snd_emu10k1_send_volume_put,0
    366 };
    367 
    368 static int snd_emu10k1_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     879static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
     880{
     881    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     882    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     883    .name =         "EMU10K1 PCM Send Volume",
     884    .count =    32,
     885    .info =         snd_emu10k1_send_volume_info,
     886    .get =          snd_emu10k1_send_volume_get,
     887    .put =          snd_emu10k1_send_volume_put
     888};
     889
     890static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    369891{
    370892    uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     
    375897}
    376898
    377 static int snd_emu10k1_attn_get(snd_kcontrol_t * kcontrol,
    378                                 snd_ctl_elem_value_t * ucontrol)
    379 {
    380     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    381     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     899static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
     900                                struct snd_ctl_elem_value *ucontrol)
     901{
     902    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     903    struct snd_emu10k1_pcm_mixer *mix =
     904        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    382905    unsigned long flags;
    383906    int idx;
     
    390913}
    391914
    392 static int snd_emu10k1_attn_put(snd_kcontrol_t * kcontrol,
    393                                 snd_ctl_elem_value_t * ucontrol)
    394 {
    395     unsigned long flags;
    396     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    397     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     915static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
     916                                struct snd_ctl_elem_value *ucontrol)
     917{
     918    unsigned long flags;
     919    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     920    struct snd_emu10k1_pcm_mixer *mix =
     921        &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    398922    int change = 0, idx, val;
    399923
     
    418942}
    419943
    420 static snd_kcontrol_new_t snd_emu10k1_attn_control =
    421 {
    422     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    423     "EMU10K1 PCM Volume",0,
    424     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,32,
    425     snd_emu10k1_attn_info,
    426     snd_emu10k1_attn_get,
    427     snd_emu10k1_attn_put,0
     944static struct snd_kcontrol_new snd_emu10k1_attn_control =
     945{
     946    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     947    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     948    .name =         "EMU10K1 PCM Volume",
     949    .count =    32,
     950    .info =         snd_emu10k1_attn_info,
     951    .get =          snd_emu10k1_attn_get,
     952    .put =          snd_emu10k1_attn_put
    428953};
    429954
    430955/* Mutichannel PCM stream controls */
    431956
    432 static int snd_emu10k1_efx_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     957static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    433958{
    434959    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    440965}
    441966
    442 static int snd_emu10k1_efx_send_routing_get(snd_kcontrol_t * kcontrol,
    443                                             snd_ctl_elem_value_t * ucontrol)
    444 {
    445     unsigned long flags;
    446     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    447     struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     967static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
     968                                            struct snd_ctl_elem_value *ucontrol)
     969{
     970    unsigned long flags;
     971    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     972    struct snd_emu10k1_pcm_mixer *mix =
     973        &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    448974    int idx;
    449975    int num_efx = emu->audigy ? 8 : 4;
     
    458984}
    459985
    460 static int snd_emu10k1_efx_send_routing_put(snd_kcontrol_t * kcontrol,
    461                                             snd_ctl_elem_value_t * ucontrol)
     986static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
     987                                            struct snd_ctl_elem_value *ucontrol)
    462988{
    463989    unsigned long flags;
     
    4771003        }
    4781004    }
     1005
    4791006    if (change && mix->epcm) {
    4801007        if (mix->epcm->voices[ch]) {
     
    4871014}
    4881015
    489 static snd_kcontrol_new_t snd_emu10k1_efx_send_routing_control =
    490 {
    491     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    492     "Multichannel PCM Send Routing",0,
    493     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    494     16,
    495     snd_emu10k1_efx_send_routing_info,
    496     snd_emu10k1_efx_send_routing_get,
    497     snd_emu10k1_efx_send_routing_put,0
    498 };
    499 
    500 static int snd_emu10k1_efx_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1016static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
     1017{
     1018    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     1019    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1020    .name =         "Multichannel PCM Send Routing",
     1021    .count =    16,
     1022    .info =         snd_emu10k1_efx_send_routing_info,
     1023    .get =          snd_emu10k1_efx_send_routing_get,
     1024    .put =          snd_emu10k1_efx_send_routing_put
     1025};
     1026
     1027static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    5011028{
    5021029    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    5081035}
    5091036
    510 static int snd_emu10k1_efx_send_volume_get(snd_kcontrol_t * kcontrol,
    511                                            snd_ctl_elem_value_t * ucontrol)
    512 {
    513     unsigned long flags;
    514     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    515     struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     1037static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
     1038                                           struct snd_ctl_elem_value *ucontrol)
     1039{
     1040    unsigned long flags;
     1041    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     1042    struct snd_emu10k1_pcm_mixer *mix =
     1043        &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    5161044    int idx;
    5171045    int num_efx = emu->audigy ? 8 : 4;
     
    5241052}
    5251053
    526 static int snd_emu10k1_efx_send_volume_put(snd_kcontrol_t * kcontrol,
    527                                            snd_ctl_elem_value_t * ucontrol)
     1054static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
     1055                                           struct snd_ctl_elem_value *ucontrol)
    5281056{
    5291057    unsigned long flags;
     
    5531081
    5541082
    555 static snd_kcontrol_new_t snd_emu10k1_efx_send_volume_control =
    556 {
    557     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    558     "Multichannel PCM Send Volume",0,
    559     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    560     16,
    561     snd_emu10k1_efx_send_volume_info,
    562     snd_emu10k1_efx_send_volume_get,
    563     snd_emu10k1_efx_send_volume_put,0
    564 };
    565 
    566 static int snd_emu10k1_efx_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1083static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
     1084{
     1085    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     1086    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1087    .name =         "Multichannel PCM Send Volume",
     1088    .count =    16,
     1089    .info =         snd_emu10k1_efx_send_volume_info,
     1090    .get =          snd_emu10k1_efx_send_volume_get,
     1091    .put =          snd_emu10k1_efx_send_volume_put
     1092};
     1093
     1094static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    5671095{
    5681096    uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     
    5731101}
    5741102
    575 static int snd_emu10k1_efx_attn_get(snd_kcontrol_t * kcontrol,
    576                                     snd_ctl_elem_value_t * ucontrol)
    577 {
    578     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    579     struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
     1103static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
     1104                                    struct snd_ctl_elem_value *ucontrol)
     1105{
     1106    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     1107    struct snd_emu10k1_pcm_mixer *mix =
     1108        &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
    5801109    unsigned long flags;
    5811110
     
    5861115}
    5871116
    588 static int snd_emu10k1_efx_attn_put(snd_kcontrol_t * kcontrol,
    589                                     snd_ctl_elem_value_t * ucontrol)
     1117static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
     1118                                    struct snd_ctl_elem_value *ucontrol)
    5901119{
    5911120    unsigned long flags;
     
    6101139}
    6111140
    612 static snd_kcontrol_new_t snd_emu10k1_efx_attn_control =
    613 {
    614     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    615     "Multichannel PCM Volume",0,
    616     SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    617     16,
    618     snd_emu10k1_efx_attn_info,
    619     snd_emu10k1_efx_attn_get,
    620     snd_emu10k1_efx_attn_put,0
    621 };
    622 
    623 static int snd_emu10k1_shared_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1141static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
     1142{
     1143    .access =   SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     1144    .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1145    .name =         "Multichannel PCM Volume",
     1146    .count =    16,
     1147    .info =         snd_emu10k1_efx_attn_info,
     1148    .get =          snd_emu10k1_efx_attn_get,
     1149    .put =          snd_emu10k1_efx_attn_put
     1150};
     1151
     1152static int snd_emu10k1_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    6241153{
    6251154    uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     
    6301159}
    6311160
    632 static int snd_emu10k1_shared_spdif_get(snd_kcontrol_t * kcontrol,
    633                                         snd_ctl_elem_value_t * ucontrol)
     1161static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
     1162                                        struct snd_ctl_elem_value *ucontrol)
    6341163{
    6351164    struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     
    6421171}
    6431172
    644 static int snd_emu10k1_shared_spdif_put(snd_kcontrol_t * kcontrol,
    645                                         snd_ctl_elem_value_t * ucontrol)
     1173static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
     1174                                        struct snd_ctl_elem_value *ucontrol)
    6461175{
    6471176    unsigned long flags;
     
    6731202}
    6741203
    675 static snd_kcontrol_new_t snd_emu10k1_shared_spdif __devinitdata =
    676 {
    677     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    678     "SB Live Analog/Digital Output Jack",0,0,0,
    679     snd_emu10k1_shared_spdif_info,
    680     snd_emu10k1_shared_spdif_get,
    681     snd_emu10k1_shared_spdif_put,0
    682 };
    683 
    684 static snd_kcontrol_new_t snd_audigy_shared_spdif __devinitdata =
    685 {
    686     SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
    687     "Audigy Analog/Digital Output Jack",0,0,0,
    688     snd_emu10k1_shared_spdif_info,
    689     snd_emu10k1_shared_spdif_get,
    690     snd_emu10k1_shared_spdif_put,0
     1204static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
     1205{
     1206    .iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
     1207    .name =             "SB Live Analog/Digital Output Jack",
     1208    .info =             snd_emu10k1_shared_spdif_info,
     1209    .get =              snd_emu10k1_shared_spdif_get,
     1210    .put =              snd_emu10k1_shared_spdif_put
     1211};
     1212
     1213static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
     1214{
     1215    .iface =    SNDRV_CTL_ELEM_IFACE_MIXER,
     1216    .name =             "Audigy Analog/Digital Output Jack",
     1217    .info =             snd_emu10k1_shared_spdif_info,
     1218    .get =              snd_emu10k1_shared_spdif_get,
     1219    .put =              snd_emu10k1_shared_spdif_put
    6911220};
    6921221
    6931222/*
    6941223 */
    695 static void snd_emu10k1_mixer_free_ac97(ac97_t *ac97)
     1224static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
    6961225{
    6971226    struct snd_emu10k1 *emu = ac97->private_data;
     
    7011230/*
    7021231 */
    703 static int remove_ctl(snd_card_t *card, const char *name)
    704 {
    705     snd_ctl_elem_id_t id;
     1232static int remove_ctl(struct snd_card *card, const char *name)
     1233{
     1234    struct snd_ctl_elem_id id;
    7061235    memset(&id, 0, sizeof(id));
    7071236    strcpy(id.name, name);
     
    7101239}
    7111240
    712 static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
    713 {
    714     snd_ctl_elem_id_t sid;
     1241static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
     1242{
     1243    struct snd_ctl_elem_id sid;
    7151244    memset(&sid, 0, sizeof(sid));
    7161245    strcpy(sid.name, name);
     
    7191248}
    7201249
    721 static int rename_ctl(snd_card_t *card, const char *src, const char *dst)
    722 {
    723     snd_kcontrol_t *kctl = ctl_find(card, src);
     1250static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
     1251{
     1252    struct snd_kcontrol *kctl = ctl_find(card, src);
    7241253    if (kctl) {
    7251254        strcpy(kctl->id.name, dst);
     
    7331262{
    7341263    int err, pcm;
    735     snd_kcontrol_t *kctl;
    736     snd_card_t *card = emu->card;
     1264    struct snd_kcontrol *kctl;
     1265    struct snd_card *card = emu->card;
    7371266    char **c;
    7381267    static char *emu10k1_remove_ctls[] = {
     
    7421271        "PCM Out Path & Mute",
    7431272        "Mono Output Select",
     1273        "Front Playback Switch",
     1274        "Front Playback Volume",
    7441275        "Surround Playback Switch",
    7451276        "Surround Playback Volume",
     
    7581289    static char *audigy_remove_ctls[] = {
    7591290        /* Master/PCM controls on ac97 of Audigy has no effect */
     1291        /* On the Audigy2 the AC97 playback is piped into
     1292         * the Philips ADC for 24bit capture */
    7601293        "PCM Playback Switch",
    7611294        "PCM Playback Volume",
     
    7861319    };
    7871320
     1321    static char *audigy_remove_ctls_1361t_adc[] = {
     1322        /* On the Audigy2 the AC97 playback is piped into
     1323         * the Philips ADC for 24bit capture */
     1324        "PCM Playback Switch",
     1325        "PCM Playback Volume",
     1326        "Master Mono Playback Switch",
     1327        "Master Mono Playback Volume",
     1328        "Capture Source",
     1329        "Capture Switch",
     1330        "Capture Volume",
     1331        "Mic Capture Volume",
     1332        "Headphone Playback Switch",
     1333        "Headphone Playback Volume",
     1334        "3D Control - Center",
     1335        "3D Control - Depth",
     1336        "3D Control - Switch",
     1337        "Line2 Playback Volume",
     1338        "Line2 Capture Volume",
     1339        NULL
     1340    };
     1341    static char *audigy_rename_ctls_1361t_adc[] = {
     1342        "Master Playback Switch", "Master Capture Switch",
     1343        "Master Playback Volume", "Master Capture Volume",
     1344        "Wave Master Playback Volume", "Master Playback Volume",
     1345        "PC Speaker Playback Switch", "PC Speaker Capture Switch",
     1346        "PC Speaker Playback Volume", "PC Speaker Capture Volume",
     1347        "Phone Playback Switch", "Phone Capture Switch",
     1348        "Phone Playback Volume", "Phone Capture Volume",
     1349        "Mic Playback Switch", "Mic Capture Switch",
     1350        "Mic Playback Volume", "Mic Capture Volume",
     1351        "Line Playback Switch", "Line Capture Switch",
     1352        "Line Playback Volume", "Line Capture Volume",
     1353        "CD Playback Switch", "CD Capture Switch",
     1354        "CD Playback Volume", "CD Capture Volume",
     1355        "Aux Playback Switch", "Aux Capture Switch",
     1356        "Aux Playback Volume", "Aux Capture Volume",
     1357        "Video Playback Switch", "Video Capture Switch",
     1358        "Video Playback Volume", "Video Capture Volume",
     1359
     1360        NULL
     1361    };
     1362
    7881363    if (emu->card_capabilities->ac97_chip) {
    789         ac97_bus_t *pbus;
    790         ac97_template_t ac97;
    791         static ac97_bus_ops_t ops = {
    792             0,snd_emu10k1_ac97_write,
    793             snd_emu10k1_ac97_read,0,0
     1364        struct snd_ac97_bus *pbus;
     1365        struct snd_ac97_template ac97;
     1366        static struct snd_ac97_bus_ops ops = {
     1367            .write = snd_emu10k1_ac97_write,
     1368            .read = snd_emu10k1_ac97_read,
    7941369        };
    7951370
    7961371        if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
    797                 return err;
    798 
     1372            return err;
    7991373        pbus->no_vra = 1; /* we don't need VRA */
     1374
    8001375        memset(&ac97, 0, sizeof(ac97));
    8011376        ac97.private_data = emu;
     
    8121387        if (emu->audigy) {
    8131388            /* set master volume to 0 dB */
    814             snd_ac97_write(emu->ac97, AC97_MASTER, 0x0000);
     1389            snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
    8151390            /* set capture source to mic */
    816             snd_ac97_write(emu->ac97, AC97_REC_SEL, 0x0000);
    817             c = audigy_remove_ctls;
     1391            snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
     1392            if (emu->card_capabilities->adc_1361t)
     1393                c = audigy_remove_ctls_1361t_adc;
     1394            else
     1395                c = audigy_remove_ctls;
    8181396        } else {
     1397            /*
     1398             * Credits for cards based on STAC9758:
     1399             *   James Courtier-Dutton <James@superbug.demon.co.uk>
     1400             *   Voluspa <voluspa@comhem.se>
     1401             */
    8191402            if (emu->ac97->id == AC97_ID_STAC9758) {
    8201403                emu->rear_ac97 = 1;
     
    8221405            }
    8231406            /* remove unused AC97 controls */
    824             snd_ac97_write(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
    825             snd_ac97_write(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
     1407            snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
     1408            snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
    8261409            c = emu10k1_remove_ctls;
    8271410        }
     
    8391422
    8401423    if (emu->audigy)
    841         c = audigy_rename_ctls;
     1424        if (emu->card_capabilities->adc_1361t)
     1425            c = audigy_rename_ctls_1361t_adc;
     1426        else
     1427            c = audigy_rename_ctls;
    8421428    else
    8431429        c = emu10k1_rename_ctls;
     
    8451431        rename_ctl(card, c[0], c[1]);
    8461432
     1433    if (emu->card_capabilities->subsystem == 0x20071102) {  /* Audigy 4 Pro */
     1434        rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
     1435        rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
     1436        rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
     1437        rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
     1438        remove_ctl(card, "Headphone Playback Switch");
     1439        remove_ctl(card, "Headphone Playback Volume");
     1440        remove_ctl(card, "3D Control - Center");
     1441        remove_ctl(card, "3D Control - Depth");
     1442        remove_ctl(card, "3D Control - Switch");
     1443    }
    8471444    if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
    8481445        return -ENOMEM;
     
    9371534    }
    9381535
    939     if (emu->audigy) {
     1536    if ( emu->card_capabilities->emu1010) {
     1537        ;  /* Disable the snd_audigy_spdif_shared_spdif */
     1538    } else if (emu->audigy) {
    9401539        if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
    9411540            return -ENOMEM;
     
    9591558            return err;
    9601559    }
    961     return 0;
    962 }
     1560    if ( emu->card_capabilities->emu1010) {
     1561        int i;
     1562
     1563        for (i = 0; i < ARRAY_SIZE(snd_emu1010_output_enum_ctls); i++) {
     1564            err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_output_enum_ctls[i], emu));
     1565            if (err < 0)
     1566                return err;
     1567        }
     1568        for (i = 0; i < ARRAY_SIZE(snd_emu1010_input_enum_ctls); i++) {
     1569            err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_input_enum_ctls[i], emu));
     1570            if (err < 0)
     1571                return err;
     1572        }
     1573        for (i = 0; i < ARRAY_SIZE(snd_emu1010_adc_pads); i++) {
     1574            err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_adc_pads[i], emu));
     1575            if (err < 0)
     1576                return err;
     1577        }
     1578        for (i = 0; i < ARRAY_SIZE(snd_emu1010_dac_pads); i++) {
     1579            err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_dac_pads[i], emu));
     1580            if (err < 0)
     1581                return err;
     1582        }
     1583        err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_internal_clock, emu));
     1584        if (err < 0)
     1585            return err;
     1586    }
     1587
     1588    return 0;
     1589}
  • GPL/trunk/alsa-kernel/pci/emu10k1/emumpu401.c

    r34 r84  
    3131static inline unsigned char mpu401_read(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *mpu, int idx)
    3232{
    33         if (emu->audigy)
    34                 return (unsigned char)snd_emu10k1_ptr_read(emu, mpu->port + idx, 0);
    35         else
    36                 return inb(emu->port + mpu->port + idx);
     33    if (emu->audigy)
     34        return (unsigned char)snd_emu10k1_ptr_read(emu, mpu->port + idx, 0);
     35    else
     36        return inb(emu->port + mpu->port + idx);
    3737}
    3838
    3939static inline void mpu401_write(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *mpu, int data, int idx)
    4040{
    41         if (emu->audigy)
    42                 snd_emu10k1_ptr_write(emu, mpu->port + idx, 0, data);
    43         else
    44                 outb(data, emu->port + mpu->port + idx);
     41    if (emu->audigy)
     42        snd_emu10k1_ptr_write(emu, mpu->port + idx, 0, data);
     43    else
     44        outb(data, emu->port + mpu->port + idx);
    4545}
    4646
     
    5959static void mpu401_clear_rx(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *mpu)
    6060{
    61         int timeout = 100000;
    62         for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--)
    63                 mpu401_read_data(emu, mpu);
     61    int timeout = 100000;
     62    for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--)
     63        mpu401_read_data(emu, mpu);
    6464#ifdef CONFIG_SND_DEBUG
    65         if (timeout <= 0)
    66                 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
     65    if (timeout <= 0)
     66        snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
    6767#endif
    6868}
     
    7070/*
    7171
    72  */
     72*/
    7373
    7474static void do_emu10k1_midi_interrupt(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, unsigned int status)
    7575{
    76         unsigned char byte;
    77 
    78         if (midi->rmidi == NULL) {
    79                 snd_emu10k1_intr_disable(emu, midi->tx_enable | midi->rx_enable);
    80                 return;
    81         }
    82 
    83         spin_lock(&midi->input_lock);
    84         if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) {
    85                 if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
    86                         mpu401_clear_rx(emu, midi);
    87                 } else {
    88                         byte = mpu401_read_data(emu, midi);
    89                         spin_unlock(&midi->input_lock);
    90                         if (midi->substream_input)
    91                                 snd_rawmidi_receive(midi->substream_input, &byte, 1);
    92                         spin_lock(&midi->input_lock);
    93                 }
    94         }
    95         spin_unlock(&midi->input_lock);
    96 
    97         spin_lock(&midi->output_lock);
    98         if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) {
    99                 if (midi->substream_output &&
    100                     snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
    101                         mpu401_write_data(emu, midi, byte);
    102                 } else {
    103                         snd_emu10k1_intr_disable(emu, midi->tx_enable);
    104                 }
    105         }
    106         spin_unlock(&midi->output_lock);
     76    unsigned char byte;
     77
     78    if (midi->rmidi == NULL) {
     79        snd_emu10k1_intr_disable(emu, midi->tx_enable | midi->rx_enable);
     80        return;
     81    }
     82
     83    spin_lock(&midi->input_lock);
     84    if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) {
     85        if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
     86            mpu401_clear_rx(emu, midi);
     87        } else {
     88            byte = mpu401_read_data(emu, midi);
     89            if (midi->substream_input)
     90                snd_rawmidi_receive(midi->substream_input, &byte, 1);
     91        }
     92    }
     93    spin_unlock(&midi->input_lock);
     94
     95    spin_lock(&midi->output_lock);
     96    if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) {
     97        if (midi->substream_output &&
     98            snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
     99            mpu401_write_data(emu, midi, byte);
     100        } else {
     101            snd_emu10k1_intr_disable(emu, midi->tx_enable);
     102        }
     103    }
     104    spin_unlock(&midi->output_lock);
    107105}
    108106
    109107static void snd_emu10k1_midi_interrupt(struct snd_emu10k1 *emu, unsigned int status)
    110108{
    111         do_emu10k1_midi_interrupt(emu, &emu->midi, status);
     109    do_emu10k1_midi_interrupt(emu, &emu->midi, status);
    112110}
    113111
    114112static void snd_emu10k1_midi_interrupt2(struct snd_emu10k1 *emu, unsigned int status)
    115113{
    116         do_emu10k1_midi_interrupt(emu, &emu->midi2, status);
    117 }
    118 
    119 static void snd_emu10k1_midi_cmd(struct snd_emu10k1 * emu, struct snd_emu10k1_midi *midi, unsigned char cmd, int ack)
    120 {
    121         unsigned long flags;
    122         int timeout, ok;
    123 
    124         spin_lock_irqsave(&midi->input_lock, flags);
    125         mpu401_write_data(emu, midi, 0x00);
    126         /* mpu401_clear_rx(emu, midi); */
    127 
    128         mpu401_write_cmd(emu, midi, cmd);
    129         if (ack) {
    130                 ok = 0;
    131                 timeout = 10000;
    132                 while (!ok && timeout-- > 0) {
    133                         if (mpu401_input_avail(emu, midi)) {
    134                                 if (mpu401_read_data(emu, midi) == MPU401_ACK)
    135                                         ok = 1;
    136                         }
    137                 }
    138                 if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK)
    139                         ok = 1;
    140         } else {
    141                 ok = 1;
    142         }
    143         spin_unlock_irqrestore(&midi->input_lock, flags);
    144         if (!ok)
    145                 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
    146                            cmd, emu->port,
    147                            mpu401_read_stat(emu, midi),
    148                            mpu401_read_data(emu, midi));
    149 }
    150 
    151 static int snd_emu10k1_midi_input_open(snd_rawmidi_substream_t * substream)
    152 {
    153         struct snd_emu10k1 *emu;
    154         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    155         unsigned long flags;
    156 
    157         emu = midi->emu;
    158         snd_assert(emu, return -ENXIO);
    159         spin_lock_irqsave(&midi->open_lock, flags);
    160         midi->midi_mode |= EMU10K1_MIDI_MODE_INPUT;
    161         midi->substream_input = substream;
    162         if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) {
    163                 spin_unlock_irqrestore(&midi->open_lock, flags);
    164                 snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1);
    165                 snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
    166         } else {
    167                 spin_unlock_irqrestore(&midi->open_lock, flags);
    168         }
    169         return 0;
    170 }
    171 
    172 static int snd_emu10k1_midi_output_open(snd_rawmidi_substream_t * substream)
    173 {
    174         struct snd_emu10k1 *emu;
    175         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    176         unsigned long flags;
    177 
    178         emu = midi->emu;
    179         snd_assert(emu, return -ENXIO);
    180         spin_lock_irqsave(&midi->open_lock, flags);
    181         midi->midi_mode |= EMU10K1_MIDI_MODE_OUTPUT;
    182         midi->substream_output = substream;
    183         if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
    184                 spin_unlock_irqrestore(&midi->open_lock, flags);
    185                 snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1);
    186                 snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
    187         } else {
    188                 spin_unlock_irqrestore(&midi->open_lock, flags);
    189         }
    190         return 0;
    191 }
    192 
    193 static int snd_emu10k1_midi_input_close(snd_rawmidi_substream_t * substream)
    194 {
    195         struct snd_emu10k1 *emu;
    196         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    197         unsigned long flags;
    198 
    199         emu = midi->emu;
    200         snd_assert(emu, return -ENXIO);
    201         spin_lock_irqsave(&midi->open_lock, flags);
    202         snd_emu10k1_intr_disable(emu, midi->rx_enable);
    203         midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT;
    204         midi->substream_input = NULL;
    205         if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) {
    206                 spin_unlock_irqrestore(&midi->open_lock, flags);
    207                 snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0);
    208         } else {
    209                 spin_unlock_irqrestore(&midi->open_lock, flags);
    210         }
    211         return 0;
    212 }
    213 
    214 static int snd_emu10k1_midi_output_close(snd_rawmidi_substream_t * substream)
    215 {
    216         struct snd_emu10k1 *emu;
    217         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    218         unsigned long flags;
    219 
    220         emu = midi->emu;
    221         snd_assert(emu, return -ENXIO);
    222         spin_lock_irqsave(&midi->open_lock, flags);
    223         snd_emu10k1_intr_disable(emu, midi->tx_enable);
    224         midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT;
    225         midi->substream_output = NULL;
    226         if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
    227                 spin_unlock_irqrestore(&midi->open_lock, flags);
    228                 snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0);
    229         } else {
    230                 spin_unlock_irqrestore(&midi->open_lock, flags);
    231         }
    232         return 0;
    233 }
    234 
    235 static void snd_emu10k1_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
    236 {
    237         struct snd_emu10k1 *emu;
    238         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    239         emu = midi->emu;
    240         snd_assert(emu, return);
    241 
    242         if (up)
    243                 snd_emu10k1_intr_enable(emu, midi->rx_enable);
    244         else
    245                 snd_emu10k1_intr_disable(emu, midi->rx_enable);
    246 }
    247 
    248 static void snd_emu10k1_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
    249 {
    250         struct snd_emu10k1 *emu;
    251         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
    252         unsigned long flags;
    253 
    254         emu = midi->emu;
    255         snd_assert(emu, return);
    256 
    257         if (up) {
    258                 int max = 4;
    259                 unsigned char byte;
    260        
    261                 /* try to send some amount of bytes here before interrupts */
    262                 spin_lock_irqsave(&midi->output_lock, flags);
    263                 while (max > 0) {
    264                         if (mpu401_output_ready(emu, midi)) {
    265                                 if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT) ||
    266                                     snd_rawmidi_transmit(substream, &byte, 1) != 1) {
    267                                         /* no more data */
    268                                         spin_unlock_irqrestore(&midi->output_lock, flags);
    269                                         return;
    270                                 }
    271                                 mpu401_write_data(emu, midi, byte);
    272                                 max--;
    273                         } else {
    274                                 break;
    275                         }
    276                 }
    277                 spin_unlock_irqrestore(&midi->output_lock, flags);
    278                 snd_emu10k1_intr_enable(emu, midi->tx_enable);
    279         } else {
    280                 snd_emu10k1_intr_disable(emu, midi->tx_enable);
    281         }
     114    do_emu10k1_midi_interrupt(emu, &emu->midi2, status);
     115}
     116
     117static int snd_emu10k1_midi_cmd(struct snd_emu10k1 * emu, struct snd_emu10k1_midi *midi, unsigned char cmd, int ack)
     118{
     119    unsigned long flags;
     120    int timeout, ok;
     121
     122    spin_lock_irqsave(&midi->input_lock, flags);
     123    mpu401_write_data(emu, midi, 0x00);
     124    /* mpu401_clear_rx(emu, midi); */
     125
     126    mpu401_write_cmd(emu, midi, cmd);
     127    if (ack) {
     128        ok = 0;
     129        timeout = 10000;
     130        while (!ok && timeout-- > 0) {
     131            if (mpu401_input_avail(emu, midi)) {
     132                if (mpu401_read_data(emu, midi) == MPU401_ACK)
     133                    ok = 1;
     134            }
     135        }
     136        if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK)
     137            ok = 1;
     138    } else {
     139        ok = 1;
     140    }
     141    spin_unlock_irqrestore(&midi->input_lock, flags);
     142    if (!ok) {
     143        snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
     144                   cmd, emu->port,
     145                   mpu401_read_stat(emu, midi),
     146                   mpu401_read_data(emu, midi));
     147        return 1;
     148    }
     149    return 0;
     150}
     151
     152static int snd_emu10k1_midi_input_open(struct snd_rawmidi_substream *substream)
     153{
     154    struct snd_emu10k1 *emu;
     155    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     156    unsigned long flags;
     157
     158    emu = midi->emu;
     159    snd_assert(emu, return -ENXIO);
     160    spin_lock_irqsave(&midi->open_lock, flags);
     161    midi->midi_mode |= EMU10K1_MIDI_MODE_INPUT;
     162    midi->substream_input = substream;
     163    if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) {
     164        spin_unlock_irqrestore(&midi->open_lock, flags);
     165        if (snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1))
     166            goto error_out;
     167        if (snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
     168            goto error_out;
     169    } else {
     170        spin_unlock_irqrestore(&midi->open_lock, flags);
     171    }
     172    return 0;
     173
     174    error_out:
     175        return -EIO;
     176}
     177
     178static int snd_emu10k1_midi_output_open(struct snd_rawmidi_substream *substream)
     179{
     180    struct snd_emu10k1 *emu;
     181    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     182    unsigned long flags;
     183
     184    emu = midi->emu;
     185    snd_assert(emu, return -ENXIO);
     186    spin_lock_irqsave(&midi->open_lock, flags);
     187    midi->midi_mode |= EMU10K1_MIDI_MODE_OUTPUT;
     188    midi->substream_output = substream;
     189    if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
     190        spin_unlock_irqrestore(&midi->open_lock, flags);
     191        if (snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 1))
     192            goto error_out;
     193        if (snd_emu10k1_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
     194            goto error_out;
     195    } else {
     196        spin_unlock_irqrestore(&midi->open_lock, flags);
     197    }
     198    return 0;
     199
     200    error_out:
     201        return -EIO;
     202}
     203
     204static int snd_emu10k1_midi_input_close(struct snd_rawmidi_substream *substream)
     205{
     206    struct snd_emu10k1 *emu;
     207    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     208    unsigned long flags;
     209    int err = 0;
     210
     211    emu = midi->emu;
     212    snd_assert(emu, return -ENXIO);
     213    spin_lock_irqsave(&midi->open_lock, flags);
     214    snd_emu10k1_intr_disable(emu, midi->rx_enable);
     215    midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT;
     216    midi->substream_input = NULL;
     217    if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT)) {
     218        spin_unlock_irqrestore(&midi->open_lock, flags);
     219        err = snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0);
     220    } else {
     221        spin_unlock_irqrestore(&midi->open_lock, flags);
     222    }
     223    return err;
     224}
     225
     226static int snd_emu10k1_midi_output_close(struct snd_rawmidi_substream *substream)
     227{
     228    struct snd_emu10k1 *emu;
     229    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     230    unsigned long flags;
     231    int err = 0;
     232
     233    emu = midi->emu;
     234    snd_assert(emu, return -ENXIO);
     235    spin_lock_irqsave(&midi->open_lock, flags);
     236    snd_emu10k1_intr_disable(emu, midi->tx_enable);
     237    midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT;
     238    midi->substream_output = NULL;
     239    if (!(midi->midi_mode & EMU10K1_MIDI_MODE_INPUT)) {
     240        spin_unlock_irqrestore(&midi->open_lock, flags);
     241        err = snd_emu10k1_midi_cmd(emu, midi, MPU401_RESET, 0);
     242    } else {
     243        spin_unlock_irqrestore(&midi->open_lock, flags);
     244    }
     245    return err;
     246}
     247
     248static void snd_emu10k1_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
     249{
     250    struct snd_emu10k1 *emu;
     251    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     252    emu = midi->emu;
     253    snd_assert(emu, return);
     254
     255    if (up)
     256        snd_emu10k1_intr_enable(emu, midi->rx_enable);
     257    else
     258        snd_emu10k1_intr_disable(emu, midi->rx_enable);
     259}
     260
     261static void snd_emu10k1_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
     262{
     263    struct snd_emu10k1 *emu;
     264    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data;
     265    unsigned long flags;
     266
     267    emu = midi->emu;
     268    snd_assert(emu, return);
     269
     270    if (up) {
     271        int max = 4;
     272        unsigned char byte;
     273
     274        /* try to send some amount of bytes here before interrupts */
     275        spin_lock_irqsave(&midi->output_lock, flags);
     276        while (max > 0) {
     277            if (mpu401_output_ready(emu, midi)) {
     278                if (!(midi->midi_mode & EMU10K1_MIDI_MODE_OUTPUT) ||
     279                    snd_rawmidi_transmit(substream, &byte, 1) != 1) {
     280                    /* no more data */
     281                    spin_unlock_irqrestore(&midi->output_lock, flags);
     282                    return;
     283                }
     284                mpu401_write_data(emu, midi, byte);
     285                max--;
     286            } else {
     287                break;
     288            }
     289        }
     290        spin_unlock_irqrestore(&midi->output_lock, flags);
     291        snd_emu10k1_intr_enable(emu, midi->tx_enable);
     292    } else {
     293        snd_emu10k1_intr_disable(emu, midi->tx_enable);
     294    }
    282295}
    283296
    284297/*
    285298
    286  */
    287 
    288 #ifdef TARGET_OS2
    289 static snd_rawmidi_ops_t snd_emu10k1_midi_output =
    290 {
    291         snd_emu10k1_midi_output_open,
    292         snd_emu10k1_midi_output_close,
    293         snd_emu10k1_midi_output_trigger,0
     299*/
     300
     301static struct snd_rawmidi_ops snd_emu10k1_midi_output =
     302{
     303    .open =             snd_emu10k1_midi_output_open,
     304    .close =    snd_emu10k1_midi_output_close,
     305    .trigger =  snd_emu10k1_midi_output_trigger,
    294306};
    295307
    296 static snd_rawmidi_ops_t snd_emu10k1_midi_input =
    297 {
    298         snd_emu10k1_midi_input_open,
    299         snd_emu10k1_midi_input_close,
    300         snd_emu10k1_midi_input_trigger,0
     308static struct snd_rawmidi_ops snd_emu10k1_midi_input =
     309{
     310    .open =             snd_emu10k1_midi_input_open,
     311    .close =    snd_emu10k1_midi_input_close,
     312    .trigger =  snd_emu10k1_midi_input_trigger,
    301313};
    302 #else
    303 static snd_rawmidi_ops_t snd_emu10k1_midi_output =
    304 {
    305         open:           snd_emu10k1_midi_output_open,
    306         close:          snd_emu10k1_midi_output_close,
    307         trigger:        snd_emu10k1_midi_output_trigger,
    308 };
    309 
    310 static snd_rawmidi_ops_t snd_emu10k1_midi_input =
    311 {
    312         open:           snd_emu10k1_midi_input_open,
    313         close:          snd_emu10k1_midi_input_close,
    314         trigger:        snd_emu10k1_midi_input_trigger,
    315 };
    316 #endif
    317 
    318 static void snd_emu10k1_midi_free(snd_rawmidi_t *rmidi)
    319 {
    320         struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)rmidi->private_data;
    321         midi->interrupt = NULL;
    322         midi->rmidi = NULL;
     314
     315static void snd_emu10k1_midi_free(struct snd_rawmidi *rmidi)
     316{
     317    struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)rmidi->private_data;
     318    midi->interrupt = NULL;
     319    midi->rmidi = NULL;
    323320}
    324321
    325322static int __devinit emu10k1_midi_init(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *midi, int device, char *name)
    326323{
    327         snd_rawmidi_t *rmidi;
    328         int err;
    329 
    330         if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
    331                 return err;
    332         midi->emu = emu;
    333         spin_lock_init(&midi->open_lock);
    334         spin_lock_init(&midi->input_lock);
    335         spin_lock_init(&midi->output_lock);
    336         strcpy(rmidi->name, name);
    337         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1_midi_output);
    338         snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1_midi_input);
    339         rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
    340                              SNDRV_RAWMIDI_INFO_INPUT |
    341                              SNDRV_RAWMIDI_INFO_DUPLEX;
    342         rmidi->private_data = midi;
    343         rmidi->private_free = snd_emu10k1_midi_free;
    344         midi->rmidi = rmidi;
    345         return 0;
     324    struct snd_rawmidi *rmidi;
     325    int err;
     326
     327    if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
     328        return err;
     329    midi->emu = emu;
     330    spin_lock_init(&midi->open_lock);
     331    spin_lock_init(&midi->input_lock);
     332    spin_lock_init(&midi->output_lock);
     333    strcpy(rmidi->name, name);
     334    snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1_midi_output);
     335    snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1_midi_input);
     336    rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
     337        SNDRV_RAWMIDI_INFO_INPUT |
     338        SNDRV_RAWMIDI_INFO_DUPLEX;
     339    rmidi->private_data = midi;
     340    rmidi->private_free = snd_emu10k1_midi_free;
     341    midi->rmidi = rmidi;
     342    return 0;
    346343}
    347344
    348345int __devinit snd_emu10k1_midi(struct snd_emu10k1 *emu)
    349346{
    350         struct snd_emu10k1_midi *midi = &emu->midi;
    351         int err;
    352 
    353         if ((err = emu10k1_midi_init(emu, midi, 0, "EMU10K1 MPU-401 (UART)")) < 0)
    354                 return err;
    355 
    356         midi->tx_enable = INTE_MIDITXENABLE;
    357         midi->rx_enable = INTE_MIDIRXENABLE;
    358         midi->port = MUDATA;
    359         midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
    360         midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
    361         midi->interrupt = snd_emu10k1_midi_interrupt;
    362         return 0;
     347    struct snd_emu10k1_midi *midi = &emu->midi;
     348    int err;
     349
     350    if ((err = emu10k1_midi_init(emu, midi, 0, "EMU10K1 MPU-401 (UART)")) < 0)
     351        return err;
     352
     353    midi->tx_enable = INTE_MIDITXENABLE;
     354    midi->rx_enable = INTE_MIDIRXENABLE;
     355    midi->port = MUDATA;
     356    midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
     357    midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
     358    midi->interrupt = snd_emu10k1_midi_interrupt;
     359    return 0;
    363360}
    364361
    365362int __devinit snd_emu10k1_audigy_midi(struct snd_emu10k1 *emu)
    366363{
    367         struct snd_emu10k1_midi *midi;
    368         int err;
    369 
    370         midi = &emu->midi;
    371         if ((err = emu10k1_midi_init(emu, midi, 0, "Audigy MPU-401 (UART)")) < 0)
    372                 return err;
    373 
    374         midi->tx_enable = INTE_MIDITXENABLE;
    375         midi->rx_enable = INTE_MIDIRXENABLE;
    376         midi->port = A_MUDATA1;
    377         midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
    378         midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
    379         midi->interrupt = snd_emu10k1_midi_interrupt;
    380 
    381         midi = &emu->midi2;
    382         if ((err = emu10k1_midi_init(emu, midi, 1, "Audigy MPU-401 #2")) < 0)
    383                 return err;
    384 
    385         midi->tx_enable = INTE_A_MIDITXENABLE2;
    386         midi->rx_enable = INTE_A_MIDIRXENABLE2;
    387         midi->port = A_MUDATA2;
    388         midi->ipr_tx = IPR_A_MIDITRANSBUFEMPTY2;
    389         midi->ipr_rx = IPR_A_MIDIRECVBUFEMPTY2;
    390         midi->interrupt = snd_emu10k1_midi_interrupt2;
    391         return 0;
    392 }
     364    struct snd_emu10k1_midi *midi;
     365    int err;
     366
     367    midi = &emu->midi;
     368    if ((err = emu10k1_midi_init(emu, midi, 0, "Audigy MPU-401 (UART)")) < 0)
     369        return err;
     370
     371    midi->tx_enable = INTE_MIDITXENABLE;
     372    midi->rx_enable = INTE_MIDIRXENABLE;
     373    midi->port = A_MUDATA1;
     374    midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
     375    midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
     376    midi->interrupt = snd_emu10k1_midi_interrupt;
     377
     378    midi = &emu->midi2;
     379    if ((err = emu10k1_midi_init(emu, midi, 1, "Audigy MPU-401 #2")) < 0)
     380        return err;
     381
     382    midi->tx_enable = INTE_A_MIDITXENABLE2;
     383    midi->rx_enable = INTE_A_MIDIRXENABLE2;
     384    midi->port = A_MUDATA2;
     385    midi->ipr_tx = IPR_A_MIDITRANSBUFEMPTY2;
     386    midi->ipr_rx = IPR_A_MIDIRECVBUFEMPTY2;
     387    midi->interrupt = snd_emu10k1_midi_interrupt2;
     388    return 0;
     389}
  • GPL/trunk/alsa-kernel/pci/emu10k1/emupcm.c

    r34 r84  
    33 *                   Creative Labs, Inc.
    44 *  Routines for control of EMU10K1 chips / PCM routines
     5 *  Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
    56 *
    67 *  BUGS:
     
    2627 */
    2728
    28 #define __NO_VERSION__
    2929#include <sound/driver.h>
     30#include <linux/pci.h>
     31#include <linux/delay.h>
    3032#include <linux/slab.h>
    3133#include <linux/time.h>
     34#include <linux/init.h>
    3235#include <sound/core.h>
    3336#include <sound/emu10k1.h>
    3437
    35 static inline snd_ctl_elem_id_t *snd_ctl_build_ioff(snd_ctl_elem_id_t *dst_id,
    36                                                     snd_kcontrol_t *src_kctl,
    37                                                     unsigned int offset)
    38 {
    39     *dst_id = src_kctl->id;
    40     dst_id->index += offset;
    41     dst_id->numid += offset;
    42     return dst_id;
    43 }
    44 
    45 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *voice)
    46 {
    47     struct snd_emu10k1_pcm *epcm;
    48 
    49     if ((epcm = voice->epcm) == NULL)
    50         return;
    51     if (epcm->substream == NULL)
    52         return;
     38static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu,
     39                                      struct snd_emu10k1_voice *voice)
     40{
     41        struct snd_emu10k1_pcm *epcm;
     42
     43        if ((epcm = voice->epcm) == NULL)
     44                return;
     45        if (epcm->substream == NULL)
     46                return;
    5347#if 0
    54     printk("IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
    55            epcm->substream->runtime->hw->pointer(emu, epcm->substream),
    56            snd_pcm_lib_period_bytes(epcm->substream),
    57            snd_pcm_lib_buffer_bytes(epcm->substream));
     48        printk("IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
     49                        epcm->substream->runtime->hw->pointer(emu, epcm->substream),
     50                        snd_pcm_lib_period_bytes(epcm->substream),
     51                        snd_pcm_lib_buffer_bytes(epcm->substream));
    5852#endif
    59     snd_pcm_period_elapsed(epcm->substream);
    60 }
    61 
    62 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu, unsigned int status)
     53        snd_pcm_period_elapsed(epcm->substream);
     54}
     55
     56static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu,
     57                                              unsigned int status)
    6358{
    6459#if 0
    65     if (status & IPR_ADCBUFHALFFULL) {
    66         if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
    67             return;
    68     }
     60        if (status & IPR_ADCBUFHALFFULL) {
     61                if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
     62                        return;
     63        }
    6964#endif
    70     snd_pcm_period_elapsed(emu->pcm_capture_substream);
    71 }
    72 
    73 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu, unsigned int status)
     65        snd_pcm_period_elapsed(emu->pcm_capture_substream);
     66}
     67
     68static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu,
     69                                              unsigned int status)
    7470{
    7571#if 0
    76     if (status & IPR_MICBUFHALFFULL) {
    77         if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
    78             return;
    79     }
     72        if (status & IPR_MICBUFHALFFULL) {
     73                if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
     74                        return;
     75        }
    8076#endif
    81     snd_pcm_period_elapsed(emu->pcm_capture_mic_substream);
    82 }
    83 
    84 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu, unsigned int status)
     77        snd_pcm_period_elapsed(emu->pcm_capture_mic_substream);
     78}
     79
     80static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu,
     81                                          unsigned int status)
    8582{
    8683#if 0
    87     if (status & IPR_EFXBUFHALFFULL) {
    88         if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
    89             return;
    90     }
     84        if (status & IPR_EFXBUFHALFFULL) {
     85                if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
     86                        return;
     87        }
    9188#endif
    92     snd_pcm_period_elapsed(emu->pcm_capture_efx_substream);
    93 }
    94 
    95 static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(snd_pcm_substream_t * substream)
    96 {
    97     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    98     snd_pcm_runtime_t *runtime = substream->runtime;
    99     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    100     unsigned int ptr;
    101 
    102     if (!epcm->running)
    103         return 0;
    104     ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
    105     ptr += runtime->buffer_size;
    106     ptr -= epcm->ccca_start_addr;
    107     ptr %= runtime->buffer_size;
    108 
    109     return ptr;
     89        snd_pcm_period_elapsed(emu->pcm_capture_efx_substream);
     90}       
     91
     92static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream *substream)
     93{
     94        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     95        struct snd_pcm_runtime *runtime = substream->runtime;
     96        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     97        unsigned int ptr;
     98
     99        if (!epcm->running)
     100                return 0;
     101        ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
     102        ptr += runtime->buffer_size;
     103        ptr -= epcm->ccca_start_addr;
     104        ptr %= runtime->buffer_size;
     105
     106        return ptr;
    110107}
    111108
    112109static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voices)
    113110{
    114     int err, i;
    115 
    116     if (epcm->voices[1] != NULL && voices < 2) {
    117         snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
    118         epcm->voices[1] = NULL;
    119     }
    120     for (i = 0; i < voices; i++) {
    121         if (epcm->voices[i] == NULL)
    122             break;
    123     }
    124     if (i == voices)
    125         return 0;               /* already allocated */
    126     for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) {
    127         if (epcm->voices[i]) {
    128             snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
    129             epcm->voices[i] = NULL;
    130         }
    131     }
    132     err = snd_emu10k1_voice_alloc(epcm->emu,
    133                                   epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
    134                                   voices,
    135                                   &epcm->voices[0]);
    136     if (err < 0)
    137         return err;
    138     epcm->voices[0]->epcm = epcm;
    139     if (voices > 1) {
    140         for (i = 1; i < voices; i++) {
    141             epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i];
    142             epcm->voices[i]->epcm = epcm;
    143         }
    144     }
    145     if (epcm->extra == NULL) {
    146         err = snd_emu10k1_voice_alloc(epcm->emu,
    147                                       epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
    148                                       1,
    149                                       &epcm->extra);
    150         if (err < 0) {
    151             // printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame);
    152             for (i = 0; i < voices; i++) {
    153                 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
    154                 epcm->voices[i] = NULL;
    155             }
    156             return err;
    157         }
    158         epcm->extra->epcm = epcm;
    159         epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
    160     }
    161     return 0;
     111        int err, i;
     112
     113        if (epcm->voices[1] != NULL && voices < 2) {
     114                snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
     115                epcm->voices[1] = NULL;
     116        }
     117        for (i = 0; i < voices; i++) {
     118                if (epcm->voices[i] == NULL)
     119                        break;
     120        }
     121        if (i == voices)
     122                return 0; /* already allocated */
     123
     124        for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) {
     125                if (epcm->voices[i]) {
     126                        snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
     127                        epcm->voices[i] = NULL;
     128                }
     129        }
     130        err = snd_emu10k1_voice_alloc(epcm->emu,
     131                                      epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
     132                                      voices,
     133                                      &epcm->voices[0]);
     134       
     135        if (err < 0)
     136                return err;
     137        epcm->voices[0]->epcm = epcm;
     138        if (voices > 1) {
     139                for (i = 1; i < voices; i++) {
     140                        epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i];
     141                        epcm->voices[i]->epcm = epcm;
     142                }
     143        }
     144        if (epcm->extra == NULL) {
     145                err = snd_emu10k1_voice_alloc(epcm->emu,
     146                                              epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
     147                                              1,
     148                                              &epcm->extra);
     149                if (err < 0) {
     150                        /* printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame); */
     151                        for (i = 0; i < voices; i++) {
     152                                snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
     153                                epcm->voices[i] = NULL;
     154                        }
     155                        return err;
     156                }
     157                epcm->extra->epcm = epcm;
     158                epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
     159        }
     160        return 0;
    162161}
    163162
    164163static unsigned int capture_period_sizes[31] = {
    165     384,        448,    512,    640,
    166     384*2,      448*2,  512*2,  640*2,
    167     384*4,      448*4,  512*4,  640*4,
    168     384*8,      448*8,  512*8,  640*8,
    169     384*16,     448*16, 512*16, 640*16,
    170     384*32,     448*32, 512*32, 640*32,
    171     384*64,     448*64, 512*64, 640*64,
    172     384*128,448*128,512*128
     164        384,    448,    512,    640,
     165        384*2,  448*2,  512*2,  640*2,
     166        384*4,  448*4,  512*4,  640*4,
     167        384*8,  448*8,  512*8,  640*8,
     168        384*16, 448*16, 512*16, 640*16,
     169        384*32, 448*32, 512*32, 640*32,
     170        384*64, 448*64, 512*64, 640*64,
     171        384*128,448*128,512*128
    173172};
    174173
    175 static snd_pcm_hw_constraint_list_t hw_constraints_capture_period_sizes = {
    176     31,
    177     capture_period_sizes,
    178     0
     174static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = {
     175        .count = 31,
     176        .list = capture_period_sizes,
     177        .mask = 0
    179178};
    180179
    181180static unsigned int capture_rates[8] = {
    182     8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
     181        8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
    183182};
    184183
    185 static snd_pcm_hw_constraint_list_t hw_constraints_capture_rates = {
    186     8,
    187     capture_rates,
    188     0
     184static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = {
     185        .count = 8,
     186        .list = capture_rates,
     187        .mask = 0
    189188};
    190189
    191190static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate)
    192191{
    193     switch (rate) {
    194     case 8000:  return ADCCR_SAMPLERATE_8;
    195     case 11025: return ADCCR_SAMPLERATE_11;
    196     case 16000: return ADCCR_SAMPLERATE_16;
    197     case 22050: return ADCCR_SAMPLERATE_22;
    198     case 24000: return ADCCR_SAMPLERATE_24;
    199     case 32000: return ADCCR_SAMPLERATE_32;
    200     case 44100: return ADCCR_SAMPLERATE_44;
    201     case 48000: return ADCCR_SAMPLERATE_48;
    202     default:
    203         snd_BUG();
    204         return ADCCR_SAMPLERATE_8;
    205     }
     192        switch (rate) {
     193        case 8000:      return ADCCR_SAMPLERATE_8;
     194        case 11025:     return ADCCR_SAMPLERATE_11;
     195        case 16000:     return ADCCR_SAMPLERATE_16;
     196        case 22050:     return ADCCR_SAMPLERATE_22;
     197        case 24000:     return ADCCR_SAMPLERATE_24;
     198        case 32000:     return ADCCR_SAMPLERATE_32;
     199        case 44100:     return ADCCR_SAMPLERATE_44;
     200        case 48000:     return ADCCR_SAMPLERATE_48;
     201        default:
     202                        snd_BUG();
     203                        return ADCCR_SAMPLERATE_8;
     204        }
    206205}
    207206
    208207static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate)
    209208{
    210     switch (rate) {
    211     case 8000:  return A_ADCCR_SAMPLERATE_8;
    212     case 11025: return A_ADCCR_SAMPLERATE_11;
    213     case 12000: return A_ADCCR_SAMPLERATE_12; /* really supported? */
    214     case 16000: return ADCCR_SAMPLERATE_16;
    215     case 22050: return ADCCR_SAMPLERATE_22;
    216     case 24000: return ADCCR_SAMPLERATE_24;
    217     case 32000: return ADCCR_SAMPLERATE_32;
    218     case 44100: return ADCCR_SAMPLERATE_44;
    219     case 48000: return ADCCR_SAMPLERATE_48;
    220     default:
    221         snd_BUG();
    222         return A_ADCCR_SAMPLERATE_8;
    223     }
     209        switch (rate) {
     210        case 8000:      return A_ADCCR_SAMPLERATE_8;
     211        case 11025:     return A_ADCCR_SAMPLERATE_11;
     212        case 12000:     return A_ADCCR_SAMPLERATE_12; /* really supported? */
     213        case 16000:     return ADCCR_SAMPLERATE_16;
     214        case 22050:     return ADCCR_SAMPLERATE_22;
     215        case 24000:     return ADCCR_SAMPLERATE_24;
     216        case 32000:     return ADCCR_SAMPLERATE_32;
     217        case 44100:     return ADCCR_SAMPLERATE_44;
     218        case 48000:     return ADCCR_SAMPLERATE_48;
     219        default:
     220                        snd_BUG();
     221                        return A_ADCCR_SAMPLERATE_8;
     222        }
    224223}
    225224
    226225static unsigned int emu10k1_calc_pitch_target(unsigned int rate)
    227226{
    228     unsigned int pitch_target;
    229 
    230     pitch_target = (rate << 8) / 375;
    231     pitch_target = (pitch_target >> 1) + (pitch_target & 1);
    232     return pitch_target;
     227        unsigned int pitch_target;
     228
     229        pitch_target = (rate << 8) / 375;
     230        pitch_target = (pitch_target >> 1) + (pitch_target & 1);
     231        return pitch_target;
    233232}
    234233
     
    242241static unsigned int emu10k1_select_interprom(unsigned int pitch_target)
    243242{
    244     if (pitch_target == PITCH_48000)
    245         return CCCA_INTERPROM_0;
    246     else if (pitch_target < PITCH_48000)
    247         return CCCA_INTERPROM_1;
    248     else if (pitch_target >= PITCH_96000)
    249         return CCCA_INTERPROM_0;
    250     else if (pitch_target >= PITCH_85000)
    251         return CCCA_INTERPROM_6;
    252     else if (pitch_target >= PITCH_80726)
    253         return CCCA_INTERPROM_5;
    254     else if (pitch_target >= PITCH_67882)
    255         return CCCA_INTERPROM_4;
    256     else if (pitch_target >= PITCH_57081)
    257         return CCCA_INTERPROM_3;
    258     else
    259         return CCCA_INTERPROM_2;
     243        if (pitch_target == PITCH_48000)
     244                return CCCA_INTERPROM_0;
     245        else if (pitch_target < PITCH_48000)
     246                return CCCA_INTERPROM_1;
     247        else if (pitch_target >= PITCH_96000)
     248                return CCCA_INTERPROM_0;
     249        else if (pitch_target >= PITCH_85000)
     250                return CCCA_INTERPROM_6;
     251        else if (pitch_target >= PITCH_80726)
     252                return CCCA_INTERPROM_5;
     253        else if (pitch_target >= PITCH_67882)
     254                return CCCA_INTERPROM_4;
     255        else if (pitch_target >= PITCH_57081)
     256                return CCCA_INTERPROM_3;
     257        else 
     258                return CCCA_INTERPROM_2;
    260259}
    261260
    262261/*
    263  * calculate cache invalidate size
     262 * calculate cache invalidate size 
    264263 *
    265264 * stereo: channel is stereo
     
    268267 * returns: cache invalidate size in samples
    269268 */
    270 static int inline emu10k1_ccis(int stereo, int w_16)
    271 {
    272     if (w_16) {
    273         return stereo ? 24 : 26;
    274     } else {
    275         return stereo ? 24*2 : 26*2;
    276     }
     269static inline int emu10k1_ccis(int stereo, int w_16)
     270{
     271        if (w_16) {
     272                return stereo ? 24 : 26;
     273        } else {
     274                return stereo ? 24*2 : 26*2;
     275        }
    277276}
    278277
    279278static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
    280                                        int master, int extra,
    281                                        struct snd_emu10k1_voice *evoice,
    282                                        unsigned int start_addr,
    283                                        unsigned int end_addr,
    284                                        struct snd_emu10k1_pcm_mixer *mix)
    285 {
    286     snd_pcm_substream_t *substream = evoice->epcm->substream;
    287     snd_pcm_runtime_t *runtime = substream->runtime;
    288     unsigned int silent_page, tmp;
    289     int voice, stereo, w_16;
    290     unsigned char attn, send_amount[8];
    291     unsigned char send_routing[8];
    292     unsigned long flags;
    293     unsigned int pitch_target;
    294     unsigned int ccis;
    295 
    296     voice = evoice->number;
    297     stereo = runtime->channels == 2;
    298     w_16 = snd_pcm_format_width(runtime->format) == 16;
    299 
    300     if (!extra && stereo) {
    301         start_addr >>= 1;
    302         end_addr >>= 1;
    303     }
    304     if (w_16) {
    305         start_addr >>= 1;
    306         end_addr >>= 1;
    307     }
    308 
    309     spin_lock_irqsave(&emu->reg_lock, flags);
    310 
    311     /* volume parameters */
    312     if (extra) {
    313         attn = 0;
    314         memset(send_routing, 0, sizeof(send_routing));
    315         send_routing[0] = 0;
    316         send_routing[1] = 1;
    317         send_routing[2] = 2;
    318         send_routing[3] = 3;
    319         memset(send_amount, 0, sizeof(send_amount));
    320     } else {
    321         /* mono, left, right (master voice = left) */
    322         tmp = stereo ? (master ? 1 : 2) : 0;
    323         memcpy(send_routing, &mix->send_routing[tmp][0], 8);
    324         memcpy(send_amount, &mix->send_volume[tmp][0], 8);
    325     }
    326 
    327     ccis = emu10k1_ccis(stereo, w_16);
    328 
    329     if (master) {
    330         evoice->epcm->ccca_start_addr = start_addr + ccis;
    331         if (extra) {
    332             start_addr += ccis;
    333             end_addr += ccis;
    334         }
    335         if (stereo && !extra) {
    336             snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK);
    337             snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK);
    338         } else {
    339             snd_emu10k1_ptr_write(emu, CPF, voice, 0);
    340         }
    341     }
    342 
    343     // setup routing
    344     if (emu->audigy) {
    345         snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
    346                               snd_emu10k1_compose_audigy_fxrt1(send_routing));
    347         snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
    348                               snd_emu10k1_compose_audigy_fxrt2(send_routing));
    349         snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
    350                               ((unsigned int)send_amount[4] << 24) |
    351                               ((unsigned int)send_amount[5] << 16) |
    352                               ((unsigned int)send_amount[6] << 8) |
    353                               (unsigned int)send_amount[7]);
    354     } else
    355         snd_emu10k1_ptr_write(emu, FXRT, voice,
    356                               snd_emu10k1_compose_send_routing(send_routing));
    357     // Stop CA
    358     // Assumption that PT is already 0 so no harm overwriting
    359     snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]);
    360     snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24));
    361     snd_emu10k1_ptr_write(emu, PSST, voice, start_addr | (send_amount[2] << 24));
    362     pitch_target = emu10k1_calc_pitch_target(runtime->rate);
    363     if (extra)
    364         snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr |
    365                               emu10k1_select_interprom(pitch_target) |
    366                               (w_16 ? 0 : CCCA_8BITSELECT));
    367     else
    368         snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) |
    369                               emu10k1_select_interprom(pitch_target) |
    370                               (w_16 ? 0 : CCCA_8BITSELECT));
    371     // Clear filter delay memory
    372     snd_emu10k1_ptr_write(emu, Z1, voice, 0);
    373     snd_emu10k1_ptr_write(emu, Z2, voice, 0);
    374     // invalidate maps
    375     silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK;
    376     snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
    377     snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
    378     // modulation envelope
    379     snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
    380     snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
    381     snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0);
    382     snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f);
    383     snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000);
    384     snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000);
    385     snd_emu10k1_ptr_write(emu, FMMOD, voice, 0);
    386     snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0);
    387     snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0);
    388     snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000);
    389     // volume envelope
    390     snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f);
    391     snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000);
    392     // filter envelope
    393     snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f);
    394     // pitch envelope
    395     snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0);
    396 
    397     spin_unlock_irqrestore(&emu->reg_lock, flags);
    398 }
    399 
    400 static int snd_emu10k1_playback_hw_params(snd_pcm_substream_t * substream,
    401                                           snd_pcm_hw_params_t * hw_params)
    402 {
    403     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    404     snd_pcm_runtime_t *runtime = substream->runtime;
    405     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    406     int err;
    407 
    408     if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0)
    409         return err;
    410     if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
    411         return err;
    412     if (err > 0) {      /* change */
    413         snd_util_memblk_t *memblk;
    414         if (epcm->memblk != NULL)
    415             snd_emu10k1_free_pages(emu, epcm->memblk);
    416         memblk = snd_emu10k1_alloc_pages(emu, substream);
    417         if ((epcm->memblk = memblk) == NULL || ((struct snd_emu10k1_memblk *)memblk)->mapped_page < 0) {
    418             epcm->start_addr = 0;
    419             return -ENOMEM;
    420         }
    421         epcm->start_addr = ((struct snd_emu10k1_memblk *)memblk)->mapped_page << PAGE_SHIFT;
    422     }
    423     return 0;
    424 }
    425 
    426 static int snd_emu10k1_playback_hw_free(snd_pcm_substream_t * substream)
    427 {
    428     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    429     snd_pcm_runtime_t *runtime = substream->runtime;
    430     struct snd_emu10k1_pcm *epcm;
    431 
    432     if (runtime->private_data == NULL)
    433         return 0;
    434     epcm = runtime->private_data;
    435     if (epcm->extra) {
    436         snd_emu10k1_voice_free(epcm->emu, epcm->extra);
    437         epcm->extra = NULL;
    438     }
    439     if (epcm->voices[1]) {
    440         snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
    441         epcm->voices[1] = NULL;
    442     }
    443     if (epcm->voices[0]) {
    444         snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]);
    445         epcm->voices[0] = NULL;
    446     }
    447     if (epcm->memblk) {
    448         snd_emu10k1_free_pages(emu, epcm->memblk);
    449         epcm->memblk = NULL;
    450         epcm->start_addr = 0;
    451     }
    452     snd_pcm_lib_free_pages(substream);
    453     return 0;
    454 }
    455 
    456 static int snd_emu10k1_efx_playback_hw_free(snd_pcm_substream_t * substream)
    457 {
    458     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    459     snd_pcm_runtime_t *runtime = substream->runtime;
    460     struct snd_emu10k1_pcm *epcm;
    461     int i;
    462 
    463     if (runtime->private_data == NULL)
    464         return 0;
    465     epcm = runtime->private_data;
    466     if (epcm->extra) {
    467         snd_emu10k1_voice_free(epcm->emu, epcm->extra);
    468         epcm->extra = NULL;
    469     }
    470     for (i=0; i < NUM_EFX_PLAYBACK; i++) {
    471         if (epcm->voices[i]) {
    472             snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
    473             epcm->voices[i] = NULL;
    474         }
    475     }
    476     if (epcm->memblk) {
    477         snd_emu10k1_free_pages(emu, epcm->memblk);
    478         epcm->memblk = NULL;
    479         epcm->start_addr = 0;
    480     }
    481     snd_pcm_lib_free_pages(substream);
    482     return 0;
    483 }
    484 
    485 static int snd_emu10k1_playback_prepare(snd_pcm_substream_t * substream)
    486 {
    487     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    488     snd_pcm_runtime_t *runtime = substream->runtime;
    489     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    490     unsigned int start_addr, end_addr;
    491 
    492     start_addr = epcm->start_addr;
    493     end_addr = snd_pcm_lib_period_bytes(substream);
    494     if (runtime->channels == 2) {
    495         start_addr >>= 1;
    496         end_addr >>= 1;
    497     }
    498     end_addr += start_addr;
    499     snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
    500                                start_addr, end_addr, NULL);
    501     start_addr = epcm->start_addr;
    502     end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
    503     snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
    504                                start_addr, end_addr,
    505                                &emu->pcm_mixer[substream->number]);
    506     if (epcm->voices[1])
    507         snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1],
    508                                    start_addr, end_addr,
    509                                    &emu->pcm_mixer[substream->number]);
    510     return 0;
    511 }
    512 
    513 static int snd_emu10k1_efx_playback_prepare(snd_pcm_substream_t * substream)
    514 {
    515     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    516     snd_pcm_runtime_t *runtime = substream->runtime;
    517     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    518     unsigned int start_addr, end_addr;
    519     unsigned int channel_size;
    520     int i;
    521 
    522     start_addr = epcm->start_addr;
    523     end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
    524 
    525     /*
    526      * the kX driver leaves some space between voices
    527      */
    528     channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK;
    529 
    530     snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
    531                                start_addr, start_addr + (channel_size / 2), NULL);
    532 
    533     /* only difference with the master voice is we use it for the pointer */
    534     snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
    535                                start_addr, start_addr + channel_size,
    536                                &emu->efx_pcm_mixer[0]);
    537 
    538     start_addr += channel_size;
    539     for (i = 1; i < NUM_EFX_PLAYBACK; i++) {
    540         snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i],
    541                                    start_addr, start_addr + channel_size,
    542                                    &emu->efx_pcm_mixer[i]);
    543         start_addr += channel_size;
    544     }
    545 
    546     return 0;
    547 }
    548 
    549 static snd_pcm_hardware_t snd_emu10k1_efx_playback =
    550 {
    551 /*.info =           */      (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED |
    552                              SNDRV_PCM_INFO_BLOCK_TRANSFER |
    553                              SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
    554 /*.formats =            */  SNDRV_PCM_FMTBIT_S16_LE,
    555 /*.rates =              */  SNDRV_PCM_RATE_48000,
    556 /*.rate_min =           */  48000,
    557 /*.rate_max =           */  48000,
    558 /*.channels_min =       */  NUM_EFX_PLAYBACK,
    559 /*.channels_max =       */  NUM_EFX_PLAYBACK,
    560 /*.buffer_bytes_max =   */  (64*1024),
    561 /*.period_bytes_min =   */  64,
    562 /*.period_bytes_max =   */  (64*1024),
    563 /*.periods_min =        */  2,
    564 /*.periods_max =        */  2,
    565 /*.fifo_size =          */  0
     279                                       int master, int extra,
     280                                       struct snd_emu10k1_voice *evoice,
     281                                       unsigned int start_addr,
     282                                       unsigned int end_addr,
     283                                       struct snd_emu10k1_pcm_mixer *mix)
     284{
     285        struct snd_pcm_substream *substream = evoice->epcm->substream;
     286        struct snd_pcm_runtime *runtime = substream->runtime;
     287        unsigned int silent_page, tmp;
     288        int voice, stereo, w_16;
     289        unsigned char attn, send_amount[8];
     290        unsigned char send_routing[8];
     291        unsigned long flags;
     292        unsigned int pitch_target;
     293        unsigned int ccis;
     294
     295        voice = evoice->number;
     296        stereo = runtime->channels == 2;
     297        w_16 = snd_pcm_format_width(runtime->format) == 16;
     298
     299        if (!extra && stereo) {
     300                start_addr >>= 1;
     301                end_addr >>= 1;
     302        }
     303        if (w_16) {
     304                start_addr >>= 1;
     305                end_addr >>= 1;
     306        }
     307
     308        spin_lock_irqsave(&emu->reg_lock, flags);
     309
     310        /* volume parameters */
     311        if (extra) {
     312                attn = 0;
     313                memset(send_routing, 0, sizeof(send_routing));
     314                send_routing[0] = 0;
     315                send_routing[1] = 1;
     316                send_routing[2] = 2;
     317                send_routing[3] = 3;
     318                memset(send_amount, 0, sizeof(send_amount));
     319        } else {
     320                /* mono, left, right (master voice = left) */
     321                tmp = stereo ? (master ? 1 : 2) : 0;
     322                memcpy(send_routing, &mix->send_routing[tmp][0], 8);
     323                memcpy(send_amount, &mix->send_volume[tmp][0], 8);
     324        }
     325
     326        ccis = emu10k1_ccis(stereo, w_16);
     327       
     328        if (master) {
     329                evoice->epcm->ccca_start_addr = start_addr + ccis;
     330                if (extra) {
     331                        start_addr += ccis;
     332                        end_addr += ccis;
     333                }
     334                if (stereo && !extra) {
     335                        snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK);
     336                        snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK);
     337                } else {
     338                        snd_emu10k1_ptr_write(emu, CPF, voice, 0);
     339                }
     340        }
     341
     342        /* setup routing */
     343        if (emu->audigy) {
     344                snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
     345                                      snd_emu10k1_compose_audigy_fxrt1(send_routing));
     346                snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
     347                                      snd_emu10k1_compose_audigy_fxrt2(send_routing));
     348                snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
     349                                      ((unsigned int)send_amount[4] << 24) |
     350                                      ((unsigned int)send_amount[5] << 16) |
     351                                      ((unsigned int)send_amount[6] << 8) |
     352                                      (unsigned int)send_amount[7]);
     353        } else
     354                snd_emu10k1_ptr_write(emu, FXRT, voice,
     355                                      snd_emu10k1_compose_send_routing(send_routing));
     356        /* Stop CA */
     357        /* Assumption that PT is already 0 so no harm overwriting */
     358        snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]);
     359        snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24));
     360        snd_emu10k1_ptr_write(emu, PSST, voice, start_addr | (send_amount[2] << 24));
     361        if (emu->card_capabilities->emu1010)
     362                pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
     363        else
     364                pitch_target = emu10k1_calc_pitch_target(runtime->rate);
     365        if (extra)
     366                snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr |
     367                              emu10k1_select_interprom(pitch_target) |
     368                              (w_16 ? 0 : CCCA_8BITSELECT));
     369        else
     370                snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) |
     371                              emu10k1_select_interprom(pitch_target) |
     372                              (w_16 ? 0 : CCCA_8BITSELECT));
     373        /* Clear filter delay memory */
     374        snd_emu10k1_ptr_write(emu, Z1, voice, 0);
     375        snd_emu10k1_ptr_write(emu, Z2, voice, 0);
     376        /* invalidate maps */
     377        silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK;
     378        snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
     379        snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
     380        /* modulation envelope */
     381        snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
     382        snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
     383        snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0);
     384        snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f);
     385        snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000);
     386        snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000);
     387        snd_emu10k1_ptr_write(emu, FMMOD, voice, 0);
     388        snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0);
     389        snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0);
     390        snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000);
     391        /* volume envelope */
     392        snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f);
     393        snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000);
     394        /* filter envelope */
     395        snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f);
     396        /* pitch envelope */
     397        snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0);
     398
     399        spin_unlock_irqrestore(&emu->reg_lock, flags);
     400}
     401
     402static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream,
     403                                          struct snd_pcm_hw_params *hw_params)
     404{
     405        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     406        struct snd_pcm_runtime *runtime = substream->runtime;
     407        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     408        int err;
     409
     410        if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0)
     411                return err;
     412        if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
     413                return err;
     414        if (err > 0) {  /* change */
     415                int mapped;
     416                if (epcm->memblk != NULL)
     417                        snd_emu10k1_free_pages(emu, epcm->memblk);
     418                epcm->memblk = snd_emu10k1_alloc_pages(emu, substream);
     419                epcm->start_addr = 0;
     420                if (! epcm->memblk)
     421                        return -ENOMEM;
     422                mapped = ((struct snd_emu10k1_memblk *)epcm->memblk)->mapped_page;
     423                if (mapped < 0)
     424                        return -ENOMEM;
     425                epcm->start_addr = mapped << PAGE_SHIFT;
     426        }
     427        return 0;
     428}
     429
     430static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream *substream)
     431{
     432        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     433        struct snd_pcm_runtime *runtime = substream->runtime;
     434        struct snd_emu10k1_pcm *epcm;
     435
     436        if (runtime->private_data == NULL)
     437                return 0;
     438        epcm = runtime->private_data;
     439        if (epcm->extra) {
     440                snd_emu10k1_voice_free(epcm->emu, epcm->extra);
     441                epcm->extra = NULL;
     442        }
     443        if (epcm->voices[1]) {
     444                snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
     445                epcm->voices[1] = NULL;
     446        }
     447        if (epcm->voices[0]) {
     448                snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]);
     449                epcm->voices[0] = NULL;
     450        }
     451        if (epcm->memblk) {
     452                snd_emu10k1_free_pages(emu, epcm->memblk);
     453                epcm->memblk = NULL;
     454                epcm->start_addr = 0;
     455        }
     456        snd_pcm_lib_free_pages(substream);
     457        return 0;
     458}
     459
     460static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream *substream)
     461{
     462        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     463        struct snd_pcm_runtime *runtime = substream->runtime;
     464        struct snd_emu10k1_pcm *epcm;
     465        int i;
     466
     467        if (runtime->private_data == NULL)
     468                return 0;
     469        epcm = runtime->private_data;
     470        if (epcm->extra) {
     471                snd_emu10k1_voice_free(epcm->emu, epcm->extra);
     472                epcm->extra = NULL;
     473        }
     474        for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
     475                if (epcm->voices[i]) {
     476                        snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
     477                        epcm->voices[i] = NULL;
     478                }
     479        }
     480        if (epcm->memblk) {
     481                snd_emu10k1_free_pages(emu, epcm->memblk);
     482                epcm->memblk = NULL;
     483                epcm->start_addr = 0;
     484        }
     485        snd_pcm_lib_free_pages(substream);
     486        return 0;
     487}
     488
     489static int snd_emu10k1_playback_prepare(struct snd_pcm_substream *substream)
     490{
     491        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     492        struct snd_pcm_runtime *runtime = substream->runtime;
     493        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     494        unsigned int start_addr, end_addr;
     495
     496        start_addr = epcm->start_addr;
     497        end_addr = snd_pcm_lib_period_bytes(substream);
     498        if (runtime->channels == 2) {
     499                start_addr >>= 1;
     500                end_addr >>= 1;
     501        }
     502        end_addr += start_addr;
     503        snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
     504                                   start_addr, end_addr, NULL);
     505        start_addr = epcm->start_addr;
     506        end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
     507        snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
     508                                   start_addr, end_addr,
     509                                   &emu->pcm_mixer[substream->number]);
     510        if (epcm->voices[1])
     511                snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1],
     512                                           start_addr, end_addr,
     513                                           &emu->pcm_mixer[substream->number]);
     514        return 0;
     515}
     516
     517static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)
     518{
     519        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     520        struct snd_pcm_runtime *runtime = substream->runtime;
     521        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     522        unsigned int start_addr, end_addr;
     523        unsigned int channel_size;
     524        int i;
     525
     526        start_addr = epcm->start_addr;
     527        end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
     528
     529        /*
     530         * the kX driver leaves some space between voices
     531         */
     532        channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK;
     533
     534        snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
     535                                   start_addr, start_addr + (channel_size / 2), NULL);
     536
     537        /* only difference with the master voice is we use it for the pointer */
     538        snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
     539                                   start_addr, start_addr + channel_size,
     540                                   &emu->efx_pcm_mixer[0]);
     541
     542        start_addr += channel_size;
     543        for (i = 1; i < NUM_EFX_PLAYBACK; i++) {
     544                snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i],
     545                                           start_addr, start_addr + channel_size,
     546                                           &emu->efx_pcm_mixer[i]);
     547                start_addr += channel_size;
     548        }
     549
     550        return 0;
     551}
     552
     553static struct snd_pcm_hardware snd_emu10k1_efx_playback =
     554{
     555        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED |
     556                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     557                                 SNDRV_PCM_INFO_RESUME |
     558                                 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
     559        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
     560        .rates =                SNDRV_PCM_RATE_48000,
     561        .rate_min =             48000,
     562        .rate_max =             48000,
     563        .channels_min =         NUM_EFX_PLAYBACK,
     564        .channels_max =         NUM_EFX_PLAYBACK,
     565        .buffer_bytes_max =     (64*1024),
     566        .period_bytes_min =     64,
     567        .period_bytes_max =     (64*1024),
     568        .periods_min =          2,
     569        .periods_max =          2,
     570        .fifo_size =            0,
    566571};
    567572
    568 static int snd_emu10k1_capture_hw_params(snd_pcm_substream_t * substream,
    569                                          snd_pcm_hw_params_t * hw_params)
    570 {
    571     return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    572 }
    573 
    574 static int snd_emu10k1_capture_hw_free(snd_pcm_substream_t * substream)
    575 {
    576     return snd_pcm_lib_free_pages(substream);
    577 }
    578 
    579 static int snd_emu10k1_capture_prepare(snd_pcm_substream_t * substream)
    580 {
    581     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    582     snd_pcm_runtime_t *runtime = substream->runtime;
    583     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    584     int idx;
    585 
    586     /* zeroing the buffer size will stop capture */
    587     snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
    588     switch (epcm->type) {
    589     case CAPTURE_AC97ADC:
    590         snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
    591         break;
    592     case CAPTURE_EFX:
    593         if (emu->audigy) {
    594             snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
    595             snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
    596         } else
    597             snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
    598         break;
    599     default:
    600         break;
    601     }
    602     snd_emu10k1_ptr_write(emu, epcm->capture_ba_reg, 0, runtime->dma_addr);
    603     epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream);
    604     epcm->capture_bs_val = 0;
    605     for (idx = 0; idx < 31; idx++) {
    606         if (capture_period_sizes[idx] == epcm->capture_bufsize) {
    607             epcm->capture_bs_val = idx + 1;
    608             break;
    609         }
    610     }
    611     if (epcm->capture_bs_val == 0) {
    612         snd_BUG();
    613         epcm->capture_bs_val++;
    614     }
    615     if (epcm->type == CAPTURE_AC97ADC) {
    616         epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
    617         if (runtime->channels > 1)
    618             epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
    619         epcm->capture_cr_val |= emu->audigy ?
    620             snd_emu10k1_audigy_capture_rate_reg(runtime->rate) :
    621             snd_emu10k1_capture_rate_reg(runtime->rate);
    622     }
    623     return 0;
     573static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream *substream,
     574                                         struct snd_pcm_hw_params *hw_params)
     575{
     576        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
     577}
     578
     579static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream *substream)
     580{
     581        return snd_pcm_lib_free_pages(substream);
     582}
     583
     584static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
     585{
     586        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     587        struct snd_pcm_runtime *runtime = substream->runtime;
     588        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     589        int idx;
     590
     591        /* zeroing the buffer size will stop capture */
     592        snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
     593        switch (epcm->type) {
     594        case CAPTURE_AC97ADC:
     595                snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
     596                break;
     597        case CAPTURE_EFX:
     598                if (emu->audigy) {
     599                        snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
     600                        snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
     601                } else
     602                        snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
     603                break;
     604        default:
     605                break;
     606        }       
     607        snd_emu10k1_ptr_write(emu, epcm->capture_ba_reg, 0, runtime->dma_addr);
     608        epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream);
     609        epcm->capture_bs_val = 0;
     610        for (idx = 0; idx < 31; idx++) {
     611                if (capture_period_sizes[idx] == epcm->capture_bufsize) {
     612                        epcm->capture_bs_val = idx + 1;
     613                        break;
     614                }
     615        }
     616        if (epcm->capture_bs_val == 0) {
     617                snd_BUG();
     618                epcm->capture_bs_val++;
     619        }
     620        if (epcm->type == CAPTURE_AC97ADC) {
     621                epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
     622                if (runtime->channels > 1)
     623                        epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
     624                epcm->capture_cr_val |= emu->audigy ?
     625                        snd_emu10k1_audigy_capture_rate_reg(runtime->rate) :
     626                        snd_emu10k1_capture_rate_reg(runtime->rate);
     627        }
     628        return 0;
    624629}
    625630
    626631static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, int extra, struct snd_emu10k1_voice *evoice)
    627632{
    628     snd_pcm_runtime_t *runtime;
    629     unsigned int voice, stereo, i, ccis, cra = 64, cs, sample;
    630 
    631     if (evoice == NULL)
    632         return;
    633     runtime = evoice->epcm->substream->runtime;
    634     voice = evoice->number;
    635     stereo = (!extra && runtime->channels == 2);
    636     sample = snd_pcm_format_width(runtime->format) == 16 ? 0 : 0x80808080;
    637     ccis = emu10k1_ccis(stereo, sample == 0);
    638     // set cs to 2 * number of cache registers beside the invalidated
    639     cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1;
    640     if (cs > 16) cs = 16;
    641     for (i = 0; i < cs; i++) {
    642         snd_emu10k1_ptr_write(emu, CD0 + i, voice, sample);
    643         if (stereo) {
    644             snd_emu10k1_ptr_write(emu, CD0 + i, voice + 1, sample);
    645         }
    646     }
    647     // reset cache
    648     snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, 0);
    649     snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice, cra);
    650     if (stereo) {
    651         snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice + 1, 0);
    652         snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice + 1, cra);
    653     }
    654     // fill cache
    655     snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, ccis);
    656     if (stereo) {
    657         snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice+1, ccis);
    658     }
     633        struct snd_pcm_runtime *runtime;
     634        unsigned int voice, stereo, i, ccis, cra = 64, cs, sample;
     635
     636        if (evoice == NULL)
     637                return;
     638        runtime = evoice->epcm->substream->runtime;
     639        voice = evoice->number;
     640        stereo = (!extra && runtime->channels == 2);
     641        sample = snd_pcm_format_width(runtime->format) == 16 ? 0 : 0x80808080;
     642        ccis = emu10k1_ccis(stereo, sample == 0);
     643        /* set cs to 2 * number of cache registers beside the invalidated */
     644        cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1;
     645        if (cs > 16) cs = 16;
     646        for (i = 0; i < cs; i++) {
     647                snd_emu10k1_ptr_write(emu, CD0 + i, voice, sample);
     648                if (stereo) {
     649                        snd_emu10k1_ptr_write(emu, CD0 + i, voice + 1, sample);
     650                }
     651        }
     652        /* reset cache */
     653        snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, 0);
     654        snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice, cra);
     655        if (stereo) {
     656                snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice + 1, 0);
     657                snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice + 1, cra);
     658        }
     659        /* fill cache */
     660        snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, ccis);
     661        if (stereo) {
     662                snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice+1, ccis);
     663        }
    659664}
    660665
    661666static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice,
    662                                                int master, int extra,
    663                                                struct snd_emu10k1_pcm_mixer *mix)
    664 {
    665     snd_pcm_substream_t *substream;
    666     snd_pcm_runtime_t *runtime;
    667     unsigned int attn, vattn;
    668     unsigned int voice, tmp;
    669 
    670     if (evoice == NULL) /* skip second voice for mono */
    671         return;
    672     substream = evoice->epcm->substream;
    673     runtime = substream->runtime;
    674     voice = evoice->number;
    675     attn = extra ? 0 : 0x00ff;
    676     tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0;
    677     vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0;
    678     snd_emu10k1_ptr_write(emu, IFATN, voice, attn);
    679     snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff);
    680     snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff);
    681     snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f);
    682     snd_emu10k1_voice_clear_loop_stop(emu, voice);
    683 }
     667                                               int master, int extra,
     668                                               struct snd_emu10k1_pcm_mixer *mix)
     669{
     670        struct snd_pcm_substream *substream;
     671        struct snd_pcm_runtime *runtime;
     672        unsigned int attn, vattn;
     673        unsigned int voice, tmp;
     674
     675        if (evoice == NULL)     /* skip second voice for mono */
     676                return;
     677        substream = evoice->epcm->substream;
     678        runtime = substream->runtime;
     679        voice = evoice->number;
     680
     681        attn = extra ? 0 : 0x00ff;
     682        tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0;
     683        vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0;
     684        snd_emu10k1_ptr_write(emu, IFATN, voice, attn);
     685        snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff);
     686        snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff);
     687        snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f);
     688        snd_emu10k1_voice_clear_loop_stop(emu, voice);
     689}       
    684690
    685691static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice, int master, int extra)
    686692{
    687     snd_pcm_substream_t *substream;
    688     snd_pcm_runtime_t *runtime;
    689     unsigned int voice, pitch, pitch_target;
    690 
    691     if (evoice == NULL)     /* skip second voice for mono */
    692         return;
    693     substream = evoice->epcm->substream;
    694     runtime = substream->runtime;
    695     voice = evoice->number;
    696 
    697     pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8;
    698     pitch_target = emu10k1_calc_pitch_target(runtime->rate);
    699     snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target);
    700     if (master || evoice->epcm->type == PLAYBACK_EFX)
    701         snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target);
    702     snd_emu10k1_ptr_write(emu, IP, voice, pitch);
    703     if (extra)
    704         snd_emu10k1_voice_intr_enable(emu, voice);
     693        struct snd_pcm_substream *substream;
     694        struct snd_pcm_runtime *runtime;
     695        unsigned int voice, pitch, pitch_target;
     696
     697        if (evoice == NULL)     /* skip second voice for mono */
     698                return;
     699        substream = evoice->epcm->substream;
     700        runtime = substream->runtime;
     701        voice = evoice->number;
     702
     703        pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8;
     704        if (emu->card_capabilities->emu1010)
     705                pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
     706        else
     707                pitch_target = emu10k1_calc_pitch_target(runtime->rate);
     708        snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target);
     709        if (master || evoice->epcm->type == PLAYBACK_EFX)
     710                snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target);
     711        snd_emu10k1_ptr_write(emu, IP, voice, pitch);
     712        if (extra)
     713                snd_emu10k1_voice_intr_enable(emu, voice);
    705714}
    706715
    707716static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice)
    708717{
    709     unsigned int voice;
    710 
    711     if (evoice == NULL)
    712         return;
    713     voice = evoice->number;
    714     snd_emu10k1_voice_intr_disable(emu, voice);
    715     snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0);
    716     snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0);
    717     snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff);
    718     snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
    719     snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
    720     snd_emu10k1_ptr_write(emu, IP, voice, 0);
    721 }
    722 
    723 static int snd_emu10k1_playback_trigger(snd_pcm_substream_t * substream,
    724                                         int cmd)
    725 {
    726     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    727     snd_pcm_runtime_t *runtime = substream->runtime;
    728     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    729     struct snd_emu10k1_pcm_mixer *mix;
    730     int result = 0;
    731 
    732     spin_lock(&emu->reg_lock);
    733     switch (cmd) {
    734     case SNDRV_PCM_TRIGGER_START:
    735         // hmm this should cause full and half full interrupt to be raised?
    736         snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);     /* do we need this? */
    737         snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
    738         /* follow thru */
    739     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    740         mix = &emu->pcm_mixer[substream->number];
    741         snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix);
    742         snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix);
    743         snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
    744         snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0);
    745         snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0);
    746         snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
    747         epcm->running = 1;
    748         break;
    749     case SNDRV_PCM_TRIGGER_STOP:
    750     case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    751         epcm->running = 0;
    752         snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
    753         snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]);
    754         snd_emu10k1_playback_stop_voice(emu, epcm->extra);
    755         break;
    756     default:
    757         result = -EINVAL;
    758         break;
    759     }
    760     spin_unlock(&emu->reg_lock);
    761     return result;
    762 }
    763 
    764 static int snd_emu10k1_capture_trigger(snd_pcm_substream_t * substream,
    765                                        int cmd)
    766 {
    767     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    768     snd_pcm_runtime_t *runtime = substream->runtime;
    769     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    770     int result = 0;
    771 
    772     // printk("trigger - emu10k1 = %p, cmd = %i, pointer = %i\n", emu, cmd, substream->ops->pointer(substream));
    773     spin_lock(&emu->reg_lock);
    774     switch (cmd) {
    775     case SNDRV_PCM_TRIGGER_START:
    776         outl(epcm->capture_ipr, emu->port + IPR);
    777         snd_emu10k1_intr_enable(emu, epcm->capture_inte);
    778         // printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs);
    779         switch (epcm->type) {
    780         case CAPTURE_AC97ADC:
    781             snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val);
    782             break;
    783         case CAPTURE_EFX:
    784             if (emu->audigy) {
    785                 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
    786                 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
    787             } else
    788                 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
    789             break;
    790         default:
    791             break;
    792         }
    793         snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val);
    794         epcm->running = 1;
    795         epcm->first_ptr = 1;
    796         break;
    797     case SNDRV_PCM_TRIGGER_STOP:
    798         epcm->running = 0;
    799         snd_emu10k1_intr_disable(emu, epcm->capture_inte);
    800         outl(epcm->capture_ipr, emu->port + IPR);
    801         snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
    802         switch (epcm->type) {
    803         case CAPTURE_AC97ADC:
    804             snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
    805             break;
    806         case CAPTURE_EFX:
    807             if (emu->audigy) {
    808                 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
    809                 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
    810             } else
    811                 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
    812             break;
    813         default:
    814             break;
    815         }
    816         break;
    817     default:
    818         result = -EINVAL;
    819     }
    820     spin_unlock(&emu->reg_lock);
    821     return result;
    822 }
    823 
    824 static snd_pcm_uframes_t snd_emu10k1_playback_pointer(snd_pcm_substream_t * substream)
    825 {
    826     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    827     snd_pcm_runtime_t *runtime = substream->runtime;
    828     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    829     unsigned int ptr;
    830 
    831     if (!epcm->running)
    832         return 0;
    833     ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
     718        unsigned int voice;
     719
     720        if (evoice == NULL)
     721                return;
     722        voice = evoice->number;
     723        snd_emu10k1_voice_intr_disable(emu, voice);
     724        snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0);
     725        snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0);
     726        snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff);
     727        snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
     728        snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
     729        snd_emu10k1_ptr_write(emu, IP, voice, 0);
     730}
     731
     732static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
     733                                        int cmd)
     734{
     735        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     736        struct snd_pcm_runtime *runtime = substream->runtime;
     737        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     738        struct snd_emu10k1_pcm_mixer *mix;
     739        int result = 0;
     740
     741        /* printk("trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n", (int)emu, cmd, substream->ops->pointer(substream)); */
     742        spin_lock(&emu->reg_lock);
     743        switch (cmd) {
     744        case SNDRV_PCM_TRIGGER_START:
     745                snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);     /* do we need this? */
     746                snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
     747                /* follow thru */
     748        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     749        case SNDRV_PCM_TRIGGER_RESUME:
     750                mix = &emu->pcm_mixer[substream->number];
     751                snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix);
     752                snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix);
     753                snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
     754                snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0);
     755                snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0);
     756                snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
     757                epcm->running = 1;
     758                break;
     759        case SNDRV_PCM_TRIGGER_STOP:
     760        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     761        case SNDRV_PCM_TRIGGER_SUSPEND:
     762                epcm->running = 0;
     763                snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
     764                snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]);
     765                snd_emu10k1_playback_stop_voice(emu, epcm->extra);
     766                break;
     767        default:
     768                result = -EINVAL;
     769                break;
     770        }
     771        spin_unlock(&emu->reg_lock);
     772        return result;
     773}
     774
     775static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
     776                                       int cmd)
     777{
     778        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     779        struct snd_pcm_runtime *runtime = substream->runtime;
     780        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     781        int result = 0;
     782
     783        spin_lock(&emu->reg_lock);
     784        switch (cmd) {
     785        case SNDRV_PCM_TRIGGER_START:
     786        case SNDRV_PCM_TRIGGER_RESUME:
     787                /* hmm this should cause full and half full interrupt to be raised? */
     788                outl(epcm->capture_ipr, emu->port + IPR);
     789                snd_emu10k1_intr_enable(emu, epcm->capture_inte);
     790                /* printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs); */
     791                switch (epcm->type) {
     792                case CAPTURE_AC97ADC:
     793                        snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val);
     794                        break;
     795                case CAPTURE_EFX:
     796                        if (emu->audigy) {
     797                                snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
     798                                snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
     799                                snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm->capture_cr_val, epcm->capture_cr_val2);
     800                        } else
     801                                snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
     802                        break;
     803                default:       
     804                        break;
     805                }
     806                snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val);
     807                epcm->running = 1;
     808                epcm->first_ptr = 1;
     809                break;
     810        case SNDRV_PCM_TRIGGER_STOP:
     811        case SNDRV_PCM_TRIGGER_SUSPEND:
     812                epcm->running = 0;
     813                snd_emu10k1_intr_disable(emu, epcm->capture_inte);
     814                outl(epcm->capture_ipr, emu->port + IPR);
     815                snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
     816                switch (epcm->type) {
     817                case CAPTURE_AC97ADC:
     818                        snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
     819                        break;
     820                case CAPTURE_EFX:
     821                        if (emu->audigy) {
     822                                snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
     823                                snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
     824                        } else
     825                                snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
     826                        break;
     827                default:
     828                        break;
     829                }
     830                break;
     831        default:
     832                result = -EINVAL;
     833        }
     834        spin_unlock(&emu->reg_lock);
     835        return result;
     836}
     837
     838static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *substream)
     839{
     840        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     841        struct snd_pcm_runtime *runtime = substream->runtime;
     842        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     843        unsigned int ptr;
     844
     845        if (!epcm->running)
     846                return 0;
     847        ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
    834848#if 0   /* Perex's code */
    835     ptr += runtime->buffer_size;
    836     ptr -= epcm->ccca_start_addr;
    837     ptr %= runtime->buffer_size;
     849        ptr += runtime->buffer_size;
     850        ptr -= epcm->ccca_start_addr;
     851        ptr %= runtime->buffer_size;
    838852#else   /* EMU10K1 Open Source code from Creative */
    839     if (ptr < epcm->ccca_start_addr)
    840         ptr += runtime->buffer_size - epcm->ccca_start_addr;
    841     else {
    842         ptr -= epcm->ccca_start_addr;
    843         if (ptr >= runtime->buffer_size)
    844             ptr -= runtime->buffer_size;
    845     }
     853        if (ptr < epcm->ccca_start_addr)
     854                ptr += runtime->buffer_size - epcm->ccca_start_addr;
     855        else {
     856                ptr -= epcm->ccca_start_addr;
     857                if (ptr >= runtime->buffer_size)
     858                        ptr -= runtime->buffer_size;
     859        }
    846860#endif
    847     // printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size);
    848     return ptr;
    849 }
    850 
    851 static int snd_emu10k1_efx_playback_trigger(snd_pcm_substream_t * substream,
    852                                             int cmd)
    853 {
    854     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    855     snd_pcm_runtime_t *runtime = substream->runtime;
    856     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    857     int i;
    858     int result = 0;
    859 
    860     spin_lock(&emu->reg_lock);
    861     switch (cmd) {
    862     case SNDRV_PCM_TRIGGER_START:
    863         // prepare voices
    864         for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
    865             snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]);
    866         }
    867         snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
    868 
    869         /* follow thru */
    870     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    871         snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
    872         snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0,
    873                                            &emu->efx_pcm_mixer[0]);
    874         for (i = 1; i < NUM_EFX_PLAYBACK; i++)
    875             snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0,
    876                                                &emu->efx_pcm_mixer[i]);
    877         snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0);
    878         snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
    879         for (i = 1; i < NUM_EFX_PLAYBACK; i++)
    880             snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0);
    881         epcm->running = 1;
    882         break;
    883     case SNDRV_PCM_TRIGGER_STOP:
    884     case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    885         epcm->running = 0;
    886         for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
    887             snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]);
    888         }
    889         snd_emu10k1_playback_stop_voice(emu, epcm->extra);
    890         break;
    891     default:
    892         result = -EINVAL;
    893         break;
    894     }
    895     spin_unlock(&emu->reg_lock);
    896     return result;
    897 }
    898 
    899 static snd_pcm_uframes_t snd_emu10k1_capture_pointer(snd_pcm_substream_t * substream)
    900 {
    901     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    902     snd_pcm_runtime_t *runtime = substream->runtime;
    903     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    904     unsigned int ptr;
    905 
    906     if (!epcm->running)
    907         return 0;
    908     if (epcm->first_ptr) {
    909         udelay(50);     // hack, it takes awhile until capture is started
    910         epcm->first_ptr = 0;
    911     }
    912     ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff;
    913     return bytes_to_frames(runtime, ptr);
     861        /* printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size); */
     862        return ptr;
     863}
     864
     865
     866static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,
     867                                        int cmd)
     868{
     869        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     870        struct snd_pcm_runtime *runtime = substream->runtime;
     871        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     872        int i;
     873        int result = 0;
     874
     875        spin_lock(&emu->reg_lock);
     876        switch (cmd) {
     877        case SNDRV_PCM_TRIGGER_START:
     878                /* prepare voices */
     879                for (i = 0; i < NUM_EFX_PLAYBACK; i++) {       
     880                        snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]);
     881                }
     882                snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
     883
     884                /* follow thru */
     885        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     886        case SNDRV_PCM_TRIGGER_RESUME:
     887                snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
     888                snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0,
     889                                                   &emu->efx_pcm_mixer[0]);
     890                for (i = 1; i < NUM_EFX_PLAYBACK; i++)
     891                        snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0,
     892                                                           &emu->efx_pcm_mixer[i]);
     893                snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0);
     894                snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
     895                for (i = 1; i < NUM_EFX_PLAYBACK; i++)
     896                        snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0);
     897                epcm->running = 1;
     898                break;
     899        case SNDRV_PCM_TRIGGER_SUSPEND:
     900        case SNDRV_PCM_TRIGGER_STOP:
     901        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     902                epcm->running = 0;
     903                for (i = 0; i < NUM_EFX_PLAYBACK; i++) {       
     904                        snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]);
     905                }
     906                snd_emu10k1_playback_stop_voice(emu, epcm->extra);
     907                break;
     908        default:
     909                result = -EINVAL;
     910                break;
     911        }
     912        spin_unlock(&emu->reg_lock);
     913        return result;
     914}
     915
     916
     917static snd_pcm_uframes_t snd_emu10k1_capture_pointer(struct snd_pcm_substream *substream)
     918{
     919        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     920        struct snd_pcm_runtime *runtime = substream->runtime;
     921        struct snd_emu10k1_pcm *epcm = runtime->private_data;
     922        unsigned int ptr;
     923
     924        if (!epcm->running)
     925                return 0;
     926        if (epcm->first_ptr) {
     927                udelay(50);     /* hack, it takes awhile until capture is started */
     928                epcm->first_ptr = 0;
     929        }
     930        ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff;
     931        return bytes_to_frames(runtime, ptr);
    914932}
    915933
     
    918936 */
    919937
    920 #if 0
    921 int snd_emu10k1_playback_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg)
    922 {
    923     switch(cmd) {
    924     case SNDRV_PCM_IOCTL1_SETVOLUME:
    925         {
    926             struct snd_emu10k1_pcm_mixer *mix;
    927             snd_pcm_volume_t    *volume = (snd_pcm_volume_t *)arg;
    928             struct snd_emu10k1           *emu    = snd_pcm_substream_chip(substream);
    929             snd_ctl_elem_value_t *ucontrol;
    930             snd_ctl_elem_info_t  *uinfo;
    931             void                 *iwishihadmorestack;
    932             int                  range;
    933 
    934 
    935             iwishihadmorestack = kmalloc(sizeof(snd_ctl_elem_value_t) + sizeof(snd_ctl_elem_info_t), GFP_KERNEL);
    936             if(iwishihadmorestack == NULL) {
    937                 kfree(iwishihadmorestack);
    938                 return -ENOMEM;
    939             }
    940             ucontrol = (snd_ctl_elem_value_t *)iwishihadmorestack;
    941             uinfo    = (snd_ctl_elem_info_t *)(ucontrol + 1);
    942 
    943             mix = &emu->pcm_mixer[substream->number];
    944             mix->ctl_attn->info(mix->ctl_attn, uinfo);
    945             range = uinfo->value.integer.max - uinfo->value.integer.min;
    946 
    947             if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
    948                 ucontrol->value.integer.value[1] = (volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] * range)/SNDRV_PCM_VOL_MAX;
    949                 ucontrol->value.integer.value[2] = (volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] * range)/SNDRV_PCM_VOL_MAX;
    950             }
    951             else
    952                 if (mix->epcm->voices[0])
    953                     ucontrol->value.integer.value[0] = (volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] * range)/SNDRV_PCM_VOL_MAX;
    954 
    955             mix->ctl_attn->put(mix->ctl_attn, ucontrol);
    956             kfree(iwishihadmorestack);
    957             return 0;
    958         }
    959     case SNDRV_PCM_IOCTL1_GETVOLUME:
    960         {
    961             struct snd_emu10k1_pcm_mixer *mix;
    962             snd_pcm_volume_t    *volume = (snd_pcm_volume_t *)arg;
    963             struct snd_emu10k1           *emu    = snd_pcm_substream_chip(substream);
    964             int                  range;
    965             snd_ctl_elem_value_t *ucontrol;
    966             snd_ctl_elem_info_t  *uinfo;
    967             void                 *iwishihadmorestack;
    968 
    969             iwishihadmorestack = kmalloc(sizeof(snd_ctl_elem_value_t) + sizeof(snd_ctl_elem_info_t), GFP_KERNEL);
    970             if(iwishihadmorestack == NULL) {
    971                 return -ENOMEM;
    972             }
    973             ucontrol = (snd_ctl_elem_value_t *)iwishihadmorestack;
    974             uinfo    = (snd_ctl_elem_info_t *)(ucontrol + 1);
    975 
    976             mix = &emu->pcm_mixer[substream->number];
    977             mix->ctl_attn->info(mix->ctl_attn, uinfo);
    978             range = uinfo->value.integer.max - uinfo->value.integer.min;
    979             if(range == 0) {
    980                 kfree(iwishihadmorestack);
    981                 return -EPERM;
    982             }
    983             mix->ctl_attn->get(mix->ctl_attn, ucontrol);
    984 
    985             if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
    986                 volume->nrchannels = 2;
    987                 volume->volume[SNDRV_PCM_VOL_FRONT_LEFT]  = (ucontrol->value.integer.value[1] * SNDRV_PCM_VOL_MAX) / range;
    988                 volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] = (ucontrol->value.integer.value[2] * SNDRV_PCM_VOL_MAX) / range;
    989                 volume->volume[SNDRV_PCM_VOL_REAR_LEFT]   = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT];
    990                 volume->volume[SNDRV_PCM_VOL_REAR_RIGHT]  = volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT];
    991             }
    992             else
    993                 if (mix->epcm->voices[0]){
    994                     volume->nrchannels = 1;
    995                     volume->volume[SNDRV_PCM_VOL_FRONT_LEFT]  = (ucontrol->value.integer.value[0] * SNDRV_PCM_VOL_MAX) / range;
    996                     volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT];
    997                     volume->volume[SNDRV_PCM_VOL_REAR_LEFT]   = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT];
    998                     volume->volume[SNDRV_PCM_VOL_REAR_RIGHT]  = volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT];
    999                 }
    1000             kfree(iwishihadmorestack);
    1001             return 0;
    1002         }
    1003 
    1004     }
    1005     return snd_pcm_lib_ioctl(substream, cmd, arg);
    1006 }
    1007 #endif
    1008 
    1009 static snd_pcm_hardware_t snd_emu10k1_playback =
    1010 {
    1011     /*  info:            */     (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    1012                                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
    1013                                  SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
    1014                                  /*     formats:         */     SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    1015                                  SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000,
    1016                                  /*     rate_min:        */     4000,
    1017                                  /*     rate_max:        */     96000,
    1018                                  /*     channels_min:    */     1,
    1019                                  /*     channels_max:    */     2,
    1020                                  /*     buffer_bytes_max: */    (128*1024),
    1021                                  /*     period_bytes_min: */    64,
    1022                                  /*     period_bytes_max: */    (128*1024),
    1023                                  /*     periods_min:     */     1,
    1024                                  /*     periods_max:     */     1024,
    1025                                  /*     fifo_size:       */     0,
     938static struct snd_pcm_hardware snd_emu10k1_playback =
     939{
     940        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     941                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     942                                 SNDRV_PCM_INFO_RESUME |
     943                                 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
     944        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     945        .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000,
     946        .rate_min =             4000,
     947        .rate_max =             96000,
     948        .channels_min =         1,
     949        .channels_max =         2,
     950        .buffer_bytes_max =     (128*1024),
     951        .period_bytes_min =     64,
     952        .period_bytes_max =     (128*1024),
     953        .periods_min =          1,
     954        .periods_max =          1024,
     955        .fifo_size =            0,
    1026956};
    1027957
     
    1030960 */
    1031961
    1032 static snd_pcm_hardware_t snd_emu10k1_capture =
    1033 {
    1034     /*  info:            */     (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    1035                                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
    1036                                  SNDRV_PCM_INFO_MMAP_VALID),
    1037                                  /*     formats:         */     SNDRV_PCM_FMTBIT_S16_LE,
    1038                                  /*     rates:           */     SNDRV_PCM_RATE_8000_48000,
    1039                                  /*     rate_min:        */     8000,
    1040                                  /*     rate_max:        */     48000,
    1041                                  /*     channels_min:    */     1,
    1042                                  /*     channels_max:    */     2,
    1043                                  /*     buffer_bytes_max: */    (64*1024),
    1044                                  /*     period_bytes_min: */    384,
    1045                                  /*     period_bytes_max: */    (64*1024),
    1046                                  /*     periods_min:     */     2,
    1047                                  /*     periods_max:     */     2,
    1048                                  /*     fifo_size:        */    0,
     962static struct snd_pcm_hardware snd_emu10k1_capture =
     963{
     964        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     965                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     966                                 SNDRV_PCM_INFO_RESUME |
     967                                 SNDRV_PCM_INFO_MMAP_VALID),
     968        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
     969        .rates =                SNDRV_PCM_RATE_8000_48000,
     970        .rate_min =             8000,
     971        .rate_max =             48000,
     972        .channels_min =         1,
     973        .channels_max =         2,
     974        .buffer_bytes_max =     (64*1024),
     975        .period_bytes_min =     384,
     976        .period_bytes_max =     (64*1024),
     977        .periods_min =          2,
     978        .periods_max =          2,
     979        .fifo_size =            0,
     980};
     981
     982static struct snd_pcm_hardware snd_emu10k1_capture_efx =
     983{
     984        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     985                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
     986                                 SNDRV_PCM_INFO_RESUME |
     987                                 SNDRV_PCM_INFO_MMAP_VALID),
     988        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
     989        .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
     990                                 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
     991                                 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
     992        .rate_min =             44100,
     993        .rate_max =             192000,
     994        .channels_min =         8,
     995        .channels_max =         8,
     996        .buffer_bytes_max =     (64*1024),
     997        .period_bytes_min =     384,
     998        .period_bytes_max =     (64*1024),
     999        .periods_min =          2,
     1000        .periods_max =          2,
     1001        .fifo_size =            0,
    10491002};
    10501003
     
    10531006 */
    10541007
    1055 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, snd_kcontrol_t *kctl, int idx, int activate)
    1056 {
    1057     snd_ctl_elem_id_t id;
    1058 
    1059     if (! kctl)
    1060         return;
    1061     if (activate)
    1062         kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    1063     else
    1064         kctl->vd[idx].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    1065     snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE |
    1066                    SNDRV_CTL_EVENT_MASK_INFO,
    1067                    snd_ctl_build_ioff(&id, kctl, idx));
     1008static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, struct snd_kcontrol *kctl, int idx, int activate)
     1009{
     1010        struct snd_ctl_elem_id id;
     1011
     1012        if (! kctl)
     1013                return;
     1014        if (activate)
     1015                kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     1016        else
     1017                kctl->vd[idx].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     1018        snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE |
     1019                       SNDRV_CTL_EVENT_MASK_INFO,
     1020                       snd_ctl_build_ioff(&id, kctl, idx));
    10681021}
    10691022
    10701023static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
    10711024{
    1072     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate);
    1073     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate);
    1074     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate);
     1025        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate);
     1026        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate);
     1027        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate);
    10751028}
    10761029
    10771030static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
    10781031{
    1079     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate);
    1080     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate);
    1081     snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate);
    1082 }
    1083 
    1084 static void snd_emu10k1_pcm_free_substream(snd_pcm_runtime_t *runtime)
    1085 {
    1086     struct snd_emu10k1_pcm *epcm = runtime->private_data;
    1087     if (epcm)
    1088         kfree(epcm);
    1089 }
    1090 
    1091 static int snd_emu10k1_efx_playback_close(snd_pcm_substream_t * substream)
    1092 {
    1093     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1094     struct snd_emu10k1_pcm_mixer *mix;
    1095     int i;
    1096 
    1097     for (i=0; i < NUM_EFX_PLAYBACK; i++) {
    1098         mix = &emu->efx_pcm_mixer[i];
    1099         mix->epcm = NULL;
    1100         snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0);
    1101     }
    1102     return 0;
    1103 }
    1104 
    1105 static int snd_emu10k1_efx_playback_open(snd_pcm_substream_t * substream)
    1106 {
    1107     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1108     struct snd_emu10k1_pcm *epcm;
    1109     struct snd_emu10k1_pcm_mixer *mix;
    1110     snd_pcm_runtime_t *runtime = substream->runtime;
    1111     int i;
    1112 
    1113     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    1114     if (epcm == NULL)
    1115         return -ENOMEM;
    1116     epcm->emu = emu;
    1117     epcm->type = PLAYBACK_EFX;
    1118     epcm->substream = substream;
    1119 
    1120     emu->pcm_playback_efx_substream = substream;
    1121 
    1122     runtime->private_data = epcm;
    1123     runtime->private_free = snd_emu10k1_pcm_free_substream;
    1124     runtime->hw = snd_emu10k1_efx_playback;
    1125 
    1126     for (i=0; i < NUM_EFX_PLAYBACK; i++) {
    1127         mix = &emu->efx_pcm_mixer[i];
    1128         mix->send_routing[0][0] = i;
    1129         memset(&mix->send_volume, 0, sizeof(mix->send_volume));
    1130         mix->send_volume[0][0] = 255;
    1131         mix->attn[0] = 0xffff;
    1132         mix->epcm = epcm;
    1133         snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1);
    1134     }
    1135     return 0;
    1136 }
    1137 
    1138 static int snd_emu10k1_playback_open(snd_pcm_substream_t * substream)
    1139 {
    1140     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1141     struct snd_emu10k1_pcm *epcm;
    1142     struct snd_emu10k1_pcm_mixer *mix;
    1143     snd_pcm_runtime_t *runtime = substream->runtime;
    1144     int i, err;
    1145 
    1146     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    1147     if (epcm == NULL)
    1148         return -ENOMEM;
    1149     epcm->emu = emu;
    1150     epcm->type = PLAYBACK_EMUVOICE;
    1151     epcm->substream = substream;
    1152     runtime->private_data = epcm;
    1153     runtime->private_free = snd_emu10k1_pcm_free_substream;
    1154     runtime->hw = snd_emu10k1_playback;
    1155     if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
    1156         kfree(epcm);
    1157         return err;
    1158     }
    1159     if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) {
    1160         kfree(epcm);
    1161         return err;
    1162     }
    1163     mix = &emu->pcm_mixer[substream->number];
    1164     for (i = 0; i < 4; i++)
    1165         mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
    1166     memset(&mix->send_volume, 0, sizeof(mix->send_volume));
    1167     mix->send_volume[0][0] = mix->send_volume[0][1] =
    1168         mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
    1169     mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
    1170     mix->epcm = epcm;
    1171     snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1);
    1172     return 0;
    1173 }
    1174 
    1175 static int snd_emu10k1_playback_close(snd_pcm_substream_t * substream)
    1176 {
    1177     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1178     struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number];
    1179 
    1180     mix->epcm = NULL;
    1181     snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0);
    1182     return 0;
    1183 }
    1184 
    1185 static int snd_emu10k1_capture_open(snd_pcm_substream_t * substream)
    1186 {
    1187     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1188     snd_pcm_runtime_t *runtime = substream->runtime;
    1189     struct snd_emu10k1_pcm *epcm;
    1190 
    1191     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    1192     if (epcm == NULL)
    1193         return -ENOMEM;
    1194     epcm->emu = emu;
    1195     epcm->type = CAPTURE_AC97ADC;
    1196     epcm->substream = substream;
    1197     epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL;
    1198     epcm->capture_inte = INTE_ADCBUFENABLE;
    1199     epcm->capture_ba_reg = ADCBA;
    1200     epcm->capture_bs_reg = ADCBS;
    1201     epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX;
    1202     runtime->private_data = epcm;
    1203     runtime->private_free = snd_emu10k1_pcm_free_substream;
    1204     runtime->hw = snd_emu10k1_capture;
    1205     emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt;
    1206     emu->pcm_capture_substream = substream;
    1207     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
    1208     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates);
    1209     return 0;
    1210 }
    1211 
    1212 static int snd_emu10k1_capture_close(snd_pcm_substream_t * substream)
    1213 {
    1214     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1215 
    1216     emu->capture_interrupt = NULL;
    1217     emu->pcm_capture_substream = NULL;
    1218     return 0;
    1219 }
    1220 
    1221 static int snd_emu10k1_capture_mic_open(snd_pcm_substream_t * substream)
    1222 {
    1223     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1224     struct snd_emu10k1_pcm *epcm;
    1225     snd_pcm_runtime_t *runtime = substream->runtime;
    1226 
    1227     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    1228     if (epcm == NULL)
    1229         return -ENOMEM;
    1230     epcm->emu = emu;
    1231     epcm->type = CAPTURE_AC97MIC;
    1232     epcm->substream = substream;
    1233     epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL;
    1234     epcm->capture_inte = INTE_MICBUFENABLE;
    1235     epcm->capture_ba_reg = MICBA;
    1236     epcm->capture_bs_reg = MICBS;
    1237     epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX;
    1238     substream->runtime->private_data = epcm;
    1239     substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
    1240     runtime->hw = snd_emu10k1_capture;
    1241     runtime->hw.rates = SNDRV_PCM_RATE_8000;
    1242     runtime->hw.rate_min = runtime->hw.rate_max = 8000;
    1243     runtime->hw.channels_min = 1;
    1244     emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt;
    1245     emu->pcm_capture_mic_substream = substream;
    1246     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
    1247     return 0;
    1248 }
    1249 
    1250 static int snd_emu10k1_capture_mic_close(snd_pcm_substream_t * substream)
    1251 {
    1252     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1253 
    1254     emu->capture_interrupt = NULL;
    1255     emu->pcm_capture_mic_substream = NULL;
    1256     return 0;
    1257 }
    1258 
    1259 static int snd_emu10k1_capture_efx_open(snd_pcm_substream_t * substream)
    1260 {
    1261     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1262     struct snd_emu10k1_pcm *epcm;
    1263     snd_pcm_runtime_t *runtime = substream->runtime;
    1264     int nefx = emu->audigy ? 64 : 32;
    1265     int idx;
    1266 
    1267     epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL);
    1268     if (epcm == NULL)
    1269         return -ENOMEM;
    1270     epcm->emu = emu;
    1271     epcm->type = CAPTURE_EFX;
    1272     epcm->substream = substream;
    1273     epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL;
    1274     epcm->capture_inte = INTE_EFXBUFENABLE;
    1275     epcm->capture_ba_reg = FXBA;
    1276     epcm->capture_bs_reg = FXBS;
    1277     epcm->capture_idx_reg = FXIDX;
    1278     substream->runtime->private_data = epcm;
    1279     substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
    1280     runtime->hw = snd_emu10k1_capture;
    1281     runtime->hw.rates = SNDRV_PCM_RATE_48000;
    1282     runtime->hw.rate_min = runtime->hw.rate_max = 48000;
    1283     spin_lock_irq(&emu->reg_lock);
    1284     runtime->hw.channels_min = runtime->hw.channels_max = 0;
    1285     for (idx = 0; idx < nefx; idx++) {
    1286         if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) {
    1287             runtime->hw.channels_min++;
    1288             runtime->hw.channels_max++;
    1289         }
    1290     }
    1291     epcm->capture_cr_val = emu->efx_voices_mask[0];
    1292     epcm->capture_cr_val2 = emu->efx_voices_mask[1];
    1293     spin_unlock_irq(&emu->reg_lock);
    1294     emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt;
    1295     emu->pcm_capture_efx_substream = substream;
    1296     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
    1297     return 0;
    1298 }
    1299 
    1300 static int snd_emu10k1_capture_efx_close(snd_pcm_substream_t * substream)
    1301 {
    1302     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1303 
    1304     emu->capture_interrupt = NULL;
    1305     emu->pcm_capture_efx_substream = NULL;
    1306     return 0;
    1307 }
    1308 
    1309 static snd_pcm_ops_t snd_emu10k1_playback_ops = {
    1310     snd_emu10k1_playback_open,
    1311     snd_emu10k1_playback_close,
    1312     snd_pcm_lib_ioctl,
    1313     snd_emu10k1_playback_hw_params,
    1314     snd_emu10k1_playback_hw_free,
    1315     snd_emu10k1_playback_prepare,
    1316     snd_emu10k1_playback_trigger,
    1317     snd_emu10k1_playback_pointer,0,0,
    1318     snd_pcm_sgbuf_ops_page,0
     1032        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate);
     1033        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate);
     1034        snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate);
     1035}
     1036
     1037static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime *runtime)
     1038{
     1039        kfree(runtime->private_data);
     1040}
     1041
     1042static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream *substream)
     1043{
     1044        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1045        struct snd_emu10k1_pcm_mixer *mix;
     1046        int i;
     1047
     1048        for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
     1049                mix = &emu->efx_pcm_mixer[i];
     1050                mix->epcm = NULL;
     1051                snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0);
     1052        }
     1053        return 0;
     1054}
     1055
     1056static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream)
     1057{
     1058        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1059        struct snd_emu10k1_pcm *epcm;
     1060        struct snd_emu10k1_pcm_mixer *mix;
     1061        struct snd_pcm_runtime *runtime = substream->runtime;
     1062        int i;
     1063
     1064        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     1065        if (epcm == NULL)
     1066                return -ENOMEM;
     1067        epcm->emu = emu;
     1068        epcm->type = PLAYBACK_EFX;
     1069        epcm->substream = substream;
     1070       
     1071        emu->pcm_playback_efx_substream = substream;
     1072
     1073        runtime->private_data = epcm;
     1074        runtime->private_free = snd_emu10k1_pcm_free_substream;
     1075        runtime->hw = snd_emu10k1_efx_playback;
     1076       
     1077        for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
     1078                mix = &emu->efx_pcm_mixer[i];
     1079                mix->send_routing[0][0] = i;
     1080                memset(&mix->send_volume, 0, sizeof(mix->send_volume));
     1081                mix->send_volume[0][0] = 255;
     1082                mix->attn[0] = 0xffff;
     1083                mix->epcm = epcm;
     1084                snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1);
     1085        }
     1086        return 0;
     1087}
     1088
     1089static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)
     1090{
     1091        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1092        struct snd_emu10k1_pcm *epcm;
     1093        struct snd_emu10k1_pcm_mixer *mix;
     1094        struct snd_pcm_runtime *runtime = substream->runtime;
     1095        int i, err;
     1096
     1097        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     1098        if (epcm == NULL)
     1099                return -ENOMEM;
     1100        epcm->emu = emu;
     1101        epcm->type = PLAYBACK_EMUVOICE;
     1102        epcm->substream = substream;
     1103        runtime->private_data = epcm;
     1104        runtime->private_free = snd_emu10k1_pcm_free_substream;
     1105        runtime->hw = snd_emu10k1_playback;
     1106        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
     1107                kfree(epcm);
     1108                return err;
     1109        }
     1110        if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) {
     1111                kfree(epcm);
     1112                return err;
     1113        }
     1114        mix = &emu->pcm_mixer[substream->number];
     1115        for (i = 0; i < 4; i++)
     1116                mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
     1117        memset(&mix->send_volume, 0, sizeof(mix->send_volume));
     1118        mix->send_volume[0][0] = mix->send_volume[0][1] =
     1119        mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
     1120        mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
     1121        mix->epcm = epcm;
     1122        snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1);
     1123        return 0;
     1124}
     1125
     1126static int snd_emu10k1_playback_close(struct snd_pcm_substream *substream)
     1127{
     1128        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1129        struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number];
     1130
     1131        mix->epcm = NULL;
     1132        snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0);
     1133        return 0;
     1134}
     1135
     1136static int snd_emu10k1_capture_open(struct snd_pcm_substream *substream)
     1137{
     1138        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1139        struct snd_pcm_runtime *runtime = substream->runtime;
     1140        struct snd_emu10k1_pcm *epcm;
     1141
     1142        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     1143        if (epcm == NULL)
     1144                return -ENOMEM;
     1145        epcm->emu = emu;
     1146        epcm->type = CAPTURE_AC97ADC;
     1147        epcm->substream = substream;
     1148        epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL;
     1149        epcm->capture_inte = INTE_ADCBUFENABLE;
     1150        epcm->capture_ba_reg = ADCBA;
     1151        epcm->capture_bs_reg = ADCBS;
     1152        epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX;
     1153        runtime->private_data = epcm;
     1154        runtime->private_free = snd_emu10k1_pcm_free_substream;
     1155        runtime->hw = snd_emu10k1_capture;
     1156        emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt;
     1157        emu->pcm_capture_substream = substream;
     1158        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
     1159        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates);
     1160        return 0;
     1161}
     1162
     1163static int snd_emu10k1_capture_close(struct snd_pcm_substream *substream)
     1164{
     1165        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1166
     1167        emu->capture_interrupt = NULL;
     1168        emu->pcm_capture_substream = NULL;
     1169        return 0;
     1170}
     1171
     1172static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream *substream)
     1173{
     1174        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1175        struct snd_emu10k1_pcm *epcm;
     1176        struct snd_pcm_runtime *runtime = substream->runtime;
     1177
     1178        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     1179        if (epcm == NULL)
     1180                return -ENOMEM;
     1181        epcm->emu = emu;
     1182        epcm->type = CAPTURE_AC97MIC;
     1183        epcm->substream = substream;
     1184        epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL;
     1185        epcm->capture_inte = INTE_MICBUFENABLE;
     1186        epcm->capture_ba_reg = MICBA;
     1187        epcm->capture_bs_reg = MICBS;
     1188        epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX;
     1189        substream->runtime->private_data = epcm;
     1190        substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
     1191        runtime->hw = snd_emu10k1_capture;
     1192        runtime->hw.rates = SNDRV_PCM_RATE_8000;
     1193        runtime->hw.rate_min = runtime->hw.rate_max = 8000;
     1194        runtime->hw.channels_min = 1;
     1195        emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt;
     1196        emu->pcm_capture_mic_substream = substream;
     1197        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
     1198        return 0;
     1199}
     1200
     1201static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream *substream)
     1202{
     1203        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1204
     1205        emu->capture_interrupt = NULL;
     1206        emu->pcm_capture_mic_substream = NULL;
     1207        return 0;
     1208}
     1209
     1210static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
     1211{
     1212        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1213        struct snd_emu10k1_pcm *epcm;
     1214        struct snd_pcm_runtime *runtime = substream->runtime;
     1215        int nefx = emu->audigy ? 64 : 32;
     1216        int idx;
     1217
     1218        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
     1219        if (epcm == NULL)
     1220                return -ENOMEM;
     1221        epcm->emu = emu;
     1222        epcm->type = CAPTURE_EFX;
     1223        epcm->substream = substream;
     1224        epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL;
     1225        epcm->capture_inte = INTE_EFXBUFENABLE;
     1226        epcm->capture_ba_reg = FXBA;
     1227        epcm->capture_bs_reg = FXBS;
     1228        epcm->capture_idx_reg = FXIDX;
     1229        substream->runtime->private_data = epcm;
     1230        substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
     1231        runtime->hw = snd_emu10k1_capture_efx;
     1232        runtime->hw.rates = SNDRV_PCM_RATE_48000;
     1233        runtime->hw.rate_min = runtime->hw.rate_max = 48000;
     1234        spin_lock_irq(&emu->reg_lock);
     1235        if (emu->card_capabilities->emu1010) {
     1236                /* TODO
     1237                 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
     1238                 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
     1239                 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
     1240                 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
     1241                 * rate_min = 44100,
     1242                 * rate_max = 192000,
     1243                 * channels_min = 8,
     1244                 * channels_max = 8,
     1245                 * Need to add mixer control to fix sample rate
     1246                 *                 
     1247                 * There are 16 mono channels of 16bits each.
     1248                 * 24bit Audio uses 2x channels over 16bit
     1249                 * 96kHz uses 2x channels over 48kHz
     1250                 * 192kHz uses 4x channels over 48kHz
     1251                 * So, for 48kHz 24bit, one has 8 channels
     1252                 * for 96kHz 24bit, one has 4 channels
     1253                 * for 192kHz 24bit, one has 2 channels
     1254                 */
     1255#if 1
     1256                switch (emu->emu1010.internal_clock) {
     1257                case 0:
     1258                        /* For 44.1kHz */
     1259                        runtime->hw.rates = SNDRV_PCM_RATE_44100;
     1260                        runtime->hw.rate_min = runtime->hw.rate_max = 44100;
     1261                        runtime->hw.channels_min = runtime->hw.channels_max = 8;
     1262                        break;
     1263                case 1:
     1264                        /* For 48kHz */
     1265                        runtime->hw.rates = SNDRV_PCM_RATE_48000;
     1266                        runtime->hw.rate_min = runtime->hw.rate_max = 48000;
     1267                        runtime->hw.channels_min = runtime->hw.channels_max = 8;
     1268                        break;
     1269                };
     1270#endif
     1271#if 0
     1272                /* For 96kHz */
     1273                runtime->hw.rates = SNDRV_PCM_RATE_96000;
     1274                runtime->hw.rate_min = runtime->hw.rate_max = 96000;
     1275                runtime->hw.channels_min = runtime->hw.channels_max = 4;
     1276#endif
     1277#if 0
     1278                /* For 192kHz */
     1279                runtime->hw.rates = SNDRV_PCM_RATE_192000;
     1280                runtime->hw.rate_min = runtime->hw.rate_max = 192000;
     1281                runtime->hw.channels_min = runtime->hw.channels_max = 2;
     1282#endif
     1283                runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
     1284                /* efx_voices_mask[0] is expected to be zero
     1285                 * efx_voices_mask[1] is expected to have 16bits set
     1286                 */
     1287        } else {
     1288                runtime->hw.channels_min = runtime->hw.channels_max = 0;
     1289                for (idx = 0; idx < nefx; idx++) {
     1290                        if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) {
     1291                                runtime->hw.channels_min++;
     1292                                runtime->hw.channels_max++;
     1293                        }
     1294                }
     1295        }
     1296        epcm->capture_cr_val = emu->efx_voices_mask[0];
     1297        epcm->capture_cr_val2 = emu->efx_voices_mask[1];
     1298        spin_unlock_irq(&emu->reg_lock);
     1299        emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt;
     1300        emu->pcm_capture_efx_substream = substream;
     1301        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
     1302        return 0;
     1303}
     1304
     1305static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream *substream)
     1306{
     1307        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1308
     1309        emu->capture_interrupt = NULL;
     1310        emu->pcm_capture_efx_substream = NULL;
     1311        return 0;
     1312}
     1313
     1314static struct snd_pcm_ops snd_emu10k1_playback_ops = {
     1315        .open =                 snd_emu10k1_playback_open,
     1316        .close =                snd_emu10k1_playback_close,
     1317        .ioctl =                snd_pcm_lib_ioctl,
     1318        .hw_params =            snd_emu10k1_playback_hw_params,
     1319        .hw_free =              snd_emu10k1_playback_hw_free,
     1320        .prepare =              snd_emu10k1_playback_prepare,
     1321        .trigger =              snd_emu10k1_playback_trigger,
     1322        .pointer =              snd_emu10k1_playback_pointer,
     1323        .page =                 snd_pcm_sgbuf_ops_page,
    13191324};
    13201325
    1321 static snd_pcm_ops_t snd_emu10k1_capture_ops = {
    1322     snd_emu10k1_capture_open,
    1323     snd_emu10k1_capture_close,
    1324     snd_pcm_lib_ioctl,
    1325     snd_emu10k1_capture_hw_params,
    1326     snd_emu10k1_capture_hw_free,
    1327     snd_emu10k1_capture_prepare,
    1328     snd_emu10k1_capture_trigger,
    1329     snd_emu10k1_capture_pointer,0,0,0,0
     1326static struct snd_pcm_ops snd_emu10k1_capture_ops = {
     1327        .open =                 snd_emu10k1_capture_open,
     1328        .close =                snd_emu10k1_capture_close,
     1329        .ioctl =                snd_pcm_lib_ioctl,
     1330        .hw_params =            snd_emu10k1_capture_hw_params,
     1331        .hw_free =              snd_emu10k1_capture_hw_free,
     1332        .prepare =              snd_emu10k1_capture_prepare,
     1333        .trigger =              snd_emu10k1_capture_trigger,
     1334        .pointer =              snd_emu10k1_capture_pointer,
    13301335};
    13311336
    13321337/* EFX playback */
    1333 static snd_pcm_ops_t snd_emu10k1_efx_playback_ops = {
    1334     /*.open =           */      snd_emu10k1_efx_playback_open,
    1335     /*.close =          */      snd_emu10k1_efx_playback_close,
    1336     /*.ioctl =          */      snd_pcm_lib_ioctl,
    1337     /*.hw_params =      */      snd_emu10k1_playback_hw_params,
    1338     /*.hw_free =        */      snd_emu10k1_efx_playback_hw_free,
    1339     /*.prepare =        */      snd_emu10k1_efx_playback_prepare,
    1340     /*.trigger =        */      snd_emu10k1_efx_playback_trigger,
    1341     /*.pointer =        */      snd_emu10k1_efx_playback_pointer,
    1342     0,0,
    1343     /*.page =           */      snd_pcm_sgbuf_ops_page,
    1344     0
     1338static struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
     1339        .open =                 snd_emu10k1_efx_playback_open,
     1340        .close =                snd_emu10k1_efx_playback_close,
     1341        .ioctl =                snd_pcm_lib_ioctl,
     1342        .hw_params =            snd_emu10k1_playback_hw_params,
     1343        .hw_free =              snd_emu10k1_efx_playback_hw_free,
     1344        .prepare =              snd_emu10k1_efx_playback_prepare,
     1345        .trigger =              snd_emu10k1_efx_playback_trigger,
     1346        .pointer =              snd_emu10k1_efx_playback_pointer,
     1347        .page =                 snd_pcm_sgbuf_ops_page,
    13451348};
    13461349
    1347 static void snd_emu10k1_pcm_free(snd_pcm_t *pcm)
    1348 {
    1349     struct snd_emu10k1 *emu = pcm->private_data;
    1350     emu->pcm = NULL;
    1351     snd_pcm_lib_preallocate_free_for_all(pcm);
    1352 }
    1353 
    1354 int __devinit snd_emu10k1_pcm(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm)
    1355 {
    1356     snd_pcm_t *pcm;
    1357     snd_pcm_substream_t *substream;
    1358     int err;
    1359 
    1360     if (rpcm)
    1361         *rpcm = NULL;
    1362 
    1363     if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0)
    1364         return err;
    1365 
    1366     pcm->private_data = emu;
    1367     pcm->private_free = snd_emu10k1_pcm_free;
    1368 
    1369     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops);
    1370     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops);
    1371 
    1372     pcm->info_flags = 0;
    1373     pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
    1374     strcpy(pcm->name, "EMU10K1");
    1375     emu->pcm = pcm;
    1376 
    1377     for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
    1378         if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
    1379             return err;
    1380 
    1381     for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next)
    1382         snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1383 
    1384     if (rpcm)
    1385         *rpcm = pcm;
    1386 
    1387     return 0;
    1388 }
    1389 
    1390 int __devinit snd_emu10k1_pcm_multi(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm)
    1391 {
    1392     snd_pcm_t *pcm;
    1393     snd_pcm_substream_t *substream;
    1394     int err;
    1395 
    1396     if (rpcm)
    1397         *rpcm = NULL;
    1398 
    1399     if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0)
    1400         return err;
    1401 
    1402     pcm->private_data = emu;
    1403     pcm->private_free = snd_emu10k1_pcm_free;
    1404 
    1405     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops);
    1406 
    1407     pcm->info_flags = 0;
    1408     pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
    1409     strcpy(pcm->name, "EMU10K1 multichannel EFX");
    1410     emu->pcm = pcm;
    1411 
    1412     for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
    1413         if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
    1414             return err;
    1415 
    1416     if (rpcm)
    1417         *rpcm = pcm;
    1418 
    1419     return 0;
    1420 }
    1421 
    1422 static snd_pcm_ops_t snd_emu10k1_capture_mic_ops = {
    1423     snd_emu10k1_capture_mic_open,
    1424     snd_emu10k1_capture_mic_close,
    1425     snd_pcm_lib_ioctl,
    1426     snd_emu10k1_capture_hw_params,
    1427     snd_emu10k1_capture_hw_free,
    1428     snd_emu10k1_capture_prepare,
    1429     snd_emu10k1_capture_trigger,
    1430     snd_emu10k1_capture_pointer,0,0,0,0
     1350int __devinit snd_emu10k1_pcm(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1351{
     1352        struct snd_pcm *pcm;
     1353        struct snd_pcm_substream *substream;
     1354        int err;
     1355
     1356        if (rpcm)
     1357                *rpcm = NULL;
     1358
     1359        if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0)
     1360                return err;
     1361
     1362        pcm->private_data = emu;
     1363
     1364        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops);
     1365        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops);
     1366
     1367        pcm->info_flags = 0;
     1368        pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
     1369        strcpy(pcm->name, "ADC Capture/Standard PCM Playback");
     1370        emu->pcm = pcm;
     1371
     1372        for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
     1373                if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
     1374                        return err;
     1375
     1376        for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next)
     1377                snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
     1378
     1379        if (rpcm)
     1380                *rpcm = pcm;
     1381
     1382        return 0;
     1383}
     1384
     1385int __devinit snd_emu10k1_pcm_multi(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1386{
     1387        struct snd_pcm *pcm;
     1388        struct snd_pcm_substream *substream;
     1389        int err;
     1390
     1391        if (rpcm)
     1392                *rpcm = NULL;
     1393
     1394        if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0)
     1395                return err;
     1396
     1397        pcm->private_data = emu;
     1398
     1399        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops);
     1400
     1401        pcm->info_flags = 0;
     1402        pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
     1403        strcpy(pcm->name, "Multichannel Playback");
     1404        emu->pcm_multi = pcm;
     1405
     1406        for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
     1407                if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0)
     1408                        return err;
     1409
     1410        if (rpcm)
     1411                *rpcm = pcm;
     1412
     1413        return 0;
     1414}
     1415
     1416
     1417static struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
     1418        .open =                 snd_emu10k1_capture_mic_open,
     1419        .close =                snd_emu10k1_capture_mic_close,
     1420        .ioctl =                snd_pcm_lib_ioctl,
     1421        .hw_params =            snd_emu10k1_capture_hw_params,
     1422        .hw_free =              snd_emu10k1_capture_hw_free,
     1423        .prepare =              snd_emu10k1_capture_prepare,
     1424        .trigger =              snd_emu10k1_capture_trigger,
     1425        .pointer =              snd_emu10k1_capture_pointer,
    14311426};
    14321427
    1433 static void snd_emu10k1_pcm_mic_free(snd_pcm_t *pcm)
    1434 {
    1435     struct snd_emu10k1 *emu = pcm->private_data;
    1436     emu->pcm_mic = NULL;
    1437     snd_pcm_lib_preallocate_free_for_all(pcm);
    1438 }
    1439 
    1440 int __devinit snd_emu10k1_pcm_mic(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm)
    1441 {
    1442     snd_pcm_t *pcm;
    1443     int err;
    1444 
    1445     if (rpcm)
    1446         *rpcm = NULL;
    1447 
    1448     if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0)
    1449         return err;
    1450 
    1451     pcm->private_data = emu;
    1452     pcm->private_free = snd_emu10k1_pcm_mic_free;
    1453 
    1454     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops);
    1455 
    1456     pcm->info_flags = 0;
    1457     strcpy(pcm->name, "EMU10K1 MIC");
    1458     emu->pcm_mic = pcm;
    1459 
    1460     snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1461 
    1462     if (rpcm)
    1463         *rpcm = pcm;
    1464     return 0;
    1465 }
    1466 
    1467 
    1468 static int snd_emu10k1_pcm_efx_voices_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1469 {
    1470     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    1471     int nefx = emu->audigy ? 64 : 32;
    1472     uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
    1473     uinfo->count = nefx;
    1474     uinfo->value.integer.min = 0;
    1475     uinfo->value.integer.max = 1;
    1476     return 0;
    1477 }
    1478 
    1479 static int snd_emu10k1_pcm_efx_voices_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1480 {
    1481     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    1482     int nefx = emu->audigy ? 64 : 32;
    1483     int idx;
    1484 
    1485     spin_lock_irq(&emu->reg_lock);
    1486     for (idx = 0; idx < nefx; idx++)
    1487         ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0;
    1488     spin_unlock_irq(&emu->reg_lock);
    1489     return 0;
    1490 }
    1491 
    1492 static int snd_emu10k1_pcm_efx_voices_mask_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1493 {
    1494     struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
    1495     unsigned int nval[2], bits;
    1496     int nefx = emu->audigy ? 64 : 32;
    1497     int nefxb = emu->audigy ? 7 : 6;
    1498     int change, idx;
    1499 
    1500     nval[0] = nval[1] = 0;
    1501     for (idx = 0, bits = 0; idx < nefx; idx++)
    1502         if (ucontrol->value.integer.value[idx]) {
    1503             nval[idx / 32] |= 1 << (idx % 32);
    1504             bits++;
    1505         }
    1506     for (idx = 0; idx < nefxb; idx++)
    1507         if (1 << idx == bits)
    1508             break;
    1509     if (idx >= nefxb)
    1510         return -EINVAL;
    1511     spin_lock_irq(&emu->reg_lock);
    1512     change = (nval[0] != emu->efx_voices_mask[0]) ||
    1513         (nval[1] != emu->efx_voices_mask[1]);
    1514     emu->efx_voices_mask[0] = nval[0];
    1515     emu->efx_voices_mask[1] = nval[1];
    1516     spin_unlock_irq(&emu->reg_lock);
    1517     return change;
    1518 }
    1519 
    1520 static snd_kcontrol_new_t snd_emu10k1_pcm_efx_voices_mask = {
    1521     SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    1522     "Captured FX8010 Outputs",0,0, 0,
    1523     snd_emu10k1_pcm_efx_voices_mask_info,
    1524     snd_emu10k1_pcm_efx_voices_mask_get,
    1525     snd_emu10k1_pcm_efx_voices_mask_put,0
     1428int __devinit snd_emu10k1_pcm_mic(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1429{
     1430        struct snd_pcm *pcm;
     1431        int err;
     1432
     1433        if (rpcm)
     1434                *rpcm = NULL;
     1435
     1436        if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0)
     1437                return err;
     1438
     1439        pcm->private_data = emu;
     1440
     1441        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops);
     1442
     1443        pcm->info_flags = 0;
     1444        strcpy(pcm->name, "Mic Capture");
     1445        emu->pcm_mic = pcm;
     1446
     1447        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
     1448
     1449        if (rpcm)
     1450                *rpcm = pcm;
     1451        return 0;
     1452}
     1453
     1454static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
     1455{
     1456        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     1457        int nefx = emu->audigy ? 64 : 32;
     1458        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     1459        uinfo->count = nefx;
     1460        uinfo->value.integer.min = 0;
     1461        uinfo->value.integer.max = 1;
     1462        return 0;
     1463}
     1464
     1465static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     1466{
     1467        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     1468        int nefx = emu->audigy ? 64 : 32;
     1469        int idx;
     1470       
     1471        spin_lock_irq(&emu->reg_lock);
     1472        for (idx = 0; idx < nefx; idx++)
     1473                ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0;
     1474        spin_unlock_irq(&emu->reg_lock);
     1475        return 0;
     1476}
     1477
     1478static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
     1479{
     1480        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
     1481        unsigned int nval[2], bits;
     1482        int nefx = emu->audigy ? 64 : 32;
     1483        int nefxb = emu->audigy ? 7 : 6;
     1484        int change, idx;
     1485       
     1486        nval[0] = nval[1] = 0;
     1487        for (idx = 0, bits = 0; idx < nefx; idx++)
     1488                if (ucontrol->value.integer.value[idx]) {
     1489                        nval[idx / 32] |= 1 << (idx % 32);
     1490                        bits++;
     1491                }
     1492               
     1493        for (idx = 0; idx < nefxb; idx++)
     1494                if (1 << idx == bits)
     1495                        break;
     1496       
     1497        if (idx >= nefxb)
     1498                return -EINVAL;
     1499
     1500        spin_lock_irq(&emu->reg_lock);
     1501        change = (nval[0] != emu->efx_voices_mask[0]) ||
     1502                (nval[1] != emu->efx_voices_mask[1]);
     1503        emu->efx_voices_mask[0] = nval[0];
     1504        emu->efx_voices_mask[1] = nval[1];
     1505        spin_unlock_irq(&emu->reg_lock);
     1506        return change;
     1507}
     1508
     1509static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = {
     1510        .iface = SNDRV_CTL_ELEM_IFACE_PCM,
     1511        .name = "Captured FX8010 Outputs",
     1512        .info = snd_emu10k1_pcm_efx_voices_mask_info,
     1513        .get = snd_emu10k1_pcm_efx_voices_mask_get,
     1514        .put = snd_emu10k1_pcm_efx_voices_mask_put
    15261515};
    15271516
    1528 static snd_pcm_ops_t snd_emu10k1_capture_efx_ops = {
    1529     snd_emu10k1_capture_efx_open,
    1530     snd_emu10k1_capture_efx_close,
    1531     snd_pcm_lib_ioctl,
    1532     snd_emu10k1_capture_hw_params,
    1533     snd_emu10k1_capture_hw_free,
    1534     snd_emu10k1_capture_prepare,
    1535     snd_emu10k1_capture_trigger,
    1536     snd_emu10k1_capture_pointer,0,0,0,0
     1517static struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
     1518        .open =                 snd_emu10k1_capture_efx_open,
     1519        .close =                snd_emu10k1_capture_efx_close,
     1520        .ioctl =                snd_pcm_lib_ioctl,
     1521        .hw_params =            snd_emu10k1_capture_hw_params,
     1522        .hw_free =              snd_emu10k1_capture_hw_free,
     1523        .prepare =              snd_emu10k1_capture_prepare,
     1524        .trigger =              snd_emu10k1_capture_trigger,
     1525        .pointer =              snd_emu10k1_capture_pointer,
    15371526};
    15381527
     
    15451534static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1 *emu, void *private_data)
    15461535{
    1547     snd_pcm_substream_t *substream = private_data;
    1548     snd_pcm_period_elapsed(substream);
     1536        struct snd_pcm_substream *substream = private_data;
     1537        snd_pcm_period_elapsed(substream);
    15491538}
    15501539
    15511540static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left,
    1552                                                    unsigned short *dst_right,
    1553                                                    unsigned short *src,
    1554                                                    unsigned int count,
    1555                                                    unsigned int tram_shift)
    1556 {
    1557     // printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count);
    1558     if ((tram_shift & 1) == 0) {
    1559         while (count--) {
    1560             *dst_left-- = *src++;
    1561             *dst_right-- = *src++;
    1562         }
    1563     } else {
    1564         while (count--) {
    1565             *dst_right-- = *src++;
    1566             *dst_left-- = *src++;
    1567         }
    1568     }
    1569 }
    1570 
    1571 
    1572 static void fx8010_pb_trans_copy(snd_pcm_substream_t *substream,
    1573                                  struct snd_pcm_indirect *rec, size_t bytes)
    1574 {
    1575     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1576     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1577     unsigned int tram_size = pcm->buffer_size;
    1578     unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data);
    1579     unsigned int frames = bytes >> 2, count;
    1580     unsigned int tram_pos = pcm->tram_pos;
    1581     unsigned int tram_shift = pcm->tram_shift;
    1582 
    1583     while (frames > tram_pos) {
    1584         count = tram_pos + 1;
    1585         snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
    1586                                                (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
    1587                                                src, count, tram_shift);
    1588         src += count * 2;
    1589         frames -= count;
    1590         tram_pos = (tram_size / 2) - 1;
    1591         tram_shift++;
    1592     }
    1593     snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
    1594                                            (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
    1595                                            src, frames, tram_shift);
    1596     tram_pos -= frames;
    1597     pcm->tram_pos = tram_pos;
    1598     pcm->tram_shift = tram_shift;
    1599 }
    1600 
    1601 static int snd_emu10k1_fx8010_playback_transfer(snd_pcm_substream_t *substream)
    1602 {
    1603     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1604     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1605 
    1606     snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy);
    1607     return 0;
    1608 }
    1609 
    1610 static int snd_emu10k1_fx8010_playback_hw_params(snd_pcm_substream_t * substream,
    1611                                                  snd_pcm_hw_params_t * hw_params)
    1612 {
    1613     return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    1614 }
    1615 
    1616 static int snd_emu10k1_fx8010_playback_hw_free(snd_pcm_substream_t * substream)
    1617 {
    1618     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1619     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1620     unsigned int i;
    1621 
    1622     for (i = 0; i < pcm->channels; i++)
    1623         snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);
    1624     snd_pcm_lib_free_pages(substream);
    1625     return 0;
    1626 }
    1627 
    1628 static int snd_emu10k1_fx8010_playback_prepare(snd_pcm_substream_t * substream)
    1629 {
    1630     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1631     snd_pcm_runtime_t *runtime = substream->runtime;
    1632     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1633     unsigned int i;
    1634 
    1635     // printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2);
    1636     memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec));
    1637     pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */
    1638     pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
    1639     pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
    1640     pcm->tram_shift = 0;
    1641     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0);     /* reset */
    1642     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);     /* reset */
    1643     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size);
    1644     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0);         /* reset ptr number */
    1645     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size);
    1646     snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size);
    1647     for (i = 0; i < pcm->channels; i++)
    1648         snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels));
    1649     return 0;
    1650 }
    1651 
    1652 static int snd_emu10k1_fx8010_playback_trigger(snd_pcm_substream_t * substream, int cmd)
    1653 {
    1654     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1655     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1656     int result = 0;
    1657 
    1658     spin_lock(&emu->reg_lock);
    1659     switch (cmd) {
    1660     case SNDRV_PCM_TRIGGER_START:
    1661         /* follow thru */
    1662     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     1541                                                   unsigned short *dst_right,
     1542                                                   unsigned short *src,
     1543                                                   unsigned int count,
     1544                                                   unsigned int tram_shift)
     1545{
     1546        /* printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count); */
     1547        if ((tram_shift & 1) == 0) {
     1548                while (count--) {
     1549                        *dst_left-- = *src++;
     1550                        *dst_right-- = *src++;
     1551                }
     1552        } else {
     1553                while (count--) {
     1554                        *dst_right-- = *src++;
     1555                        *dst_left-- = *src++;
     1556                }
     1557        }
     1558}
     1559
     1560static void fx8010_pb_trans_copy(struct snd_pcm_substream *substream,
     1561                                 struct snd_pcm_indirect *rec, size_t bytes)
     1562{
     1563        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1564        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1565        unsigned int tram_size = pcm->buffer_size;
     1566        unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data);
     1567        unsigned int frames = bytes >> 2, count;
     1568        unsigned int tram_pos = pcm->tram_pos;
     1569        unsigned int tram_shift = pcm->tram_shift;
     1570
     1571        while (frames > tram_pos) {
     1572                count = tram_pos + 1;
     1573                snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
     1574                                                       (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
     1575                                                       src, count, tram_shift);
     1576                src += count * 2;
     1577                frames -= count;
     1578                tram_pos = (tram_size / 2) - 1;
     1579                tram_shift++;
     1580        }
     1581        snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
     1582                                               (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
     1583                                               src, frames, tram_shift);
     1584        tram_pos -= frames;
     1585        pcm->tram_pos = tram_pos;
     1586        pcm->tram_shift = tram_shift;
     1587}
     1588
     1589static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream *substream)
     1590{
     1591        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1592        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1593
     1594        snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy);
     1595        return 0;
     1596}
     1597
     1598static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream *substream,
     1599                                                 struct snd_pcm_hw_params *hw_params)
     1600{
     1601        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
     1602}
     1603
     1604static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream *substream)
     1605{
     1606        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1607        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1608        unsigned int i;
     1609
     1610        for (i = 0; i < pcm->channels; i++)
     1611                snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);
     1612        snd_pcm_lib_free_pages(substream);
     1613        return 0;
     1614}
     1615
     1616static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substream)
     1617{
     1618        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1619        struct snd_pcm_runtime *runtime = substream->runtime;
     1620        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1621        unsigned int i;
     1622       
     1623        /* printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2); */
     1624        memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec));
     1625        pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */
     1626        pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
     1627        pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
     1628        pcm->tram_shift = 0;
     1629        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0);     /* reset */
     1630        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);     /* reset */
     1631        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size);
     1632        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0);         /* reset ptr number */
     1633        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size);
     1634        snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size);
     1635        for (i = 0; i < pcm->channels; i++)
     1636                snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels));
     1637        return 0;
     1638}
     1639
     1640static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream *substream, int cmd)
     1641{
     1642        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1643        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1644        int result = 0;
     1645
     1646        spin_lock(&emu->reg_lock);
     1647        switch (cmd) {
     1648        case SNDRV_PCM_TRIGGER_START:
     1649                /* follow thru */
     1650        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     1651        case SNDRV_PCM_TRIGGER_RESUME:
    16631652#ifdef EMU10K1_SET_AC3_IEC958
    1664         {
    1665             int i;
    1666             for (i = 0; i < 3; i++) {
    1667                 unsigned int bits;
    1668                 bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
    1669                     SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
    1670                     0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT | SPCS_NOTAUDIODATA;
    1671                 snd_emu10k1_ptr_write(emu, SPCS0 + i, 0, bits);
    1672             }
    1673         }
     1653        {
     1654                int i;
     1655                for (i = 0; i < 3; i++) {
     1656                        unsigned int bits;
     1657                        bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
     1658                               SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
     1659                               0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT | SPCS_NOTAUDIODATA;
     1660                        snd_emu10k1_ptr_write(emu, SPCS0 + i, 0, bits);
     1661                }
     1662        }
    16741663#endif
    1675         result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq);
    1676         if (result < 0)
    1677             goto __err;
    1678         snd_emu10k1_fx8010_playback_transfer(substream);        /* roll the ball */
    1679         snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1);
    1680         break;
    1681     case SNDRV_PCM_TRIGGER_STOP:
    1682     case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    1683         snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL;
    1684         snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);
    1685         pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
    1686         pcm->tram_shift = 0;
    1687         break;
    1688     default:
    1689         result = -EINVAL;
    1690         break;
    1691     }
    1692 __err:
    1693     spin_unlock(&emu->reg_lock);
    1694     return result;
    1695 }
    1696 
    1697 static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(snd_pcm_substream_t * substream)
    1698 {
    1699     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1700     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1701     size_t ptr; /* byte pointer */
    1702 
    1703     if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0))
    1704         return 0;
    1705     ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2;
    1706     return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr);
     1664                result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq);
     1665                if (result < 0)
     1666                        goto __err;
     1667                snd_emu10k1_fx8010_playback_transfer(substream);        /* roll the ball */
     1668                snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1);
     1669                break;
     1670        case SNDRV_PCM_TRIGGER_STOP:
     1671        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     1672        case SNDRV_PCM_TRIGGER_SUSPEND:
     1673                snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL;
     1674                snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);
     1675                pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
     1676                pcm->tram_shift = 0;
     1677                break;
     1678        default:
     1679                result = -EINVAL;
     1680                break;
     1681        }
     1682      __err:
     1683        spin_unlock(&emu->reg_lock);
     1684        return result;
     1685}
     1686
     1687static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream *substream)
     1688{
     1689        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1690        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1691        size_t ptr; /* byte pointer */
     1692
     1693        if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0))
     1694                return 0;
     1695        ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2;
     1696        return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr);
    17071697}
    17081698
    17091699static struct snd_pcm_hardware snd_emu10k1_fx8010_playback =
    17101700{
    1711     .info =                     (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    1712                                 SNDRV_PCM_INFO_RESUME |
    1713                                 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE),
    1714                                  .formats =             SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    1715                                  .rates =               SNDRV_PCM_RATE_48000,
    1716                                  .rate_min =            48000,
    1717                                  .rate_max =            48000,
    1718                                  .channels_min =                1,
    1719                                  .channels_max =                1,
    1720                                  .buffer_bytes_max =    (128*1024),
    1721                                  .period_bytes_min =    1024,
    1722                                  .period_bytes_max =    (128*1024),
    1723                                  .periods_min =         1,
    1724                                  .periods_max =         1024,
    1725                                  .fifo_size =           0,
     1701        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     1702                                SNDRV_PCM_INFO_RESUME |
     1703                                /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE),
     1704        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     1705        .rates =                SNDRV_PCM_RATE_48000,
     1706        .rate_min =             48000,
     1707        .rate_max =             48000,
     1708        .channels_min =         1,
     1709        .channels_max =         1,
     1710        .buffer_bytes_max =     (128*1024),
     1711        .period_bytes_min =     1024,
     1712        .period_bytes_max =     (128*1024),
     1713        .periods_min =          1,
     1714        .periods_max =          1024,
     1715        .fifo_size =            0,
    17261716};
    17271717
    1728 static int snd_emu10k1_fx8010_playback_open(snd_pcm_substream_t * substream)
    1729 {
    1730     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1731     snd_pcm_runtime_t *runtime = substream->runtime;
    1732     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1733 
    1734     runtime->hw = snd_emu10k1_fx8010_playback;
    1735     runtime->hw.channels_min = runtime->hw.channels_max = pcm->channels;
    1736     runtime->hw.period_bytes_max = (pcm->buffer_size * 2) / 2;
    1737     spin_lock_irq(&emu->reg_lock);
    1738     if (pcm->valid == 0) {
    1739         spin_unlock_irq(&emu->reg_lock);
    1740         return -ENODEV;
    1741     }
    1742     pcm->opened = 1;
    1743     spin_unlock_irq(&emu->reg_lock);
    1744     return 0;
    1745 }
    1746 
    1747 static int snd_emu10k1_fx8010_playback_close(snd_pcm_substream_t * substream)
    1748 {
    1749     struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
    1750     struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
    1751 
    1752     spin_lock_irq(&emu->reg_lock);
    1753     pcm->opened = 0;
    1754     spin_unlock_irq(&emu->reg_lock);
    1755     return 0;
     1718static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream *substream)
     1719{
     1720        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1721        struct snd_pcm_runtime *runtime = substream->runtime;
     1722        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1723
     1724        runtime->hw = snd_emu10k1_fx8010_playback;
     1725        runtime->hw.channels_min = runtime->hw.channels_max = pcm->channels;
     1726        runtime->hw.period_bytes_max = (pcm->buffer_size * 2) / 2;
     1727        spin_lock_irq(&emu->reg_lock);
     1728        if (pcm->valid == 0) {
     1729                spin_unlock_irq(&emu->reg_lock);
     1730                return -ENODEV;
     1731        }
     1732        pcm->opened = 1;
     1733        spin_unlock_irq(&emu->reg_lock);
     1734        return 0;
     1735}
     1736
     1737static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream *substream)
     1738{
     1739        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
     1740        struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
     1741
     1742        spin_lock_irq(&emu->reg_lock);
     1743        pcm->opened = 0;
     1744        spin_unlock_irq(&emu->reg_lock);
     1745        return 0;
    17561746}
    17571747
     
    17681758};
    17691759
    1770 static void snd_emu10k1_pcm_efx_free(snd_pcm_t *pcm)
    1771 {
    1772     struct snd_emu10k1 *emu = pcm->private_data;
    1773     emu->pcm_efx = NULL;
    1774     snd_pcm_lib_preallocate_free_for_all(pcm);
    1775 }
    1776 
    1777 int __devinit snd_emu10k1_pcm_efx(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm)
    1778 {
    1779     snd_pcm_t *pcm;
    1780     snd_kcontrol_t *kctl;
    1781     int err;
    1782 
    1783     if (rpcm)
    1784         *rpcm = NULL;
    1785 
    1786     if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0)
    1787         return err;
    1788 
    1789     pcm->private_data = emu;
    1790     pcm->private_free = snd_emu10k1_pcm_efx_free;
    1791 
    1792     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops);
    1793     snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops);
    1794 
    1795     pcm->info_flags = 0;
    1796     strcpy(pcm->name, "EMU10K1 EFX");
    1797     emu->pcm_efx = pcm;
    1798     if (rpcm)
    1799         *rpcm = pcm;
    1800 
    1801     /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
    1802      * to these
    1803      */
    1804 
    1805     /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
    1806     if (emu->audigy) {
    1807         emu->efx_voices_mask[0] = 0;
    1808         emu->efx_voices_mask[1] = 0xffff;
    1809     } else {
    1810         emu->efx_voices_mask[0] = 0xffff0000;
    1811         emu->efx_voices_mask[1] = 0;
    1812     }
    1813 
    1814     kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu);
    1815     if (!kctl)
    1816         return -ENOMEM;
    1817     kctl->id.device = device;
    1818     snd_ctl_add(emu->card, kctl);
    1819     snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
    1820 
    1821     return 0;
    1822 }
    1823 
     1760int __devinit snd_emu10k1_pcm_efx(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm)
     1761{
     1762        struct snd_pcm *pcm;
     1763        struct snd_kcontrol *kctl;
     1764        int err;
     1765
     1766        if (rpcm)
     1767                *rpcm = NULL;
     1768
     1769        if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0)
     1770                return err;
     1771
     1772        pcm->private_data = emu;
     1773
     1774        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops);
     1775        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops);
     1776
     1777        pcm->info_flags = 0;
     1778        strcpy(pcm->name, "Multichannel Capture/PT Playback");
     1779        emu->pcm_efx = pcm;
     1780        if (rpcm)
     1781                *rpcm = pcm;
     1782
     1783        /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs
     1784         * to these
     1785         */     
     1786       
     1787        /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
     1788        if (emu->audigy) {
     1789                emu->efx_voices_mask[0] = 0;
     1790                emu->efx_voices_mask[1] = 0xffff;
     1791        } else {
     1792                emu->efx_voices_mask[0] = 0xffff0000;
     1793                emu->efx_voices_mask[1] = 0;
     1794        }
     1795        kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu);
     1796        if (!kctl)
     1797                return -ENOMEM;
     1798        kctl->id.device = device;
     1799        snd_ctl_add(emu->card, kctl);
     1800
     1801        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024);
     1802
     1803        return 0;
     1804}
  • GPL/trunk/alsa-kernel/pci/emu10k1/io.c

    r34 r84  
    2626 */
    2727
    28 #define __NO_VERSION__
    2928#include <sound/driver.h>
    3029#include <linux/time.h>
     
    6261        }
    6362}
     63
     64EXPORT_SYMBOL(snd_emu10k1_ptr_read);
    6465
    6566void snd_emu10k1_ptr_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data)
     
    9394}
    9495
     96EXPORT_SYMBOL(snd_emu10k1_ptr_write);
     97
    9598unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu,
    9699                                    unsigned int reg,
     
    123126    outl(data, emu->port + 0x20 + DATA);
    124127    spin_unlock_irqrestore(&emu->emu_lock, flags);
     128}
     129
     130int snd_emu10k1_spi_write(struct snd_emu10k1 * emu,
     131                                   unsigned int data)
     132{
     133        unsigned int reset, set;
     134        unsigned int reg, tmp;
     135        int n, result;
     136        if (emu->card_capabilities->ca0108_chip)
     137                reg = 0x3c; /* PTR20, reg 0x3c */
     138        else {
     139                /* For other chip types the SPI register
     140                 * is currently unknown. */
     141                return 1;
     142        }
     143        if (data > 0xffff) /* Only 16bit values allowed */
     144                return 1;
     145
     146        tmp = snd_emu10k1_ptr20_read(emu, reg, 0);
     147        reset = (tmp & ~0x3ffff) | 0x20000; /* Set xxx20000 */
     148        set = reset | 0x10000; /* Set xxx1xxxx */
     149        snd_emu10k1_ptr20_write(emu, reg, 0, reset | data);
     150        tmp = snd_emu10k1_ptr20_read(emu, reg, 0); /* write post */
     151        snd_emu10k1_ptr20_write(emu, reg, 0, set | data);
     152        result = 1;
     153        /* Wait for status bit to return to 0 */
     154        for (n = 0; n < 100; n++) {
     155                udelay(10);
     156                tmp = snd_emu10k1_ptr20_read(emu, reg, 0);
     157                if (!(tmp & 0x10000)) {
     158                        result = 0;
     159                        break;
     160                }
     161        }
     162        if (result) /* Timed out */
     163                return 1;
     164        snd_emu10k1_ptr20_write(emu, reg, 0, reset | data);
     165        tmp = snd_emu10k1_ptr20_read(emu, reg, 0); /* Write post */
     166        return 0;
     167}
     168
     169int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, int reg, int value)
     170{
     171        if (reg < 0 || reg > 0x3f)
     172                return 1;
     173        reg += 0x40; /* 0x40 upwards are registers. */
     174        if (value < 0 || value > 0x3f) /* 0 to 0x3f are values */
     175                return 1;
     176        outl(reg, emu->port + A_IOCFG);
     177        udelay(10);
     178        outl(reg | 0x80, emu->port + A_IOCFG);  /* High bit clocks the value into the fpga. */
     179        udelay(10);
     180        outl(value, emu->port + A_IOCFG);
     181        udelay(10);
     182        outl(value | 0x80 , emu->port + A_IOCFG);  /* High bit clocks the value into the fpga. */
     183
     184        return 0;
     185}
     186
     187int snd_emu1010_fpga_read(struct snd_emu10k1 * emu, int reg, int *value)
     188{
     189        if (reg < 0 || reg > 0x3f)
     190                return 1;
     191        reg += 0x40; /* 0x40 upwards are registers. */
     192        outl(reg, emu->port + A_IOCFG);
     193        udelay(10);
     194        outl(reg | 0x80, emu->port + A_IOCFG);  /* High bit clocks the value into the fpga. */
     195        udelay(10);
     196        *value = ((inl(emu->port + A_IOCFG) >> 8) & 0x7f);
     197
     198        return 0;
     199}
     200
     201/* Each Destination has one and only one Source,
     202 * but one Source can feed any number of Destinations simultaneously.
     203 */
     204int snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 * emu, int dst, int src)
     205{
     206        snd_emu1010_fpga_write(emu, 0x00, ((dst >> 8) & 0x3f) );
     207        snd_emu1010_fpga_write(emu, 0x01, (dst & 0x3f) );
     208        snd_emu1010_fpga_write(emu, 0x02, ((src >> 8) & 0x3f) );
     209        snd_emu1010_fpga_write(emu, 0x03, (src & 0x3f) );
     210
     211        return 0;
    125212}
    126213
     
    320407}
    321408
    322 unsigned short snd_emu10k1_ac97_read(ac97_t *ac97, unsigned short reg)
     409unsigned short snd_emu10k1_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
    323410{
    324411    struct snd_emu10k1 *emu = ac97->private_data;
     
    333420}
    334421
    335 void snd_emu10k1_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short data)
     422void snd_emu10k1_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short data)
    336423{
    337424    struct snd_emu10k1 *emu = ac97->private_data;
     
    403490        return 0;               /* Should never reach this point */
    404491}
    405 
    406 /*
    407  *  Returns an attenuation based upon a cumulative volume value
    408  *  Algorithm calculates 0x200 - 0x10 log2 (input)
    409  */
    410 
    411 unsigned char snd_emu10k1_sum_vol_attn(unsigned int value)
    412 {
    413         unsigned short count = 16, ans;
    414 
    415         if (value == 0)
    416                 return 0xFF;
    417 
    418         /* Find first SET bit. This is the integer part of the value */
    419         while ((value & 0x10000) == 0) {
    420                 value <<= 1;
    421                 count--;
    422         }
    423 
    424         /* The REST of the data is the fractional part. */
    425         ans = (unsigned short) (0x110 - ((count << 4) + ((value & 0x0FFFFL) >> 12)));
    426         if (ans > 0xFF)
    427                 ans = 0xFF;
    428 
    429         return (unsigned char) ans;
    430 }
  • GPL/trunk/alsa-kernel/pci/emu10k1/irq.c

    r34 r84  
    3232#include <sound/emu10k1.h>
    3333
    34 irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     34irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
    3535{
    3636    struct snd_emu10k1 *emu = dev_id;
    3737    unsigned int status, status2, orig_status, orig_status2;
    3838    int handled = 0;
    39 #ifdef TARGET_OS2
    40     int fOurIrq = FALSE;
    41 #endif
    4239
    4340    while ((status = inl(emu->port + IPR)) != 0) {
    44         // printk("irq - status = 0x%x\n", status);
    45 #ifdef TARGET_OS2
    46 #if 1
    47         if (status & (IPR_CHANNELNUMBERMASK|IPR_A_MIDITRANSBUFEMPTY2|IPR_A_MIDIRECVBUFEMPTY2|
    48                       IPR_SAMPLERATETRACKER|IPR_FXDSP|IPR_FORCEINT|IPR_PCIERROR|IPR_VOLINCR|
    49                       IPR_VOLDECR|IPR_MUTE|IPR_MICBUFFULL|IPR_MICBUFHALFFULL|IPR_ADCBUFFULL|
    50                       IPR_ADCBUFHALFFULL|IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL|IPR_GPSPDIFSTATUSCHANGE|
    51                       IPR_CDROMSTATUSCHANGE|IPR_INTERVALTIMER|IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY|
    52                       IPR_CHANNELLOOP))
    53 #else
    54             if (status)
    55 #endif
    56             {
    57                 fOurIrq = TRUE;
    58             }
    59 #endif
     41        //snd_printk(KERN_INFO "emu10k1 irq - status = 0x%x\n", status);
    6042        orig_status = status;
    6143        handled = 1;
     44        if ((status & 0xffffffff) == 0xffffffff) {
     45            snd_printk(KERN_INFO "snd-emu10k1: Suspected sound card removal\n");
     46            break;
     47        }
    6248        if (status & IPR_PCIERROR) {
    63             //                  snd_printk("interrupt: PCI error\n");
     49            snd_printk("interrupt: PCI error\n");
    6450            snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
    6551            status &= ~IPR_PCIERROR;
  • GPL/trunk/alsa-kernel/pci/emu10k1/memory.c

    r34 r84  
    6565            /* do not increment ptr */
    6666            __set_ptb_entry(emu, page, emu->silent_page.addr);
    67 //              __set_ptb_entry(emu, page, emu->silent_page_dmaaddr);
    6867}
    6968#endif /* PAGE_SIZE */
     
    290289 * page allocation for DMA
    291290 */
    292 snd_util_memblk_t *
    293 snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, snd_pcm_substream_t *substream)
    294 {
    295     snd_pcm_runtime_t *runtime = substream->runtime;
     291struct snd_util_memblk *
     292snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream)
     293{
     294    struct snd_pcm_runtime *runtime = substream->runtime;
    296295    struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
    297     snd_util_memhdr_t *hdr;
     296    struct snd_util_memhdr *hdr;
    298297    struct snd_emu10k1_memblk *blk;
    299298    int page, err, idx;
     
    338337    err = snd_emu10k1_memblk_map(emu, blk);
    339338    if (err < 0) {
    340         __snd_util_mem_free(hdr, (snd_util_memblk_t *)blk);
     339        __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk);
    341340        up(&hdr->block_mutex);
    342341        return NULL;
    343342    }
    344343    up(&hdr->block_mutex);
    345     return (snd_util_memblk_t *)blk;
     344    return (struct snd_util_memblk *)blk;
    346345}
    347346
     
    350349 * release DMA buffer from page table
    351350 */
    352 int snd_emu10k1_free_pages(struct snd_emu10k1 *emu, snd_util_memblk_t *blk)
     351int snd_emu10k1_free_pages(struct snd_emu10k1 *emu, struct snd_util_memblk *blk)
    353352{
    354353        snd_assert(emu && blk, return -EINVAL);
     
    365364 * allocate a synth sample area
    366365 */
    367 snd_util_memblk_t *
     366struct snd_util_memblk *
    368367snd_emu10k1_synth_alloc(struct snd_emu10k1 *hw, unsigned int size)
    369368{
    370         struct snd_emu10k1_memblk *blk;
    371         snd_util_memhdr_t *hdr = hw->memhdr;
     369    struct snd_emu10k1_memblk *blk;
     370    struct snd_util_memhdr *hdr = hw->memhdr;
    372371
    373372        down(&hdr->block_mutex);
     
    377376                return NULL;
    378377        }
    379         if (synth_alloc_pages(hw, blk)) {
    380                 __snd_util_mem_free(hdr, (snd_util_memblk_t *)blk);
     378        if (synth_alloc_pages(hw, blk)) {
     379            __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk);
    381380                up(&hdr->block_mutex);
    382381                return NULL;
     
    384383        snd_emu10k1_memblk_map(hw, blk);
    385384        up(&hdr->block_mutex);
    386         return (snd_util_memblk_t *)blk;
     385        return (struct snd_util_memblk *)blk;
    387386}
    388387
  • 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
  • GPL/trunk/alsa-kernel/pci/emu10k1/voice.c

    r34 r84  
    4747 */
    4848
    49 static int voice_alloc(struct snd_emu10k1 *emu, int type, int number, struct snd_emu10k1_voice **rvoice)
     49static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
     50                       struct snd_emu10k1_voice **rvoice)
    5051{
    5152    struct snd_emu10k1_voice *voice;
     
    6364        }
    6465
    65         /* make sure the block of voices does not cross the 32 voice boundary */
    66         //if (((i % 32) + number) > 32)
    67         //      continue;
    68 
    6966        skip = 0;
    7067        for (k = 0; k < number; k++) {
     
    7269            if (voice->use) {
    7370                skip = 1;
     71                break;
    7472            }
    7573        }
  • GPL/trunk/alsa-kernel/pci/hda/hda_intel.c

    r77 r84  
    10401040        runtime->hw.channels_max = hinfo->channels_max;
    10411041        runtime->hw.formats = hinfo->formats;
    1042         runtime->hw.rates = hinfo->rates;
     1042        runtime->hw.rates = hinfo->rates;
     1043        printk("azx hw rates: %x. ratemin: %i, ratemax: %i\n",
     1044               runtime->hw.rates, runtime->hw.rate_min, runtime->hw.rate_max);
    10431045        snd_pcm_limit_hw_rates(runtime);
    10441046        snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  • GPL/trunk/alsa-kernel/pci/trident/trident_main.c

    r34 r84  
    3333#include <sound/control.h>
    3434#include <sound/trident.h>
    35 
    36 static inline snd_ctl_elem_id_t *snd_ctl_build_ioff(snd_ctl_elem_id_t *dst_id,
    37                                                     snd_kcontrol_t *src_kctl,
    38                                                     unsigned int offset)
    39 {
    40         *dst_id = src_kctl->id;
    41         dst_id->index += offset;
    42         dst_id->numid += offset;
    43         return dst_id;
    44 }
    4535
    4636static int snd_trident_pcm_mixer_build(struct snd_trident *trident, struct snd_trident_voice* voice, snd_pcm_substream_t *substream);
  • GPL/trunk/alsa-kernel/pci/ymfpci/ymfpci_main.c

    r83 r84  
    17921792        return err;
    17931793
     1794    /* to be sure */
     1795    snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS,
     1796                         AC97_EA_VRA|AC97_EA_VRM, 0);
    17941797
    17951798    for (idx = 0; idx < ARRAY_SIZE(snd_ymfpci_controls); idx++) {
  • GPL/trunk/drv32/dispatch.c

    r32 r84  
    9595    ULONG ctl_id;
    9696
     97#ifdef DEBUG
     98    printk("StratIOCtl\n");
     99#endif
    97100    if (rp->Category != CAT_IOCTL_OSS32)
    98101    {
  • GPL/trunk/drv32/init.c

    r63 r84  
    283283        WriteString(szEOL, sizeof(szEOL)-1);
    284284    }
    285 
     285#ifdef DEBUG
     286    dprintf(("DiscardableInit. cp1"));
     287#endif
    286288    // Complete the installation
    287289    rp->Out.FinalCS = _OffsetFinalCS16;
    288290    rp->Out.FinalDS = _OffsetFinalDS16;
     291#ifdef DEBUG
     292    dprintf(("DiscardableInit. cp2"));
     293#endif
    289294
    290295//    SaveBuffer();
  • GPL/trunk/drv32/strategy.c

    r32 r84  
    7070    RPInit __far* rp = (RPInit __far*)_rp;
    7171    rc = DiscardableInit(rp);
    72 
     72#ifdef DEBUG
     73    dprintf(("StratInit. cp1.rc %d", rc));
     74#endif
    7375    return rc;
    7476}
     
    8082#pragma on (unreferenced)
    8183{
     84#ifdef DEBUG
     85    dprintf(("StratInitComplete"));
     86#endif
    8287  return(RPDONE);
    8388}
     
    9095 RPShutdown __far *rp = (RPShutdown __far *)_rp;
    9196
    92   dprintf(("StratShutdown %d", rp->Function));
     97#ifdef DEBUG
     98 dprintf(("StratShutdown %d", rp->Function));
     99#endif
    93100  if(rp->Function == 1) {//end of shutdown
    94101        OSS32_Shutdown();
  • GPL/trunk/include/ossdefos2.h

    r32 r84  
    8686#define OSS_MIXER_3DDEPTH       25   
    8787#define OSS_MIXER_3DCENTER      26
    88 #define OSS_MIXER_NRDEVICES     27
     88#define OSS_MIXER_FRONT         27
     89#define OSS_MIXER_NRDEVICES     28
    8990
    9091#endif
  • GPL/trunk/include/version.mak

    r83 r84  
    1111BLDLVL_REVISION = 1.1
    1212BLDLVL_FILEVER = 4
    13 BLDLVL_DATETIME = 25.09.2006 22:56:59
     13BLDLVL_DATETIME = 23.10.2006 23:58:13
    1414BLDLVL_MACHINE = VLAD
  • GPL/trunk/lib32/irq.c

    r76 r84  
    176176
    177177#ifdef DEBUG
    178     dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
     178//    dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
    179179#endif
    180180
     
    213213                    OSS32_ProcessIRQ();
    214214#ifdef DEBUG
    215                     dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
     215//                    dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
    216216#endif
    217217                    eoiIrq[pSlot->irqNo] = 0;
     
    222222    }
    223223#ifdef DEBUG
    224                     dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
     224//                    dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
    225225#endif
    226226
  • GPL/trunk/lib32/ossidc.cpp

    r76 r84  
    283283
    284284    if(nrCardsDetected != 0) {
     285        dprintf(("OSS32_Initialize2"));
    285286        pcm_info();
     287        dprintf(("OSS32_Initialize3"));
    286288        for(int i=0;i<nrCardsDetected;i++) {
     289            dprintf(("OSS32_Initialize4 start: %d",i));
    287290            FillCaps(i);
     291            dprintf(("OSS32_Initialize4 end: %d",i));
    288292        }
     293        dprintf(("OSS32_Initialize: SUCCESS. nr. of cards: %d",nrCardsDetected));
    289294        return OSSERR_SUCCESS;
    290295    }
     296    dprintf(("OSS32_Initialize. FAILED"));
    291297    return OSSERR_INIT_FAILED;
    292298}
  • GPL/trunk/lib32/sound.c

    r82 r84  
    754754    soundhandle        *pHandle = (soundhandle *)streamid;
    755755    snd_pcm_hw_params_t params;
     756    snd_pcm_status_t    status;
    756757    snd_pcm_sw_params_t swparams;
    757758    int                 ret, ret1, nrperiods, minnrperiods, maxnrperiods, samplesize, i;
     
    889890            }
    890891        }
     892
    891893//        ret1 = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
    892894        DebugInt3();
     
    10401042    total = 0;
    10411043    per_bytes = periodbytes;
     1044    ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_STATUS, (ULONG)__Stack32ToFlat(&status));
     1045    if ( ((status.state != SNDRV_PCM_STATE_PREPARED) &&
     1046          (status.state != SNDRV_PCM_STATE_RUNNING) &&
     1047          (status.state != SNDRV_PCM_STATE_DRAINING))) {
     1048        printk("Device is not in proper state: %i. Calling prepare\n", status.state);
     1049        ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_PREPARE, 0);
     1050    }
    10421051    printk("OSS32_WaveSetHwParams return %d after SNDRV_PCM_IOCTL_SW_PARAMS ioctl, streamid %X", ret,(ULONG)pHandle);
    10431052    return UNIXToOSSError(ret);
     
    11331142                    printk("OSS32_WaveAddBuffer failed on partial transfer %x %i; ret = %i\n", buffer, size, ret);
    11341143                    *pTransferred = transferred;
    1135                     return OSSERR_SUCCESS;
     1144                    if (toret)
     1145                        return OSSERR_SUCCESS; /* avoid infinite loop */
     1146                    toret = 1;
     1147                    goto again;
    11361148                }
    11371149
     
    11431155                    ret1 = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_PCM_IOCTL_PREPARE, 0);
    11441156                    printk("OSS32_WaveAddBuffer buffer overrun: size %i, ret %i, trans %i, prev sz %i per sz %i total %i\n", size, ret, transferred, prev_size, per_bytes, total);
    1145                     ret = size;
    1146                     transferred = size;
    1147                     break; /* UGLY hack*/
    1148                     //goto again;
     1157                    //ret = size;
     1158                    //transferred = size;
     1159                    if (toret) break; /* avoid infinite loop */
     1160                    toret = 1;
     1161                    goto again;
    11491162                }
    11501163                else {
     
    11621175                break;
    11631176            }
     1177            toret = 0;
    11641178            transferred += ret;
    11651179//            printk("written: now: %i, buffer: %i, total: %i\n", ret, transferred, total);
  • GPL/trunk/lib32/soundmixer.c

    r32 r84  
    7272        /* OSS_MIXER_3DDEPTH  */ { "3D Control - Depth", 0 , -1},
    7373        /* OSS_MIXER_3DCENTER */ { "3D Control - Center", 0 , -1},
     74        /* OSS_MIXER_FRONT    */ { "Front", 0 , -1},
    7475};
    7576char *szRecSources[OSS32_MIX_RECSRC_MAX] = {
     
    201202                int controlnamelen = strlen(pHandle->pids[i].name);
    202203
    203                 if(namelen == controlnamelen) 
     204                if(namelen == controlnamelen)
    204205                {//control names are identical; found exact match
    205206                    pHandle->controls[j].idxVolume = i;
     
    392393        idx = pHandle->controls[OSS_MIXER_VOLUME].idxVolume;
    393394        idxMute = pHandle->controls[OSS_MIXER_VOLUME].idxMute;
     395        if (idx == -1)
     396        {
     397            /* HDA codecs workaround */
     398            idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
     399            idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
     400        }
    394401        break;
    395402    case OSS32_MIX_VOLUME_MASTER_REAR: //TODO:
     
    400407        idx = pHandle->controls[OSS_MIXER_PCM].idxVolume;
    401408        idxMute = pHandle->controls[OSS_MIXER_PCM].idxMute;
     409        if (idx == -1)
     410        {
     411            /* HDA codecs workaround */
     412            idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
     413            idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
     414        }
    402415        break;
    403416    case OSS32_MIX_VOLUME_MIDI:
  • GPL/trunk/lib32/stack.cpp

    r76 r84  
    3333#endif
    3434
    35 #define MAX_STACK               8
     35#define MAX_STACK               16
    3636#define STACKSIZE               (16*1024)
    3737#define TOTAL_STACKSIZE     MAX_STACK*(16*1024)
Note: See TracChangeset for help on using the changeset viewer.