Ignore:
Timestamp:
Aug 22, 2007, 5:33:25 AM (18 years ago)
Author:
Brendan Oakley
Message:

Merged to ALSA 0.9.3

Location:
GPL/branches/alsa-resync1/alsa-kernel/pci
Files:
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ak4xxx.c

    r244 r246  
    3030#include "ice1712.h"
    3131
     32static void snd_ice1712_akm4xxx_lock(akm4xxx_t *ak, int chip)
     33{
     34        ice1712_t *ice = ak->private_data[0];
     35
     36        snd_ice1712_save_gpio_status(ice);
     37}
     38
     39static void snd_ice1712_akm4xxx_unlock(akm4xxx_t *ak, int chip)
     40{
     41        ice1712_t *ice = ak->private_data[0];
     42
     43        snd_ice1712_restore_gpio_status(ice);
     44}
    3245
    3346/*
    3447 * write AK4xxx register
    3548 */
    36 void snd_ice1712_akm4xxx_write(akm4xxx_t *ak, int chip,
    37                               unsigned char addr, unsigned char data)
     49static void snd_ice1712_akm4xxx_write(akm4xxx_t *ak, int chip,
     50                                      unsigned char addr, unsigned char data)
    3851{
    3952        unsigned int tmp;
    4053        int idx;
    4154        unsigned int addrdata;
    42         ice1712_t *ice = ak->chip;
     55        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     56        ice1712_t *ice = ak->private_data[0];
    4357
    4458        snd_assert(chip >= 0 && chip < 4, return);
    4559
    46         if (ak->ops.start) {
    47                 if (ak->ops.start(ak, chip) < 0)
    48                         return;
    49         } else
    50                 snd_ice1712_save_gpio_status(ice);
    51 
    5260        tmp = snd_ice1712_gpio_read(ice);
    53         tmp |= ak->add_flags;
    54         tmp &= ~ak->mask_flags;
    55         if (ak->cs_mask == ak->cs_addr) {
    56                 if (ak->cif) {
    57                         tmp |= ak->cs_mask; /* start without chip select */
     61        tmp |= priv->add_flags;
     62        tmp &= ~priv->mask_flags;
     63        if (priv->cs_mask == priv->cs_addr) {
     64                if (priv->cif) {
     65                        tmp |= priv->cs_mask; /* start without chip select */
    5866                }  else {
    59                         tmp &= ~ak->cs_mask; /* chip select low */
     67                        tmp &= ~priv->cs_mask; /* chip select low */
    6068                        snd_ice1712_gpio_write(ice, tmp);
    6169                        udelay(1);
     
    6371        } else {
    6472                /* doesn't handle cf=1 yet */
    65                 tmp &= ~ak->cs_mask;
    66                 tmp |= ak->cs_addr;
     73                tmp &= ~priv->cs_mask;
     74                tmp |= priv->cs_addr;
    6775                snd_ice1712_gpio_write(ice, tmp);
    6876                udelay(1);
     
    7078
    7179        /* build I2C address + data byte */
    72         addrdata = (ak->caddr << 6) | 0x20 | (addr & 0x1f);
     80        addrdata = (priv->caddr << 6) | 0x20 | (addr & 0x1f);
    7381        addrdata = (addrdata << 8) | data;
    7482        for (idx = 15; idx >= 0; idx--) {
    7583                /* drop clock */
    76                 tmp &= ~ak->clk_mask;
     84                tmp &= ~priv->clk_mask;
    7785                snd_ice1712_gpio_write(ice, tmp);
    7886                udelay(1);
    7987                /* set data */
    8088                if (addrdata & (1 << idx))
    81                         tmp |= ak->data_mask;
     89                        tmp |= priv->data_mask;
    8290                else
    83                         tmp &= ~ak->data_mask;
     91                        tmp &= ~priv->data_mask;
    8492                snd_ice1712_gpio_write(ice, tmp);
    8593                udelay(1);
    8694                /* raise clock */
    87                 tmp |= ak->clk_mask;
     95                tmp |= priv->clk_mask;
    8896                snd_ice1712_gpio_write(ice, tmp);
    8997                udelay(1);
     
    101109        }
    102110       
    103         if (ak->cs_mask == ak->cs_addr) {
    104                 if (ak->cif) {
     111        if (priv->cs_mask == priv->cs_addr) {
     112                if (priv->cif) {
    105113                        /* assert a cs pulse to trigger */
    106                         tmp &= ~ak->cs_mask;
     114                        tmp &= ~priv->cs_mask;
    107115                        snd_ice1712_gpio_write(ice, tmp);
    108116                        udelay(1);
    109117                }
    110                 tmp |= ak->cs_mask; /* chip select high to trigger */
     118                tmp |= priv->cs_mask; /* chip select high to trigger */
    111119        } else {
    112                 tmp &= ~ak->cs_mask;
    113                 tmp |= ak->cs_none; /* deselect address */
     120                tmp &= ~priv->cs_mask;
     121                tmp |= priv->cs_none; /* deselect address */
    114122        }
    115123        snd_ice1712_gpio_write(ice, tmp);
    116124        udelay(1);
    117 
    118         if (ak->ops.stop)
    119                 ak->ops.stop(ak);
    120         else
    121                 snd_ice1712_restore_gpio_status(ice);
    122125}
    123 
    124 /*
    125  * reset the AKM codecs
    126  * @state: 1 = reset codec, 0 = restore the registers
    127  *
    128  * assert the reset operation and restores the register values to the chips.
    129  */
    130 void snd_ice1712_akm4xxx_reset(akm4xxx_t *ak, int state)
    131 {
    132         unsigned int chip;
    133         unsigned char reg;
    134        
    135         switch (ak->type) {
    136         case SND_AK4524:
    137         case SND_AK4528:
    138                 for (chip = 0; chip < ak->num_dacs/2; chip++) {
    139                         snd_ice1712_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
    140                         if (state)
    141                                 continue;
    142                         /* DAC volumes */
    143                         for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
    144                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->images[chip][reg]);
    145                         if (ak->type == SND_AK4528)
    146                                 continue;
    147                         /* IPGA */
    148                         for (reg = 0x04; reg < 0x06; reg++)
    149                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->ipga_gain[chip][reg-4]);
    150                 }
    151                 break;
    152         case SND_AK4529:
    153                 /* FIXME: needed for ak4529? */
    154                 break;
    155         case SND_AK4355:
    156                 snd_ice1712_akm4xxx_write(ak, 0, 0x01, state ? 0x02 : 0x01);
    157                 if (state)
    158                         return;
    159                 for (reg = 0x00; reg < 0x0a; reg++)
    160                         if (reg != 0x01)
    161                                 snd_ice1712_akm4xxx_write(ak, 0, reg, ak->images[0][reg]);
    162                 break;
    163         case SND_AK4381:
    164                 for (chip = 0; chip < ak->num_dacs/2; chip++) {
    165                         snd_ice1712_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
    166                         if (state)
    167                                 continue;
    168                         for (reg = 0x01; reg < 0x05; reg++)
    169                                 snd_ice1712_akm4xxx_write(ak, chip, reg, ak->images[chip][reg]);
    170                 }
    171                 break;
    172         }
    173 }
    174 
    175 /*
    176  * initialize all the ak4xxx chips
    177  */
    178 static void __devinit snd_ice1712_akm4xxx_init_chip(akm4xxx_t *ak)
    179 {
    180         static unsigned char inits_ak4524[] = {
    181                 0x00, 0x07, /* 0: all power up */
    182                 0x01, 0x00, /* 1: ADC/DAC reset */
    183                 0x02, 0x60, /* 2: 24bit I2S */
    184                 0x03, 0x19, /* 3: deemphasis off */
    185                 0x01, 0x03, /* 1: ADC/DAC enable */
    186                 0x04, 0x00, /* 4: ADC left muted */
    187                 0x05, 0x00, /* 5: ADC right muted */
    188                 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
    189                 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
    190                 0x06, 0x00, /* 6: DAC left muted */
    191                 0x07, 0x00, /* 7: DAC right muted */
    192                 0xff, 0xff
    193         };
    194         static unsigned char inits_ak4528[] = {
    195                 0x00, 0x07, /* 0: all power up */
    196                 0x01, 0x00, /* 1: ADC/DAC reset */
    197                 0x02, 0x60, /* 2: 24bit I2S */
    198                 0x03, 0x0d, /* 3: deemphasis off, turn LR highpass filters on */
    199                 0x01, 0x03, /* 1: ADC/DAC enable */
    200                 0x04, 0x00, /* 4: ADC left muted */
    201                 0x05, 0x00, /* 5: ADC right muted */
    202                 0xff, 0xff
    203         };
    204         static unsigned char inits_ak4529[] = {
    205                 0x09, 0x01, /* 9: ATS=0, RSTN=1 */
    206                 0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
    207                 0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
    208                 0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
    209                 0x02, 0xff, /* 2: LOUT1 muted */
    210                 0x03, 0xff, /* 3: ROUT1 muted */
    211                 0x04, 0xff, /* 4: LOUT2 muted */
    212                 0x05, 0xff, /* 5: ROUT2 muted */
    213                 0x06, 0xff, /* 6: LOUT3 muted */
    214                 0x07, 0xff, /* 7: ROUT3 muted */
    215                 0x0b, 0xff, /* B: LOUT4 muted */
    216                 0x0c, 0xff, /* C: ROUT4 muted */
    217                 0x08, 0x55, /* 8: deemphasis all off */
    218                 0xff, 0xff
    219         };
    220         static unsigned char inits_ak4355[] = {
    221                 0x01, 0x02, /* 1: reset and soft-mute */
    222                 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
    223                 // 0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
    224                 0x02, 0x2e,
    225                 0x03, 0x01, /* 3: de-emphasis off */
    226                 0x04, 0x00, /* 4: LOUT1 volume muted */
    227                 0x05, 0x00, /* 5: ROUT1 volume muted */
    228                 0x06, 0x00, /* 6: LOUT2 volume muted */
    229                 0x07, 0x00, /* 7: ROUT2 volume muted */
    230                 0x08, 0x00, /* 8: LOUT3 volume muted */
    231                 0x09, 0x00, /* 9: ROUT3 volume muted */
    232                 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
    233                 0x01, 0x01, /* 1: un-reset, unmute */
    234                 0xff, 0xff
    235         };
    236         static unsigned char inits_ak4381[] = {
    237                 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
    238                 // 0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
    239                 0x01, 0x12,
    240                 0x02, 0x00, /* 2: DZF disabled */
    241                 0x03, 0x00, /* 3: LATT 0 */
    242                 0x04, 0x00, /* 4: RATT 0 */
    243                 0x00, 0x0f, /* 0: power-up, un-reset */
    244                 0xff, 0xff
    245         };
    246 
    247         int chip, num_chips;
    248         unsigned char *ptr, reg, data, *inits;
    249 
    250         switch (ak->type) {
    251         case SND_AK4524:
    252                 inits = inits_ak4524;
    253                 num_chips = ak->num_dacs / 2;
    254                 break;
    255         case SND_AK4528:
    256                 inits = inits_ak4528;
    257                 num_chips = ak->num_dacs / 2;
    258                 break;
    259         case SND_AK4529:
    260                 inits = inits_ak4529;
    261                 num_chips = 1;
    262                 break;
    263         case SND_AK4355:
    264                 inits = inits_ak4355;
    265                 num_chips = 1;
    266                 break;
    267         case SND_AK4381:
    268                 inits = inits_ak4381;
    269                 num_chips = ak->num_dacs / 2;
    270                 break;
    271         default:
    272                 snd_BUG();
    273                 return;
    274         }
    275 
    276         for (chip = 0; chip < num_chips; chip++) {
    277                 ptr = inits;
    278                 while (*ptr != 0xff) {
    279                         reg = *ptr++;
    280                         data = *ptr++;
    281                         snd_ice1712_akm4xxx_write(ak, chip, reg, data);
    282                 }
    283         }
    284 }
    285 
    286126
    287127/*
    288128 * initialize the akm4xxx_t record with the template
    289129 */
    290 void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp, ice1712_t *ice)
     130int __devinit snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp,
     131                                       const struct snd_ak4xxx_private *_priv, ice1712_t *ice)
    291132{
     133        struct snd_ak4xxx_private *priv;
     134
     135        priv = kmalloc(sizeof(*priv), GFP_KERNEL);
     136        if (priv == NULL)
     137                return -ENOMEM;
    292138        *ak = *temp;
    293         ak->chip = ice;
    294         snd_ice1712_akm4xxx_init_chip(ak);
    295 }
    296 
    297 
    298 #define AK_GET_CHIP(val)                (((val) >> 8) & 0xff)
    299 #define AK_GET_ADDR(val)                ((val) & 0xff)
    300 #define AK_GET_SHIFT(val)               (((val) >> 16) & 0x7f)
    301 #define AK_GET_INVERT(val)              (((val) >> 23) & 1)
    302 #define AK_GET_MASK(val)                (((val) >> 24) & 0xff)
    303 #define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
    304 #define AK_INVERT                       (1<<23)
    305 
    306 static int snd_ice1712_akm4xxx_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    307 {
    308         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    309 
    310         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    311         uinfo->count = 1;
    312         uinfo->value.integer.min = 0;
    313         uinfo->value.integer.max = mask;
     139        ak->card = ice->card;
     140        *priv = *_priv;
     141        ak->private_value[0] = (unsigned long)priv;
     142        ak->private_data[0] = ice;
     143        if (ak->ops.lock == NULL)
     144                ak->ops.lock = snd_ice1712_akm4xxx_lock;
     145        if (ak->ops.unlock == NULL)
     146                ak->ops.unlock = snd_ice1712_akm4xxx_unlock;
     147        if (ak->ops.write == NULL)
     148                ak->ops.write = snd_ice1712_akm4xxx_write;
     149        snd_akm4xxx_init(ak);
    314150        return 0;
    315151}
    316152
    317 static int snd_ice1712_akm4xxx_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     153void __devexit snd_ice1712_akm4xxx_free(ice1712_t *ice)
    318154{
    319         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    320         int chip = AK_GET_CHIP(kcontrol->private_value);
    321         int addr = AK_GET_ADDR(kcontrol->private_value);
    322         int invert = AK_GET_INVERT(kcontrol->private_value);
    323         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    324         unsigned char val = ak->images[chip][addr];
    325        
    326         ucontrol->value.integer.value[0] = invert ? mask - val : val;
    327         return 0;
    328 }
    329 
    330 static int snd_ice1712_akm4xxx_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    331 {
    332         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    333         int chip = AK_GET_CHIP(kcontrol->private_value);
    334         int addr = AK_GET_ADDR(kcontrol->private_value);
    335         int invert = AK_GET_INVERT(kcontrol->private_value);
    336         unsigned int mask = AK_GET_MASK(kcontrol->private_value);
    337         unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
    338         int change;
    339 
    340         if (invert)
    341                 nval = mask - nval;
    342         change = ak->images[chip][addr] != nval;
    343         if (change)
    344                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    345         return change;
    346 }
    347 
    348 static int snd_ice1712_akm4xxx_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    349 {
    350         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    351         uinfo->count = 1;
    352         uinfo->value.integer.min = 0;
    353         uinfo->value.integer.max = 36;
    354         return 0;
    355 }
    356 
    357 static int snd_ice1712_akm4xxx_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    358 {
    359         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    360         int chip = AK_GET_CHIP(kcontrol->private_value);
    361         int addr = AK_GET_ADDR(kcontrol->private_value);
    362         ucontrol->value.integer.value[0] = ak->ipga_gain[chip][addr-4] & 0x7f;
    363         return 0;
    364 }
    365 
    366 static int snd_ice1712_akm4xxx_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    367 {
    368         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    369         int chip = AK_GET_CHIP(kcontrol->private_value);
    370         int addr = AK_GET_ADDR(kcontrol->private_value);
    371         unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
    372         int change = ak->ipga_gain[chip][addr] != nval;
    373         if (change)
    374                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    375         return change;
    376 }
    377 
    378 static int snd_ice1712_akm4xxx_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
    379 {
    380         static char *texts[4] = {
    381                 "44.1kHz", "Off", "48kHz", "32kHz",
    382         };
    383         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    384         uinfo->count = 1;
    385         uinfo->value.enumerated.items = 4;
    386         if (uinfo->value.enumerated.item >= 4)
    387                 uinfo->value.enumerated.item = 3;
    388         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    389         return 0;
    390 }
    391 
    392 static int snd_ice1712_akm4xxx_deemphasis_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
    393 {
    394         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    395         int chip = AK_GET_CHIP(kcontrol->private_value);
    396         int addr = AK_GET_ADDR(kcontrol->private_value);
    397         int shift = AK_GET_SHIFT(kcontrol->private_value);
    398         ucontrol->value.enumerated.item[0] = (ak->images[chip][addr] >> shift) & 3;
    399         return 0;
    400 }
    401 
    402 static int snd_ice1712_akm4xxx_deemphasis_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    403 {
    404         akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    405         int chip = AK_GET_CHIP(kcontrol->private_value);
    406         int addr = AK_GET_ADDR(kcontrol->private_value);
    407         int shift = AK_GET_SHIFT(kcontrol->private_value);
    408         unsigned char nval = ucontrol->value.enumerated.item[0] & 3;
    409         int change;
    410        
    411         nval = (nval << shift) | (ak->images[chip][addr] & ~(3 << shift));
    412         change = ak->images[chip][addr] != nval;
    413         if (change)
    414                 snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    415         return change;
     155        unsigned int akidx;
     156        if (ice->akm == NULL)
     157                return;
     158        for (akidx = 0; akidx < ice->akm_codecs; akidx++) {
     159                akm4xxx_t *ak = &ice->akm[akidx];
     160                if (ak->private_value[0])
     161                        kfree((void *)ak->private_value[0]);
     162        }
     163        kfree(ice->akm);
    416164}
    417165
    418166/*
    419  * build AK4524 controls
     167 * build AK4xxx controls
    420168 */
    421 
    422169int __devinit snd_ice1712_akm4xxx_build_controls(ice1712_t *ice)
    423170{
    424         unsigned int idx;
     171        unsigned int akidx;
    425172        int err;
    426         unsigned int akidx;
    427173
    428174        for (akidx = 0; akidx < ice->akm_codecs; akidx++) {
    429175                akm4xxx_t *ak = &ice->akm[akidx];
    430                 for (idx = 0; idx < ak->num_dacs; ++idx) {
    431                         snd_kcontrol_t ctl;
    432                         memset(&ctl, 0, sizeof(ctl));
    433                         strcpy(ctl.id.name, "DAC Volume");
    434                         ctl.id.index = idx + ak->idx_offset * 2;
    435                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    436                         ctl.info = snd_ice1712_akm4xxx_volume_info;
    437                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    438                         ctl.get = snd_ice1712_akm4xxx_volume_get;
    439                         ctl.put = snd_ice1712_akm4xxx_volume_put;
    440                         switch (ak->type) {
    441                         case SND_AK4524:
    442                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
    443                                 break;
    444                         case SND_AK4528:
    445                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
    446                                 break;
    447                         case SND_AK4529: {
    448                                 int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
    449                                 ctl.private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
    450                                 break;
    451                         }
    452                         case SND_AK4355:
    453                                 ctl.private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
    454                                 break;
    455                         case SND_AK4381:
    456                                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
    457                                 break;
    458                         default:
    459                                 return -EINVAL;
    460                         }
    461                         ctl.private_data = ak;
    462                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    463                                 return err;
    464                 }
    465                 for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
    466                         snd_kcontrol_t ctl;
    467                         memset(&ctl, 0, sizeof(ctl));
    468                         strcpy(ctl.id.name, "ADC Volume");
    469                         ctl.id.index = idx;
    470                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    471                         ctl.info = snd_ice1712_akm4xxx_volume_info;
    472                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    473                         ctl.get = snd_ice1712_akm4xxx_volume_get;
    474                         ctl.put = snd_ice1712_akm4xxx_volume_put;
    475                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
    476                         ctl.private_data = ak;
    477                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    478                                 return err;
    479                         memset(&ctl, 0, sizeof(ctl));
    480                         strcpy(ctl.id.name, "IPGA Analog Capture Volume");
    481                         ctl.id.index = idx;
    482                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    483                         ctl.info = snd_ice1712_akm4xxx_ipga_gain_info;
    484                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    485                         ctl.get = snd_ice1712_akm4xxx_ipga_gain_get;
    486                         ctl.put = snd_ice1712_akm4xxx_ipga_gain_put;
    487                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
    488                         ctl.private_data = ak;
    489                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    490                                 return err;
    491                 }
    492                 for (idx = 0; idx < ak->num_dacs/2; idx++) {
    493                         snd_kcontrol_t ctl;
    494                         memset(&ctl, 0, sizeof(ctl));
    495                         strcpy(ctl.id.name, "Deemphasis");
    496                         ctl.id.index = idx + ak->idx_offset;
    497                         ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    498                         ctl.info = snd_ice1712_akm4xxx_deemphasis_info;
    499                         ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    500                         ctl.get = snd_ice1712_akm4xxx_deemphasis_get;
    501                         ctl.put = snd_ice1712_akm4xxx_deemphasis_put;
    502                         switch (ak->type) {
    503                         case SND_AK4524:
    504                         case SND_AK4528:
    505                                 ctl.private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
    506                                 break;
    507                         case SND_AK4529: {
    508                                 int shift = idx == 3 ? 6 : (2 - idx) * 2;
    509                                 ctl.private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
    510                                 break;
    511                         }
    512                         case SND_AK4355:
    513                                 ctl.private_value = AK_COMPOSE(idx, 3, 0, 0);
    514                                 break;
    515                         case SND_AK4381:
    516                                 ctl.private_value = AK_COMPOSE(idx, 1, 1, 0);
    517                                 break;
    518                         }
    519                         ctl.private_data = ak;
    520                         if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    521                                 return err;
    522                 }
     176                err = snd_akm4xxx_build_controls(ak);
     177                if (err < 0)
     178                        return err;
    523179        }
    524180        return 0;
    525181}
    526 
    527 
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/delta.c

    r224 r246  
    233233 * AK4524 on Delta 44 and 66 to choose the chip mask
    234234 */
    235 static int delta_ak4524_start(akm4xxx_t *ak, int chip)
    236 {
    237         snd_ice1712_save_gpio_status(ak->chip);
    238         ak->cs_mask =
    239         ak->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
    240                                   ICE1712_DELTA_CODEC_CHIP_B;
    241         return 0;
     235static void delta_ak4524_lock(akm4xxx_t *ak, int chip)
     236{
     237        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     238        ice1712_t *ice = ak->private_data[0];
     239
     240        snd_ice1712_save_gpio_status(ice);
     241        priv->cs_mask =
     242        priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
     243                                    ICE1712_DELTA_CODEC_CHIP_B;
    242244}
    243245
     
    245247 * AK4524 on Delta1010LT to choose the chip address
    246248 */
    247 static int delta1010lt_ak4524_start(akm4xxx_t *ak, int chip)
    248 {
    249         snd_ice1712_save_gpio_status(ak->chip);
    250         ak->cs_mask = ICE1712_DELTA_1010LT_CS;
    251         ak->cs_addr = chip << 4;
    252         return 0;
     249static void delta1010lt_ak4524_lock(akm4xxx_t *ak, int chip)
     250{
     251        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     252        ice1712_t *ice = ak->private_data[0];
     253
     254        snd_ice1712_save_gpio_status(ice);
     255        priv->cs_mask = ICE1712_DELTA_1010LT_CS;
     256        priv->cs_addr = chip << 4;
    253257}
    254258
     
    259263{
    260264        unsigned char tmp, tmp2;
    261         ice1712_t *ice = ak->chip;
     265        ice1712_t *ice = ak->private_data[0];
    262266
    263267        if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
     
    276280
    277281        /* do it again */
    278         snd_ice1712_akm4xxx_reset(ak, 1);
     282        snd_akm4xxx_reset(ak, 1);
    279283        down(&ice->gpio_mutex);
    280284        tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
     
    283287        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    284288        up(&ice->gpio_mutex);
    285         snd_ice1712_akm4xxx_reset(ak, 0);
     289        snd_akm4xxx_reset(ak, 0);
    286290}
    287291
     
    331335        .num_adcs = 2,
    332336        .num_dacs = 2,
     337        .ops = {
     338                .set_rate_val = delta_ak4524_set_rate_val
     339        }
     340};
     341
     342static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = {
    333343        .caddr = 2,
    334344        .cif = 0,
     
    340350        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
    341351        .mask_flags = 0,
    342         .ops = {
    343                 .set_rate_val = delta_ak4524_set_rate_val
    344         }
    345352};
    346353
     
    349356        .num_adcs = 2,
    350357        .num_dacs = 8,
     358        .ops = {
     359                .set_rate_val = delta_ak4524_set_rate_val
     360        }
     361};
     362
     363static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = {
    351364        .caddr = 0,
    352365        .cif = 0,
     
    358371        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
    359372        .mask_flags = 0,
    360         .ops = {
    361                 .set_rate_val = delta_ak4524_set_rate_val
    362         }
    363373};
    364374
     
    367377        .num_adcs = 8,
    368378        .num_dacs = 8,
     379        .ops = {
     380                .lock = delta1010lt_ak4524_lock,
     381                .set_rate_val = delta_ak4524_set_rate_val
     382        }
     383};
     384
     385static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
    369386        .caddr = 2,
    370387        .cif = 0, /* the default level of the CIF pin from AK4524 */
     
    376393        .add_flags = 0,
    377394        .mask_flags = 0,
    378         .ops = {
    379                 .start = delta1010lt_ak4524_start,
    380                 .set_rate_val = delta_ak4524_set_rate_val
    381         }
    382395};
    383396
     
    386399        .num_adcs = 4,
    387400        .num_dacs = 4,
     401        .ops = {
     402                .lock = delta_ak4524_lock,
     403                .set_rate_val = delta_ak4524_set_rate_val
     404        }
     405};
     406
     407static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = {
    388408        .caddr = 2,
    389409        .cif = 0, /* the default level of the CIF pin from AK4524 */
     
    395415        .add_flags = 0,
    396416        .mask_flags = 0,
    397         .ops = {
    398                 .start = delta_ak4524_start,
    399                 .set_rate_val = delta_ak4524_set_rate_val
    400         }
    401417};
    402418
     
    467483        switch (ice->eeprom.subvendor) {
    468484        case ICE1712_SUBDEVICE_AUDIOPHILE:
    469                 snd_ice1712_akm4xxx_init(ak, &akm_audiophile, ice);
     485                err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
    470486                break;
    471487        case ICE1712_SUBDEVICE_DELTA410:
    472                 snd_ice1712_akm4xxx_init(ak, &akm_delta410, ice);
     488                err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
    473489                break;
    474490        case ICE1712_SUBDEVICE_DELTA1010LT:
    475                 snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, ice);
     491                err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
    476492                break;
    477493        case ICE1712_SUBDEVICE_DELTA66:
    478494        case ICE1712_SUBDEVICE_DELTA44:
    479                 snd_ice1712_akm4xxx_init(ak, &akm_delta44, ice);
     495                err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
    480496                break;
    481497        default:
     
    484500        }
    485501
    486         return 0;
     502        return err;
    487503}
    488504
     
    535551        case ICE1712_SUBDEVICE_DELTADIO2496:
    536552        case ICE1712_SUBDEVICE_DELTA66:
    537         case ICE1712_SUBDEVICE_AUDIOPHILE:
    538         case ICE1712_SUBDEVICE_DELTA410:
    539         case ICE1712_SUBDEVICE_DELTA1010LT:
    540553                err = snd_ice1712_spdif_build_controls(ice);
    541554                if (err < 0)
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ews.c

    r224 r246  
    156156
    157157/* start callback for EWS88MT, needs to select a certain chip mask */
    158 static int ews88mt_ak4524_start(akm4xxx_t *ak, int chip)
    159 {
    160         ice1712_t *ice = ak->chip;
     158static void ews88mt_ak4524_lock(akm4xxx_t *ak, int chip)
     159{
     160        ice1712_t *ice = ak->private_data[0];
    161161        unsigned char tmp;
    162162        /* assert AK4524 CS */
    163163        if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
    164                 return -EINVAL;
     164                snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n");
    165165        snd_ice1712_save_gpio_status(ice);
    166166        tmp = ICE1712_EWS88_SERIAL_DATA |
     
    170170                          ice->gpio.direction | tmp);
    171171        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    172         return 0;
    173172}
    174173
    175174/* stop callback for EWS88MT, needs to deselect chip mask */
    176 static void ews88mt_ak4524_stop(akm4xxx_t *ak)
    177 {
    178         ice1712_t *ice = ak->chip;
     175static void ews88mt_ak4524_unlock(akm4xxx_t *ak, int chip)
     176{
     177        ice1712_t *ice = ak->private_data[0];
    179178        snd_ice1712_restore_gpio_status(ice);
    180179        udelay(1);
     
    183182
    184183/* start callback for EWX24/96 */
    185 static int ewx2496_ak4524_start(akm4xxx_t *ak, int chip)
    186 {
    187         ice1712_t *ice = ak->chip;
     184static void ewx2496_ak4524_lock(akm4xxx_t *ak, int chip)
     185{
     186        ice1712_t *ice = ak->private_data[0];
    188187        unsigned char tmp;
    189188        snd_ice1712_save_gpio_status(ice);
     
    195194                          ice->gpio.direction | tmp);
    196195        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    197         return 0;
    198196}
    199197
    200198/* start callback for DMX 6fire */
    201 static int dmx6fire_ak4524_start(akm4xxx_t *ak, int chip)
    202 {
    203         ice1712_t *ice = ak->chip;
     199static void dmx6fire_ak4524_lock(akm4xxx_t *ak, int chip)
     200{
     201        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
     202        ice1712_t *ice = ak->private_data[0];
    204203        unsigned char tmp;
    205204        snd_ice1712_save_gpio_status(ice);
    206         tmp = ak->cs_mask = ak->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
     205        tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
    207206        tmp |= ICE1712_6FIRE_SERIAL_DATA |
    208207                ICE1712_6FIRE_SERIAL_CLOCK |
     
    211210                          ice->gpio.direction | tmp);
    212211        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    213         return 0;
    214 }
    215 
     212}
    216213
    217214/*
     
    329326        .num_dacs = 8,
    330327        .type = SND_AK4524,
     328        .ops = {
     329                .lock = ews88mt_ak4524_lock,
     330                .unlock = ews88mt_ak4524_unlock
     331        }
     332};
     333
     334static struct snd_ak4xxx_private akm_ews88mt_priv __devinitdata = {
    331335        .caddr = 2,
    332336        .cif = 1, /* CIF high */
     
    338342        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
    339343        .mask_flags = 0,
    340         .ops = {
    341                 .start = ews88mt_ak4524_start,
    342                 .stop = ews88mt_ak4524_stop
    343         }
    344344};
    345345
     
    348348        .num_dacs = 2,
    349349        .type = SND_AK4524,
     350        .ops = {
     351                .lock = ewx2496_ak4524_lock
     352        }
     353};
     354
     355static struct snd_ak4xxx_private akm_ewx2496_priv __devinitdata = {
    350356        .caddr = 2,
    351357        .cif = 1, /* CIF high */
     
    357363        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
    358364        .mask_flags = 0,
    359         .ops = {
    360                 .start = ewx2496_ak4524_start
    361         }
    362365};
    363366
     
    366369        .num_dacs = 6,
    367370        .type = SND_AK4524,
     371        .ops = {
     372                .lock = dmx6fire_ak4524_lock
     373        }
     374};
     375
     376static struct snd_ak4xxx_private akm_6fire_priv __devinitdata = {
    368377        .caddr = 2,
    369378        .cif = 1, /* CIF high */
     
    375384        .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
    376385        .mask_flags = 0,
    377         .ops = {
    378                 .start = dmx6fire_ak4524_start
    379         }
    380 };
    381 
     386};
    382387
    383388/*
     
    480485        case ICE1712_SUBDEVICE_EWS88MT:
    481486        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    482                 snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, ice);
     487                err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
    483488                break;
    484489        case ICE1712_SUBDEVICE_EWX2496:
    485                 snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, ice);
     490                err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
    486491                break;
    487492        case ICE1712_SUBDEVICE_DMX6FIRE:
    488                 snd_ice1712_akm4xxx_init(ak, &akm_6fire, ice);
    489                 break;
    490         }
    491 
    492         return 0;
     493                err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
     494                break;
     495        default:
     496                err = 0;
     497        }
     498
     499        return err;
    493500}
    494501
     
    603610{
    604611        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    605         int channel = kcontrol->id.index;
     612        int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    606613        unsigned char data;
    607614
     
    622629{
    623630        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    624         int channel = kcontrol->id.index;
     631        int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    625632        unsigned char data, ndata;
    626633
     
    646653        .get = snd_ice1712_ews88mt_input_sense_get,
    647654        .put = snd_ice1712_ews88mt_input_sense_put,
     655        .count = 8,
    648656};
    649657
     
    895903        unsigned int idx;
    896904        int err;
    897         snd_kcontrol_t *kctl;
    898905       
    899         /* all terratec cards have spdif */
    900         err = snd_ice1712_spdif_build_controls(ice);
    901         if (err < 0)
    902                 return err;
     906        /* all terratec cards have spdif, but cs8427 module builds it's own controls */
     907        if (ice->cs8427 == NULL) {
     908                err = snd_ice1712_spdif_build_controls(ice);
     909                if (err < 0)
     910                        return err;
     911        }
    903912
    904913        /* ak4524 controls */
     
    925934        case ICE1712_SUBDEVICE_EWS88MT:
    926935        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    927                 for (idx = 0; idx < 8; idx++) {
    928                         kctl = snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice);
    929                         kctl->id.index = idx;
    930                         err = snd_ctl_add(ice->card, kctl);
    931                         if (err < 0)
    932                                 return err;
    933                 }
     936                err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
     937                if (err < 0)
     938                        return err;
    934939                err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
    935940                if (err < 0)
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.c

    r231 r246  
    119119
    120120/*
     121 *  AK4xxx stuff
     122 */
     123
     124#include "ak4xxx.c"
     125
     126/*
    121127 *  Basic I/O
    122128 */
     
    399405 */
    400406
    401 static void snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    402 {
    403         ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return);
     407static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     408{
     409        ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
    404410        unsigned char status;
     411        int handled = 0;
    405412
    406413        while (1) {
     
    408415                if (status == 0)
    409416                        break;
     417                handled = 1;
    410418                if (status & ICE1712_IRQ_MPU1) {
    411419                        if (ice->rmidi[0])
     
    463471                }
    464472        }
     473        return IRQ_RETVAL(handled);
    465474}
    466475
     
    963972                unsigned int what = 0;
    964973                unsigned int old;
    965                 snd_pcm_substream_t *s = substream;
    966 
    967                 do {
     974                struct list_head *pos;
     975                snd_pcm_substream_t *s;
     976
     977                snd_pcm_group_for_each(pos, substream) {
     978                        s = snd_pcm_group_substream_entry(pos);
    968979                        if (s == ice->playback_pro_substream) {
    969980                                what |= ICE1712_PLAYBACK_START;
     
    973984                                snd_pcm_trigger_done(s, substream);
    974985                        }
    975                         s = s->link_next;
    976                 } while (s != substream);
     986                }
    977987                spin_lock(&ice->reg_lock);
    978988                old = inl(ICEMT(ice, PLAYBACK_CONTROL));
     
    12971307{
    12981308        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1299         int index = kcontrol->private_value;
     1309        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13001310       
    13011311        spin_lock_irq(&ice->reg_lock);
     
    13091319{
    13101320        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1311         int index = kcontrol->private_value;
     1321        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13121322        unsigned int nval, change;
    13131323
     
    13351345{
    13361346        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1337         int index = kcontrol->private_value;
     1347        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13381348       
    13391349        spin_lock_irq(&ice->reg_lock);
     
    13471357{
    13481358        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1349         int index = kcontrol->private_value;
     1359        int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
    13501360        unsigned int nval, change;
    13511361
     
    13621372
    13631373
     1374static snd_kcontrol_new_t snd_ice1712_multi_ctrls[] __devinitdata = {
     1375        {
     1376                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1377                .name = "Multi Playback Switch",
     1378                .info = snd_ice1712_pro_mixer_switch_info,
     1379                .get = snd_ice1712_pro_mixer_switch_get,
     1380                .put = snd_ice1712_pro_mixer_switch_put,
     1381                .private_value = 0,
     1382                .count = 10,
     1383        },
     1384        {
     1385                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1386                .name = "Multi Playback Volume",
     1387                .info = snd_ice1712_pro_mixer_volume_info,
     1388                .get = snd_ice1712_pro_mixer_volume_get,
     1389                .put = snd_ice1712_pro_mixer_volume_put,
     1390                .private_value = 0,
     1391                .count = 10,
     1392        },
     1393        {
     1394                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1395                .name = "Multi Capture Switch",
     1396                .info = snd_ice1712_pro_mixer_switch_info,
     1397                .get = snd_ice1712_pro_mixer_switch_get,
     1398                .put = snd_ice1712_pro_mixer_switch_put,
     1399                .private_value = 10,
     1400                .count = 10,
     1401        },
     1402        {
     1403                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1404                .name = "Multi Capture Volume",
     1405                .info = snd_ice1712_pro_mixer_volume_info,
     1406                .get = snd_ice1712_pro_mixer_volume_get,
     1407                .put = snd_ice1712_pro_mixer_volume_put,
     1408                .private_value = 10,
     1409                .count = 10,
     1410        },
     1411};
     1412
    13641413static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
    13651414{
    13661415        snd_card_t * card = ice->card;
    1367         snd_kcontrol_t ctl;
    1368         int idx, err;
    1369 
    1370         /* PCM playback */
    1371         for (idx = 0; idx < 10; idx++) {
    1372                 memset(&ctl, 0, sizeof(ctl));
    1373                 strcpy(ctl.id.name, "Multi Playback Switch");
    1374                 ctl.id.index = idx;
    1375                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1376                 ctl.info = snd_ice1712_pro_mixer_switch_info;
    1377                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1378                 ctl.get = snd_ice1712_pro_mixer_switch_get;
    1379                 ctl.put = snd_ice1712_pro_mixer_switch_put;
    1380                 ctl.private_value = idx;
    1381                 ctl.private_data = ice;
    1382                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1383                         return err;
    1384                 memset(&ctl, 0, sizeof(ctl));
    1385                 strcpy(ctl.id.name, "Multi Playback Volume");
    1386                 ctl.id.index = idx;
    1387                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1388                 ctl.info = snd_ice1712_pro_mixer_volume_info;
    1389                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1390                 ctl.get = snd_ice1712_pro_mixer_volume_get;
    1391                 ctl.put = snd_ice1712_pro_mixer_volume_put;
    1392                 ctl.private_value = idx;
    1393                 ctl.private_data = ice;
    1394                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1395                         return err;
    1396         }
    1397 
    1398         /* PCM capture */
    1399         for (idx = 0; idx < 10; idx++) {
    1400                 memset(&ctl, 0, sizeof(ctl));
    1401                 strcpy(ctl.id.name, "Multi Capture Switch");
    1402                 ctl.id.index = idx;
    1403                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1404                 ctl.info = snd_ice1712_pro_mixer_switch_info;
    1405                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1406                 ctl.get = snd_ice1712_pro_mixer_switch_get;
    1407                 ctl.put = snd_ice1712_pro_mixer_switch_put;
    1408                 ctl.private_value = idx + 10;
    1409                 ctl.private_data = ice;
    1410                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
    1411                         return err;
    1412                 memset(&ctl, 0, sizeof(ctl));
    1413                 strcpy(ctl.id.name, "Multi Capture Volume");
    1414                 ctl.id.index = idx;
    1415                 ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    1416                 ctl.info = snd_ice1712_pro_mixer_volume_info;
    1417                 ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    1418                 ctl.get = snd_ice1712_pro_mixer_volume_get;
    1419                 ctl.put = snd_ice1712_pro_mixer_volume_put;
    1420                 ctl.private_value = idx + 10;
    1421                 ctl.private_data = ice;
    1422                 if ((err = snd_ctl_add(card, snd_ctl_new(&ctl))) < 0)
     1416        unsigned int idx;
     1417        int err;
     1418
     1419        /* multi-channel mixer */
     1420        for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_ctrls); idx++) {
     1421                err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_ctrls[idx], ice));
     1422                if (err < 0)
    14231423                        return err;
    14241424        }
     
    19091909        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    19101910        uinfo->count = 1;
    1911         uinfo->value.enumerated.items = kcontrol->id.index < 2 ? 12 : 11;
     1911        uinfo->value.enumerated.items = snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
    19121912        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    19131913                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     
    19191919{
    19201920        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1921         int idx = kcontrol->id.index;
     1921        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19221922        unsigned int val, cval;
    19231923
     
    19451945        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    19461946        int change, shift;
    1947         int idx = kcontrol->id.index;
     1947        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19481948        unsigned int val, old_val, nval;
    19491949       
     
    19931993{
    19941994        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1995         int idx = kcontrol->id.index;
     1995        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    19961996        unsigned int val, cval;
    19971997        val = inw(ICEMT(ice, ROUTE_SPDOUT));
     
    20132013        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    20142014        int change, shift;
    2015         int idx = kcontrol->id.index;
     2015        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    20162016        unsigned int val, old_val, nval;
    20172017       
     
    20612061        .get = snd_ice1712_pro_route_spdif_get,
    20622062        .put = snd_ice1712_pro_route_spdif_put,
     2063        .count = 2,
    20632064};
    20642065
     
    22472248static int __devinit snd_ice1712_build_controls(ice1712_t *ice)
    22482249{
    2249         unsigned int idx;
    2250         snd_kcontrol_t *kctl;
    22512250        int err;
    22522251
     
    22652264                return err;
    22662265
    2267         for (idx = 0; idx < ice->num_total_dacs; idx++) {
    2268                 kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
    2269                 if (kctl == NULL)
    2270                         return -ENOMEM;
    2271                 kctl->id.index = idx;
    2272                 err = snd_ctl_add(ice->card, kctl);
     2266        if (ice->num_total_dacs > 0) {
     2267                snd_kcontrol_new_t tmp = snd_ice1712_mixer_pro_analog_route;
     2268                tmp.count = ice->num_total_dacs;
     2269                err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
    22732270                if (err < 0)
    22742271                        return err;
    22752272        }
    22762273
    2277         for (idx = 0; idx < 2; idx++) {
    2278                 kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice);
    2279                 if (kctl == NULL)
    2280                         return -ENOMEM;
    2281                 kctl->id.index = idx;
    2282                 err = snd_ctl_add(ice->card, kctl);
    2283                 if (err < 0)
    2284                         return err;
    2285         }
     2274        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
     2275        if (err < 0)
     2276                return err;
    22862277
    22872278        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
     
    23242315                kfree_nocheck(ice->res_profi_port);
    23252316        }
    2326         if (ice->akm)
    2327                 kfree(ice->akm);
     2317        snd_ice1712_akm4xxx_free(ice);
    23282318        snd_magic_kfree(ice);
    23292319        return 0;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.h

    r224 r246  
    2727#include <sound/rawmidi.h>
    2828#include <sound/i2c.h>
     29#include <sound/ak4xxx-adda.h>
    2930#include <sound/pcm.h>
    3031
     
    215216
    216217typedef struct _snd_ice1712 ice1712_t;
    217 typedef struct snd_ak4xxx akm4xxx_t;
    218218
    219219typedef struct {
     
    255255
    256256
    257 struct snd_ak4xxx {
    258         unsigned int num_adcs;          /* AK4524 or AK4528 ADCs */
    259         unsigned int num_dacs;          /* AK4524 or AK4528 DACs */
    260         unsigned char images[4][16];    /* saved register image */
    261         unsigned char ipga_gain[4][2];  /* saved register image for IPGA (AK4528) */
    262         ice1712_t *chip;
    263         /* template should fill the following fields */
    264         unsigned int idx_offset;        /* control index offset */
    265         enum {
    266                 SND_AK4524, SND_AK4528, SND_AK4529, SND_AK4355, SND_AK4381
    267         } type;
     257struct snd_ak4xxx_private {
    268258        unsigned int cif: 1;            /* CIF mode */
    269259        unsigned char caddr;            /* C0 and C1 bits */
     
    276266        unsigned int mask_flags;        /* total mask bits */
    277267        struct snd_akm4xxx_ops {
    278                 int (*start)(akm4xxx_t *ak, int chip);
    279                 void (*stop)(akm4xxx_t *ak);
    280268                void (*set_rate_val)(akm4xxx_t *ak, unsigned int rate);
    281269        } ops;
     
    440428int snd_ice1712_spdif_build_controls(ice1712_t *ice);
    441429
    442 void snd_ice1712_akm4xxx_write(akm4xxx_t *ice, int chip, unsigned char addr, unsigned char data);
    443 void snd_ice1712_akm4xxx_reset(akm4xxx_t *ice, int state);
    444 void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *template, ice1712_t *ice);
     430int snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *template, const struct snd_ak4xxx_private *priv, ice1712_t *ice);
     431void snd_ice1712_akm4xxx_free(ice1712_t *ice);
    445432int snd_ice1712_akm4xxx_build_controls(ice1712_t *ice);
    446433
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1724.c

    r231 r246  
    8989
    9090/*
     91 *  AK4xxx stuff
     92 */
     93
     94#include "ak4xxx.c"
     95
     96/*
    9197 *  Basic I/O
    9298 */
     
    195201 */
    196202
    197 static void snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    198 {
    199         ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return);
     203static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     204{
     205        ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return IRQ_NONE);
    200206        unsigned char status;
     207        int handled = 0;
    201208
    202209        while (1) {
     
    204211                if (status == 0)
    205212                        break;
    206                
     213
     214                handled = 1;           
    207215                /*  these should probably be separated at some point,
    208216                        but as we don't currently have MPU support on the board I will leave it */
     
    243251                }
    244252        }
     253        return IRQ_RETVAL(handled);
    245254}
    246255
     
    282291        unsigned int what;
    283292        unsigned int old;
     293        struct list_head *pos;
    284294        snd_pcm_substream_t *s;
    285295
     
    288298        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    289299                what = 0;
    290                 s = substream;
    291                 do {
     300                snd_pcm_group_for_each(pos, substream) {
     301                        s = snd_pcm_group_substream_entry(pos);
    292302                        if (s == ice->playback_pro_substream)
    293303                                what |= VT1724_PDMA0_PAUSE;
     
    298308                        else if (s == ice->capture_con_substream)
    299309                                what |= VT1724_RDMA1_PAUSE;
    300                         s = s->link_next;
    301                 } while (s != substream);
     310                }
    302311                spin_lock(&ice->reg_lock);
    303312                old = inl(ICEMT1724(ice, DMA_PAUSE));
     
    314323                what = 0;
    315324                s = substream;
    316                 do {
     325                snd_pcm_group_for_each(pos, substream) {
     326                        s = snd_pcm_group_substream_entry(pos);
    317327                        if (s == ice->playback_pro_substream) {
    318328                                what |= VT1724_PDMA0_START;
     
    328338                                snd_pcm_trigger_done(s, substream);
    329339                        }
    330                         s = s->link_next;
    331                 } while (s != substream);
     340                }
    332341                spin_lock(&ice->reg_lock);
    333342                old = inl(ICEMT1724(ice, DMA_CONTROL));
     
    12951304}
    12961305
    1297 static snd_kcontrol_new_t snd_vt1724_pro_internal_clock = __devinitdata {
     1306static snd_kcontrol_new_t snd_vt1724_pro_internal_clock __devinitdata = {
    12981307        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
    12991308        .name = "Multi Track Internal Clock",
     
    14501459{
    14511460        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1452         int idx = kcontrol->id.index;
     1461        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14531462        ucontrol->value.enumerated.item[0] = get_route_val(ice, analog_route_shift(idx));
    14541463        return 0;
     
    14581467{
    14591468        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1460         int idx = kcontrol->id.index;
     1469        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14611470        return put_route_val(ice, ucontrol->value.enumerated.item[0],
    14621471                             analog_route_shift(idx));
     
    14661475{
    14671476        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1468         int idx = kcontrol->id.index;
     1477        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14691478        ucontrol->value.enumerated.item[0] = get_route_val(ice, digital_route_shift(idx));
    14701479        return 0;
     
    14741483{
    14751484        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1476         int idx = kcontrol->id.index;
     1485        int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
    14771486        return put_route_val(ice, ucontrol->value.enumerated.item[0],
    14781487                             digital_route_shift(idx));
     
    14931502        .get = snd_vt1724_pro_route_spdif_get,
    14941503        .put = snd_vt1724_pro_route_spdif_put,
     1504        .count = 2,
    14951505};
    14961506
     
    16031613{
    16041614        int err;
    1605         unsigned int idx;
    16061615        snd_kcontrol_t *kctl;
    16071616
    16081617        snd_assert(ice->pcm != NULL, return -EIO);
    16091618
    1610         for (idx = 0; idx < 2; idx++) {
    1611                 kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice);
    1612                 if (kctl == NULL)
    1613                         return -ENOMEM;
    1614                 kctl->id.index = idx;
    1615                 err = snd_ctl_add(ice->card, kctl);
    1616                 if (err < 0)
    1617                         return err;
    1618         }
     1619        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
     1620        if (err < 0)
     1621                return err;
    16191622
    16201623        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
     
    16471650static int __devinit snd_vt1724_build_controls(ice1712_t *ice)
    16481651{
    1649         unsigned int idx;
    1650         snd_kcontrol_t *kctl;
    16511652        int err;
    16521653
     
    16651666                return err;
    16661667
    1667         for (idx = 0; idx < ice->num_total_dacs; idx++) {
    1668                 kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_analog_route, ice);
    1669                 if (kctl == NULL)
    1670                         return -ENOMEM;
    1671                 kctl->id.index = idx;
    1672                 err = snd_ctl_add(ice->card, kctl);
     1668        if (ice->num_total_dacs > 0) {
     1669                snd_kcontrol_new_t tmp = snd_vt1724_mixer_pro_analog_route;
     1670                tmp.count = ice->num_total_dacs;
     1671                err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
    16731672                if (err < 0)
    16741673                        return err;
     
    17031702                kfree_nocheck(ice->res_profi_port);
    17041703        }
    1705         if (ice->akm)
    1706                 kfree(ice->akm);
     1704        snd_ice1712_akm4xxx_free(ice);
    17071705        snd_magic_kfree(ice);
    17081706        return 0;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/makefile.os2

    r224 r246  
    1313#
    1414#===================================================================
    15 FILE1    = ak4524.obj delta.obj ews.obj hoontech.obj ice1712.obj
     15FILE1    = ak4xxx.obj delta.obj ews.obj hoontech.obj ice1712.obj
    1616FILE2    = ice1724.obj revo.obj
    1717FILE3    =
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/revo.c

    r224 r246  
    6666
    6767        /* reset DFS */
    68         snd_ice1712_akm4xxx_reset(ak, 1);
     68        snd_akm4xxx_reset(ak, 1);
    6969        tmp = ak->images[0][reg];
    7070        tmp &= ~(0x03 << shift);
    7171        tmp |= dfs << shift;
    72         snd_ice1712_akm4xxx_write(ak, 0, reg, tmp);
    73         snd_ice1712_akm4xxx_reset(ak, 0);
     72        snd_akm4xxx_write(ak, 0, reg, tmp);
     73        snd_akm4xxx_reset(ak, 0);
    7474}
    7575
     
    8181        .type = SND_AK4381,
    8282        .num_dacs = 2,
     83        .ops = {
     84                .set_rate_val = revo_set_rate_val
     85        }
     86};
     87
     88static struct snd_ak4xxx_private akm_revo_front_priv __devinitdata = {
    8389        .caddr = 1,
    8490        .cif = 0,
     
    9096        .add_flags = VT1724_REVO_CCLK, /* high at init */
    9197        .mask_flags = 0,
    92         .ops = {
    93                 .set_rate_val = revo_set_rate_val
    94         }
    9598};
    9699
     
    99102        .idx_offset = 1,
    100103        .num_dacs = 6,
     104        .ops = {
     105                .set_rate_val = revo_set_rate_val
     106        }
     107};
     108
     109static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
    101110        .caddr = 3,
    102111        .cif = 0,
     
    108117        .add_flags = VT1724_REVO_CCLK, /* high at init */
    109118        .mask_flags = 0,
    110         .ops = {
    111                 .set_rate_val = revo_set_rate_val
    112         }
    113119};
    114120
     
    134140        switch (ice->eeprom.subvendor) {
    135141        case VT1724_SUBDEVICE_REVOLUTION71:
    136                 snd_ice1712_akm4xxx_init(ak, &akm_revo_front, ice);
    137                 snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, ice);
     142                snd_ice1712_akm4xxx_init(ak, &akm_revo_front, &akm_revo_front_priv, ice);
     143                snd_ice1712_akm4xxx_init(ak + 1, &akm_revo_surround, &akm_revo_surround_priv, ice);
    138144                /* unmute all codecs */
    139145                snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE, VT1724_REVO_MUTE);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/korg1212/korg1212.c

    r224 r246  
    150150#define MAILBOX2_OFFSET      0x48       // location of mailbox 2 relative to base address
    151151#define MAILBOX3_OFFSET      0x4c       // location of mailbox 3 relative to base address
    152 #define OUT_DOORBELL_OFFSET  0x60       // location of PCI to local doorbell "
    153 #define IN_DOORBELL_OFFSET   0x64       // location of local to PCI doorbell "
    154 #define STATUS_REG_OFFSET    0x68       // location of interrupt control/status register "
     152#define OUT_DOORBELL_OFFSET  0x60       // location of PCI to local doorbell
     153#define IN_DOORBELL_OFFSET   0x64       // location of local to PCI doorbell
     154#define STATUS_REG_OFFSET    0x68       // location of interrupt control/status register
    155155#define PCI_CONTROL_OFFSET   0x6c       // location of the EEPROM, PCI, User I/O, init control
    156156                                        //    register
     
    330330
    331331        spinlock_t    lock;
     332        struct semaphore open_mutex;
     333
     334        struct timer_list timer;        /* timer callback for checking ack of stop request */
     335        int stop_pending_cnt;           /* counter for stop pending check */
    332336
    333337        wait_queue_head_t wait;
     
    603607}
    604608
    605 static void snd_korg1212_WaitForCardStopAck(korg1212_t *korg1212)
    606 {
    607         u32 endtime = jiffies + 2 * HZ;
    608 
    609 #if K1212_DEBUG_LEVEL > 0
    610         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.in [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    611 #endif
    612 
    613         if (korg1212->inIRQ)
    614                 return;
    615 
    616         do {
     609/* spinlock already held */
     610static void snd_korg1212_SendStop(korg1212_t *korg1212)
     611{
     612        if (! korg1212->stop_pending_cnt) {
     613                writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
     614                /* program the timer */
     615                korg1212->stop_pending_cnt = HZ;
     616                korg1212->timer.expires = jiffies + 1;
     617                add_timer(&korg1212->timer);
     618        }
     619}
     620
     621static void snd_korg1212_SendStopAndWait(korg1212_t *korg1212)
     622{
     623        unsigned long flags;
     624        spin_lock_irqsave(&korg1212->lock, flags);
     625        snd_korg1212_SendStop(korg1212);
     626        spin_unlock_irqrestore(&korg1212->lock, flags);
     627        sleep_on_timeout(&korg1212->wait, (HZ * 3) / 2);
     628}
     629
     630/* timer callback for checking the ack of stop request */
     631static void snd_korg1212_timer_func(unsigned long data)
     632{
     633        korg1212_t *korg1212 = snd_magic_cast(korg1212_t, (void*)data, return);
     634       
     635        spin_lock(&korg1212->lock);
    617636                if (readl(&korg1212->sharedBufferPtr->cardCommand) == 0) {
    618 #if K1212_DEBUG_LEVEL > 0
    619                         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.out [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    620 #endif
    621                         return;
     637                /* ack'ed */
     638                korg1212->stop_pending_cnt = 0;
     639                wake_up(&korg1212->wait);
     640#if K1212_DEBUG_LEVEL > 1
     641                K1212_DEBUG_PRINTK("K1212_DEBUG: Stop ack'ed [%s]\n", stateName[korg1212->cardState]);
     642#endif
     643        } else {
     644                if (--korg1212->stop_pending_cnt > 0) {
     645                        /* reprogram timer */
     646                        korg1212->timer.expires = jiffies + 1;
     647                        add_timer(&korg1212->timer);
     648                } else {
     649                        snd_printd("korg1212_timer_func timeout\n");
     650        writel(0, &korg1212->sharedBufferPtr->cardCommand);
     651                        wake_up(&korg1212->wait);
     652#if K1212_DEBUG_LEVEL > 0
     653                        K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", stateName[korg1212->cardState]);
     654#endif
    622655                }
    623                 if (!korg1212->inIRQ)
    624                         schedule();
    625         } while (time_before(jiffies, endtime));
    626 
    627 #if K1212_DEBUG_LEVEL > 0
    628         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck.out TO [%s] %lu %lu\n", stateName[korg1212->cardState], jiffies, korg1212->inIRQ);
    629 #endif
    630         writel(0, &korg1212->sharedBufferPtr->cardCommand);
     656        }
     657        spin_unlock(&korg1212->lock);
    631658}
    632659
    633660static void snd_korg1212_TurnOnIdleMonitor(korg1212_t *korg1212)
    634661{
     662        unsigned long flags;
     663
    635664        udelay(INTERCOMMAND_DELAY);
     665        spin_lock_irqsave(&korg1212->lock, flags);
    636666        korg1212->idleMonitorOn = 1;
    637667        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
    638668                        K1212_MODE_MonitorOn, 0, 0, 0);
     669        spin_unlock_irqrestore(&korg1212->lock, flags);
    639670}
    640671
     
    642673{
    643674        if (korg1212->idleMonitorOn) {
    644                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    645                 snd_korg1212_WaitForCardStopAck(korg1212);
     675                snd_korg1212_SendStopAndWait(korg1212);
    646676                korg1212->idleMonitorOn = 0;
    647677        }
    648678}
    649679
    650 static void snd_korg1212_setCardState(korg1212_t * korg1212, CardState csState)
    651 {
    652         switch (csState) {
    653                 case K1212_STATE_READY:
    654                         snd_korg1212_TurnOnIdleMonitor(korg1212);
    655                         break;
    656 
    657                 case K1212_STATE_OPEN:
    658                         snd_korg1212_TurnOffIdleMonitor(korg1212);
    659                         break;
    660 
    661                 default:
    662                         break;
    663         }
    664 
     680static inline void snd_korg1212_setCardState(korg1212_t * korg1212, CardState csState)
     681{
    665682        korg1212->cardState = csState;
    666683}
     
    671688        K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt);
    672689#endif
    673         if (korg1212->opencnt++ == 0)
     690        down(&korg1212->open_mutex);
     691        if (korg1212->opencnt++ == 0) {
     692                snd_korg1212_TurnOffIdleMonitor(korg1212);
    674693        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
     694        }
     695
     696        up(&korg1212->open_mutex);
    675697        return 1;
    676698}
     
    682704#endif
    683705
    684         if (--(korg1212->opencnt))
     706        down(&korg1212->open_mutex);
     707        if (--(korg1212->opencnt)) {
     708                up(&korg1212->open_mutex);
    685709                return 0;
     710        }
    686711
    687712        if (korg1212->cardState == K1212_STATE_SETUP) {
     
    692717#endif
    693718
    694                 if (rc != K1212_CMDRET_Success)
     719                if (rc != K1212_CMDRET_Success) {
     720                        up(&korg1212->open_mutex);
    695721                        return 0;
     722                }
    696723        } else if (korg1212->cardState > K1212_STATE_SETUP) {
    697                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    698                 snd_korg1212_WaitForCardStopAck(korg1212);
    699         }
    700 
    701         if (korg1212->cardState > K1212_STATE_READY)
     724                snd_korg1212_SendStopAndWait(korg1212);
     725        }
     726
     727        if (korg1212->cardState > K1212_STATE_READY) {
     728                snd_korg1212_TurnOnIdleMonitor(korg1212);
    702729                snd_korg1212_setCardState(korg1212, K1212_STATE_READY);
    703 
     730        }
     731
     732        up(&korg1212->open_mutex);
    704733        return 0;
    705734}
    706735
     736/* spinlock already held */
    707737static int snd_korg1212_SetupForPlay(korg1212_t * korg1212)
    708738{
     
    727757}
    728758
     759/* spinlock already held */
    729760static int snd_korg1212_TriggerPlay(korg1212_t * korg1212)
    730761{
     
    749780}
    750781
     782/* spinlock already held */
    751783static int snd_korg1212_StopPlay(korg1212_t * korg1212)
    752784{
     
    760792        korg1212->setcnt = 0;
    761793
    762         if (korg1212->cardState != K1212_STATE_ERRORSTOP) {
    763                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    764                 snd_korg1212_WaitForCardStopAck(korg1212);
    765         }
     794        if (korg1212->cardState != K1212_STATE_ERRORSTOP)
     795                snd_korg1212_SendStop(korg1212);
     796
    766797        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    767798        return 0;
     
    790821                                return 0;
    791822                        } else {
    792                                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    793                                 snd_korg1212_WaitForCardStopAck(korg1212);
     823                                snd_korg1212_SendStopAndWait(korg1212);
    794824                                snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    795825                        }
     
    885915                                   //  the card's eeprom control register.
    886916        u16       count;
     917        unsigned long flags;
    887918
    888919#if K1212_DEBUG_LEVEL > 0
     
    901932        // ----------------------------------------------------------------------------
    902933        if (korg1212->cardState == K1212_STATE_MONITOR || korg1212->idleMonitorOn) {
    903                 writel(0xffffffff, &korg1212->sharedBufferPtr->cardCommand);
    904934                monModeSet = 1;
    905                 snd_korg1212_WaitForCardStopAck(korg1212);
     935                snd_korg1212_SendStopAndWait(korg1212);
    906936        } else
    907937                monModeSet = 0;
     938
     939        spin_lock_irqsave(&korg1212->lock, flags);
    908940
    909941        // ----------------------------------------------------------------------------
     
    10171049        }
    10181050
     1051        spin_unlock_irqrestore(&korg1212->lock, flags);
     1052
    10191053        return 1;
    10201054}
     
    10901124#endif
    10911125
     1126        snd_korg1212_TurnOnIdleMonitor(korg1212);
    10921127        snd_korg1212_setCardState(korg1212, K1212_STATE_READY);
    10931128
     
    10961131#endif
    10971132
    1098         wake_up_interruptible(&korg1212->wait);
    1099 }
    1100 
    1101 static void snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     1133        snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE);
     1134}
     1135
     1136static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    11021137{
    11031138        u32 doorbellValue;
    1104         korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return);
     1139        korg1212_t *korg1212 = snd_magic_cast(korg1212_t, dev_id, return IRQ_NONE);
    11051140
    11061141        if(irq != korg1212->irq)
    1107                 return;
     1142                return IRQ_NONE;
    11081143
    11091144        doorbellValue = readl(korg1212->inDoorbellPtr);
    11101145
    11111146        if (!doorbellValue)
    1112                 return;
     1147                return IRQ_HANDLED;
     1148
     1149        spin_lock(&korg1212->lock);
    11131150
    11141151        writel(doorbellValue, korg1212->inDoorbellPtr);
     
    11241161                        K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);
    11251162#endif
    1126                         if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) {
    1127                                         snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE);
    1128                                         snd_korg1212_OnDSPDownloadComplete(korg1212);
    1129                         }
     1163                        if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS)
     1164                                wake_up(&korg1212->wait);
    11301165                        break;
    11311166
     
    11671202
    11681203                                if (korg1212->capture_substream) {
     1204                                        spin_unlock(&korg1212->lock);
    11691205                                        snd_pcm_period_elapsed(korg1212->capture_substream);
     1206                                        spin_lock(&korg1212->lock);
    11701207                                }
    11711208
    11721209                                if (korg1212->playback_substream) {
     1210                                        spin_unlock(&korg1212->lock);
    11731211                                        snd_pcm_period_elapsed(korg1212->playback_substream);
     1212                                        spin_lock(&korg1212->lock);
    11741213                                }
    11751214                        }
     
    11781217
    11791218        korg1212->inIRQ--;
     1219
     1220        spin_unlock(&korg1212->lock);
     1221        return IRQ_HANDLED;
    11801222}
    11811223
     
    12061248#endif
    12071249
    1208         interruptible_sleep_on_timeout(&korg1212->wait, HZ * 4);
     1250        if (! sleep_on_timeout(&korg1212->wait, HZ * 4))
     1251                return -EBUSY; /* timeout */
     1252
     1253        snd_korg1212_OnDSPDownloadComplete(korg1212);
    12091254
    12101255        return 0;
     
    13641409        snd_pcm_set_sync(substream);    // ???
    13651410
    1366         spin_lock_irqsave(&korg1212->lock, flags);
    1367 
    13681411        snd_korg1212_OpenCard(korg1212);
    13691412
     1413        runtime->hw = snd_korg1212_playback_info;
    13701414        runtime->dma_area = (char *) korg1212->playDataBufsPtr;
    13711415        runtime->dma_bytes = K1212_BUF_SIZE;
     1416
     1417        spin_lock_irqsave(&korg1212->lock, flags);
    13721418
    13731419        korg1212->playback_substream = substream;
     
    13941440        snd_pcm_set_sync(substream);    // ???
    13951441
    1396         spin_lock_irqsave(&korg1212->lock, flags);
    1397 
    13981442        snd_korg1212_OpenCard(korg1212);
    13991443
     
    14021446        runtime->dma_bytes = K1212_BUF_SIZE;
    14031447
     1448        spin_lock_irqsave(&korg1212->lock, flags);
     1449
    14041450        korg1212->capture_substream = substream;
    14051451        korg1212->periodsize = K1212_PERIODS;
     
    14281474        korg1212->periodsize = 0;
    14291475
    1430         snd_korg1212_CloseCard(korg1212);
    1431 
    14321476        spin_unlock_irqrestore(&korg1212->lock, flags);
     1477
     1478        snd_korg1212_CloseCard(korg1212);
    14331479        return 0;
    14341480}
     
    14481494        korg1212->periodsize = 0;
    14491495
    1450         snd_korg1212_CloseCard(korg1212);
    1451 
    14521496        spin_unlock_irqrestore(&korg1212->lock, flags);
     1497
     1498        snd_korg1212_CloseCard(korg1212);
    14531499        return 0;
    14541500}
     
    15081554{
    15091555        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    1510         unsigned long flags;
    15111556        int rc;
    15121557
     
    15151560#endif
    15161561
    1517         spin_lock_irqsave(&korg1212->lock, flags);
     1562        spin_lock(&korg1212->lock);
     1563
     1564        /* FIXME: we should wait for ack! */
     1565        if (korg1212->stop_pending_cnt > 0) {
     1566#if K1212_DEBUG_LEVEL > 0
     1567                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]);
     1568#endif
     1569                spin_unlock(&korg1212->lock);
     1570                return -EAGAIN;
     1571                /*
     1572                writel(0, &korg1212->sharedBufferPtr->cardCommand);
     1573                del_timer(&korg1212->timer);
     1574                korg1212->stop_pending_cnt = 0;
     1575                */
     1576        }
    15181577
    15191578        rc = snd_korg1212_SetupForPlay(korg1212);
     1579
    15201580        korg1212->currentBuffer = 0;
    15211581
    1522         spin_unlock_irqrestore(&korg1212->lock, flags);
     1582        spin_unlock(&korg1212->lock);
    15231583
    15241584        return rc ? -EINVAL : 0;
     
    15351595#endif
    15361596
     1597        spin_lock(&korg1212->lock);
    15371598        switch (cmd) {
    15381599                case SNDRV_PCM_TRIGGER_START:
     
    15661627                        break;
    15671628        }
     1629        spin_unlock(&korg1212->lock);
    15681630        return rc ? -EINVAL : 0;
    15691631}
     
    18941956        }
    18951957
     1958        spin_unlock_irqrestore(&korg1212->lock, flags);
     1959
    18961960        if (change)
    18971961                snd_korg1212_WriteADCSensitivity(korg1212);
    1898 
    1899         spin_unlock_irqrestore(&korg1212->lock, flags);
    19001962
    19011963        return change;
     
    21512213        init_waitqueue_head(&korg1212->wait);
    21522214        spin_lock_init(&korg1212->lock);
     2215        init_MUTEX(&korg1212->open_mutex);
     2216        init_timer(&korg1212->timer);
     2217        korg1212->timer.function = snd_korg1212_timer_func;
     2218        korg1212->timer.data = (unsigned long)korg1212;
    21532219
    21542220        korg1212->irq = -1;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme96.c

    r224 r246  
    11541154}
    11551155
    1156 static void
     1156static irqreturn_t
    11571157snd_rme96_interrupt(int irq,
    11581158                    void *dev_id,
     
    11661166              (rme96->rcreg & RME96_RCR_IRQ_2)))
    11671167        {
    1168                 return;
     1168                return IRQ_NONE;
    11691169        }
    11701170       
     
    11791179                writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
    11801180        }
     1181        return IRQ_HANDLED;
    11811182}
    11821183
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/hdsp.c

    r224 r246  
    33 *
    44 *      Copyright (c) 2002  Paul Davis
     5 *                          Marcus Andersson
     6 *                          Thomas Charbonnel
    57 *
    68 *   This program is free software; you can redistribute it and/or modify
     
    2123
    2224#include <sound/driver.h>
    23 #include <asm/io.h>
    24 #include <asm/byteorder.h>
    2525#include <linux/delay.h>
    26 #include <linux/init.h>
     26#include <linux/interrupt.h>
    2727#include <linux/slab.h>
    2828#include <linux/pci.h>
     29
    2930#include <sound/core.h>
    3031#include <sound/control.h>
     
    3334#include <sound/asoundef.h>
    3435#include <sound/rawmidi.h>
     36#include <sound/hwdep.h>
    3537#define SNDRV_GET_ID
    3638#include <sound/initval.h>
    37 
    38 #include "multiface_firmware.dat"
    39 #include "digiface_firmware.dat"
     39#include <sound/hdsp.h>
     40
     41#include <asm/byteorder.h>
     42#include <asm/current.h>
     43#include <asm/io.h>
    4044
    4145static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
     
    4448static int precise_ptr[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* Enable precise pointer */
    4549static int line_outs_monitor[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Send all inputs/playback to line outs */
    46 static int force_firmware[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Force firmware reload */
    4750
    4851MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     
    6164MODULE_PARM_DESC(line_outs_monitor, "Send all input and playback streams to line outs by default.");
    6265MODULE_PARM_SYNTAX(line_outs_monitor, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    63 MODULE_PARM(force_firmware,"1-" __MODULE_STRING(SNDRV_CARDS) "i");
    64 MODULE_PARM_DESC(force_firmware, "Force a reload of the I/O box firmware");
    65 MODULE_PARM_SYNTAX(force_firmware, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
    66 MODULE_AUTHOR("Paul Davis <pbd@op.net>");
     66MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
    6767MODULE_DESCRIPTION("RME Hammerfall DSP");
    6868MODULE_LICENSE("GPL");
    6969MODULE_CLASSES("{sound}");
    70 MODULE_DEVICES("{{RME,Hammerfall-DSP}}");
    71 
    72 typedef enum {
    73         Digiface,
    74         Multiface
    75 } HDSP_Type;
     70MODULE_DEVICES("{{RME Hammerfall-DSP},"
     71                "{RME HDSP-9652}}");
    7672
    7773#define HDSP_MAX_CHANNELS        26
     
    7975#define DIGIFACE_DS_CHANNELS     14
    8076#define MULTIFACE_SS_CHANNELS    18
    81 #define MULTIFACE_DS_CHANNELS    10
     77#define MULTIFACE_DS_CHANNELS    14
    8278
    8379/* Write registers. These are defined as byte-offsets from the iobase value.
     
    119115#define HDSP_playbackPeakLevel  4096  /* 26 * 32 bit values */
    120116#define HDSP_inputPeakLevel     4224  /* 26 * 32 bit values */
    121 #define HDSP_outputPeakLevel    4100  /* 26 * 32 bit values */
     117#define HDSP_outputPeakLevel    4352  /* (26+2) * 32 bit values */
    122118#define HDSP_playbackRmsLevel   4612  /* 26 * 64 bit values */
    123 #define HDSP_inputRmsLevel      4884  /* 26 * 64 bit values */
     119#define HDSP_inputRmsLevel      4868  /* 26 * 64 bit values */
    124120
    125121#define HDSP_IO_EXTENT     5192
     
    144140/* Control Register bits */
    145141
    146 #define HDSP_Start                (1<<0)  // start engine
    147 #define HDSP_Latency0             (1<<1)  // buffer size = 2^n where n is defined by Latency{2,1,0}
    148 #define HDSP_Latency1             (1<<2)  // [ see above ]
    149 #define HDSP_Latency2             (1<<3)  // ] see above ]
    150 #define HDSP_ClockModeMaster      (1<<4)  // 1=Master, 0=Slave/Autosync
    151 #define HDSP_AudioInterruptEnable (1<<5)  // what do you think ?
    152 #define HDSP_Frequency0           (1<<6)  // 0=44.1kHz/88.2kHz 1=48kHz/96kHz
    153 #define HDSP_Frequency1           (1<<7)  // 0=32kHz/64kHz
    154 #define HDSP_DoubleSpeed          (1<<8)  // 0=normal speed, 1=double speed
    155 #define HDSP_SPDIFProfessional    (1<<9)  // 0=consumer, 1=professional
    156 #define HDSP_SPDIFEmphasis        (1<<10) // 0=none, 1=on
    157 #define HDSP_SPDIFNonAudio        (1<<11) // 0=off, 1=on
    158 #define HDSP_SPDIFOpticalOut      (1<<12) // 1=use 1st ADAT connector for SPDIF, 0=do not
     142#define HDSP_Start                (1<<0)  /* start engine */
     143#define HDSP_Latency0             (1<<1)  /* buffer size = 2^n where n is defined by Latency{2,1,0} */
     144#define HDSP_Latency1             (1<<2)  /* [ see above ] */
     145#define HDSP_Latency2             (1<<3)  /* ] see above ] */
     146#define HDSP_ClockModeMaster      (1<<4)  /* 1=Master, 0=Slave/Autosync */
     147#define HDSP_AudioInterruptEnable (1<<5)  /* what do you think ? */
     148#define HDSP_Frequency0           (1<<6)  /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
     149#define HDSP_Frequency1           (1<<7)  /* 0=32kHz/64kHz */
     150#define HDSP_DoubleSpeed          (1<<8)  /* 0=normal speed, 1=double speed */
     151#define HDSP_SPDIFProfessional    (1<<9)  /* 0=consumer, 1=professional */
     152#define HDSP_SPDIFEmphasis        (1<<10) /* 0=none, 1=on */
     153#define HDSP_SPDIFNonAudio        (1<<11) /* 0=off, 1=on */
     154#define HDSP_SPDIFOpticalOut      (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
    159155#define HDSP_SyncRef2             (1<<13)
    160156#define HDSP_SPDIFInputSelect0    (1<<14)
     
    182178#define HDSP_SyncRef_ADAT_SYNC  (HDSP_SyncRef0|HDSP_SyncRef2)
    183179
    184 /* Preferred sync source choices - used by "sync_pref" control switch */
    185 
    186 #define HDSP_SYNC_FROM_SELF      0
    187 #define HDSP_SYNC_FROM_WORD      1
    188 #define HDSP_SYNC_FROM_ADAT_SYNC 2
    189 #define HDSP_SYNC_FROM_SPDIF     3
    190 #define HDSP_SYNC_FROM_ADAT1     4
    191 #define HDSP_SYNC_FROM_ADAT2     5
    192 #define HDSP_SYNC_FROM_ADAT3     6
     180/* Sample Clock Sources */
     181
     182#define HDSP_CLOCK_SOURCE_AUTOSYNC         0
     183#define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ   1
     184#define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
     185#define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ   3
     186#define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ   4
     187#define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
     188#define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ   6
     189
     190/* Preferred sync reference choices - used by "pref_sync_ref" control switch */
     191
     192#define HDSP_SYNC_FROM_WORD      0
     193#define HDSP_SYNC_FROM_ADAT_SYNC 1
     194#define HDSP_SYNC_FROM_SPDIF     2
     195#define HDSP_SYNC_FROM_ADAT1     3
     196#define HDSP_SYNC_FROM_ADAT2     4
     197#define HDSP_SYNC_FROM_ADAT3     5
     198
     199/* SyncCheck status */
     200
     201#define HDSP_SYNC_CHECK_NO_LOCK 0
     202#define HDSP_SYNC_CHECK_LOCK    1
     203#define HDSP_SYNC_CHECK_SYNC    2
     204
     205/* AutoSync references - used by "autosync_ref" control switch */
     206
     207#define HDSP_AUTOSYNC_FROM_WORD      0
     208#define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
     209#define HDSP_AUTOSYNC_FROM_SPDIF     2
     210#define HDSP_AUTOSYNC_FROM_NONE      3
     211#define HDSP_AUTOSYNC_FROM_ADAT1     4
     212#define HDSP_AUTOSYNC_FROM_ADAT2     5
     213#define HDSP_AUTOSYNC_FROM_ADAT3     6
    193214
    194215/* Possible sources of S/PDIF input */
     
    238259#define HDSP_spdifFrequencyMask    (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
    239260
    240 #define HDSP_spdifFrequency32KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
    241 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
    242 #define HDSP_spdifFrequency48KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
    243 
    244 #define HDSP_spdifFrequency64KHz    0
    245 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency2)
    246 #define HDSP_spdifFrequency96KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
     261#define HDSP_spdifFrequency32KHz   (HDSP_spdifFrequency0)
     262#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
     263#define HDSP_spdifFrequency48KHz   (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
     264
     265#define HDSP_spdifFrequency64KHz   (HDSP_spdifFrequency2)
     266#define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
     267#define HDSP_spdifFrequency96KHz   (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
    247268
    248269/* Status2 Register bits */
     
    278299#define HDSP_SelSyncRef_ADAT_SYNC  (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
    279300
    280 /* FIFO wait times, defined in terms of loops on readl() */
    281 
    282 #define HDSP_LONG_WAIT   40000
    283 #define HDSP_SHORT_WAIT  100
    284 
    285 /* Computing addresses for adjusting gains */
    286 
    287 #define INPUT_TO_OUTPUT_KEY(in,out)     ((64 * (out)) + (in))
    288 #define PLAYBACK_TO_OUTPUT_KEY(chn,out) ((64 * (out)) + 32 + (chn))
     301/* Card state flags */
     302
     303#define HDSP_InitializationComplete  (1<<0)
     304#define HDSP_FirmwareLoaded          (1<<1)
     305#define HDSP_FirmwareCached          (1<<2)
     306
     307/* FIFO wait times, defined in terms of 1/10ths of msecs */
     308
     309#define HDSP_LONG_WAIT   5000
     310#define HDSP_SHORT_WAIT  30
     311
    289312#define UNITY_GAIN                       32768
    290313#define MINUS_INFINITY_GAIN              0
     
    314337#define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
    315338
    316 #define HDSP_MATRIX_MIXER_SIZE 2048
    317 
    318 typedef struct _hdsp      hdsp_t;
    319 typedef struct _hdsp_midi hdsp_midi_t;
     339typedef struct _hdsp          hdsp_t;
     340typedef struct _hdsp_midi     hdsp_midi_t;
    320341
    321342struct _hdsp_midi {
     
    328349    struct timer_list        timer;
    329350    spinlock_t               lock;
     351    int                      pending;
    330352};
    331353
    332354struct _hdsp {
    333         spinlock_t lock;
    334         snd_pcm_substream_t *capture_substream;
    335         snd_pcm_substream_t *playback_substream;
    336         hdsp_midi_t midi[2];
    337         int precise_ptr;
    338         u32 control_register;            /* cached value */
    339         u32 creg_spdif;
    340         u32 creg_spdif_stream;
    341         char *card_name;                 /* digiface/multiface */
    342         HDSP_Type type;                  /* ditto, but for code use */
    343         size_t period_bytes;             /* guess what this is */
    344         unsigned char ds_channels;
    345         unsigned char ss_channels;       /* different for multiface/digiface */
    346         void *capture_buffer_unaligned;  /* original buffer addresses */
    347         void *playback_buffer_unaligned; /* original buffer addresses */
    348         unsigned char *capture_buffer;   /* suitably aligned address */
    349         unsigned char *playback_buffer;  /* suitably aligned address */
    350         dma_addr_t capture_buffer_addr;
    351         dma_addr_t playback_buffer_addr;
    352         pid_t capture_pid;
    353         pid_t playback_pid;
    354         int running;
    355         int passthru;                   /* non-zero if doing pass-thru */
    356         int last_spdif_sample_rate;     /* so that we can catch externally ... */
    357         int last_adat_sample_rate;      /* ... induced rate changes            */
    358         char *channel_map;
    359         int dev;
    360         int irq;
    361         unsigned long port;
    362         struct resource *res_port;
    363         unsigned long iobase;
    364         snd_card_t *card;
    365         snd_pcm_t *pcm;
    366         struct pci_dev *pci;
    367         snd_info_entry_t *proc_entry;
    368         snd_kcontrol_t *spdif_ctl;
    369         unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
     355        spinlock_t            lock;
     356        snd_pcm_substream_t  *capture_substream;
     357        snd_pcm_substream_t  *playback_substream;
     358        hdsp_midi_t           midi[2];
     359        struct tasklet_struct midi_tasklet;
     360        int                   precise_ptr;
     361        u32                   control_register;          /* cached value */
     362        u32                   creg_spdif;
     363        u32                   creg_spdif_stream;
     364        char                 *card_name;                    /* digiface/multiface */
     365        HDSP_IO_Type          io_type;               /* ditto, but for code use */
     366        unsigned short        firmware_rev;
     367        unsigned short        state;                 /* stores state bits */
     368        u32                   firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
     369        size_t                period_bytes;         /* guess what this is */
     370        unsigned char         ds_channels;
     371        unsigned char         ss_channels;          /* different for multiface/digiface */
     372        void                 *capture_buffer_unaligned;  /* original buffer addresses */
     373        void                 *playback_buffer_unaligned; /* original buffer addresses */
     374        unsigned char        *capture_buffer;       /* suitably aligned address */
     375        unsigned char        *playback_buffer;      /* suitably aligned address */
     376        dma_addr_t            capture_buffer_addr;
     377        dma_addr_t            playback_buffer_addr;
     378        pid_t                 capture_pid;
     379        pid_t                 playback_pid;
     380        int                   running;
     381        int                   passthru;              /* non-zero if doing pass-thru */
     382        int                   last_spdif_sample_rate;/* for information reporting */
     383        int                   last_external_sample_rate;
     384        int                   last_internal_sample_rate;
     385        int                   system_sample_rate;
     386        char                 *channel_map;
     387        int                   dev;
     388        int                   irq;
     389        unsigned long         port;
     390        struct resource      *res_port;
     391        unsigned long         iobase;
     392        snd_card_t           *card;
     393        snd_pcm_t            *pcm;
     394        snd_hwdep_t          *hwdep;
     395        struct pci_dev       *pci;
     396        snd_kcontrol_t       *spdif_ctl;
     397        snd_kcontrol_t       *playback_mixer_ctls[HDSP_MAX_CHANNELS];
     398        unsigned short        mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
    370399};
    371400
     
    384413
    385414static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
    386         /* ADAT 0 */
     415        /* Analog */
    387416        0, 1, 2, 3, 4, 5, 6, 7,
    388417        /* ADAT 2 */
     
    410439
    411440static struct pci_device_id snd_hdsp_ids[] __devinitdata = {
    412         {PCI_VENDOR_ID_XILINX,
    413          PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
    414          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,}, /* RME Hammerfall-DSP */
    415         {0,}
     441        {
     442                .vendor = PCI_VENDOR_ID_XILINX,
     443                .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
     444                .subvendor = PCI_ANY_ID,
     445                .subdevice = PCI_ANY_ID,
     446        }, /* RME Hammerfall-DSP */
     447        { 0, },
    416448};
    417449
    418450MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
    419451
     452/* prototypes */
     453static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
     454static int __devinit snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
     455static inline int snd_hdsp_initialize_input_enable (hdsp_t *hdsp);
     456static inline void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
     457static inline void snd_hdsp_initialize_channels (hdsp_t *hdsp);
     458static inline int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
     459static int hdsp_update_simple_mixer_controls(hdsp_t *hdsp);
     460static int hdsp_autosync_ref(hdsp_t *hdsp);
     461static int snd_hdsp_set_defaults(hdsp_t *hdsp);
     462
     463static inline int hdsp_is_9652 (hdsp_t *hdsp)
     464{
     465        switch (hdsp->firmware_rev) {
     466        case 0x64:
     467        case 0x65:
     468        case 0x68:
     469                return 1;
     470        default:
     471                return 0;
     472        }
     473}
     474
     475static inline int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
     476{
     477        switch (hdsp->firmware_rev) {
     478        case 0xa:
     479                return (64 * out) + (32 + (in));
     480        default:
     481                return (52 * out) + (26 + (in));
     482        }
     483}
     484
     485static inline int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
     486{
     487        switch (hdsp->firmware_rev) {
     488        case 0xa:
     489                return (64 * out) + in;
     490        default:
     491                return (52 * out) + in;
     492        }
     493}
     494
    420495static inline void hdsp_write(hdsp_t *hdsp, int reg, int val)
    421496{
     
    426501{
    427502        return readl (hdsp->iobase + reg);
    428 }
    429 
    430 static inline unsigned long long hdsp_read64 (hdsp_t *hdsp, int reg)
    431 {
    432         unsigned long long val;
    433         val = hdsp_read(hdsp, reg);
    434         val = (val<<32)|hdsp_read(hdsp, reg + 4);
    435 
    436         return val;
    437503}
    438504
     
    441507        if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
    442508                snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
     509                hdsp->state &= ~HDSP_FirmwareLoaded;
    443510                return -EIO;
    444511        }
    445512        return 0;
    446513}
     514
     515static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
     516
     517        int i;
     518        unsigned long flags;
     519
     520        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     521               
     522                snd_printk ("loading firmware\n");
     523
     524                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_PROGRAM);
     525                hdsp_write (hdsp, HDSP_fifoData, 0);
     526               
     527                if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
     528                        snd_printk ("timeout waiting for download preparation\n");
     529                        return -EIO;
     530                }
     531               
     532                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     533               
     534                for (i = 0; i < 24413; ++i) {
     535                        hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
     536                        if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
     537                                snd_printk ("timeout during firmware loading\n");
     538                                return -EIO;
     539                        }
     540                }
     541               
     542                if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
     543                        snd_printk ("timeout at end of firmware loading\n");
     544                        return -EIO;
     545                }
     546
     547                hdsp_write (hdsp, HDSP_jtagReg, 0);
     548                snd_printk ("finished firmware loading\n");
     549               
     550                if ((1000 / HZ) < 3000) {
     551                        set_current_state(TASK_UNINTERRUPTIBLE);
     552                        schedule_timeout((3000 * HZ + 999) / 1000);
     553                } else {
     554                        mdelay(3000);
     555                }
     556        }
     557        if (hdsp->state & HDSP_InitializationComplete) {
     558                snd_printk("firmware loaded from cache, restoring defaults\n");
     559                spin_lock_irqsave(&hdsp->lock, flags);
     560                snd_hdsp_set_defaults(hdsp);
     561                spin_unlock_irqrestore(&hdsp->lock, flags);
     562        }
     563       
     564        hdsp->state |= HDSP_FirmwareLoaded;
     565
     566        return 0;
     567}
     568
     569static inline int hdsp_get_iobox_version (hdsp_t *hdsp)
     570{
     571        int err;
     572       
     573        if (hdsp_check_for_iobox (hdsp)) {
     574                return -EIO;
     575        }
     576
     577        if ((err = snd_hdsp_initialize_input_enable(hdsp)) < 0) {
     578                return err;
     579        }
     580               
     581        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     582       
     583                hdsp_write (hdsp, HDSP_jtagReg, HDSP_PROGRAM);
     584                hdsp_write (hdsp, HDSP_fifoData, 0);
     585                if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
     586                        return -EIO;
     587                }
     588
     589                hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     590                hdsp_write (hdsp, HDSP_fifoData, 0);
     591
     592                if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
     593                        hdsp->io_type = Multiface;
     594                        hdsp_write (hdsp, HDSP_jtagReg, HDSP_VERSION_BIT);
     595                        hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
     596                        hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
     597                } else {
     598                        hdsp->io_type = Digiface;
     599                }
     600        } else {
     601                /* firmware was already loaded, get iobox type */
     602                if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
     603                        hdsp->io_type = Multiface;
     604                } else {
     605                        hdsp->io_type = Digiface;
     606                }
     607        }
     608        return 0;
     609}
     610
     611
     612static inline int hdsp_check_for_firmware (hdsp_t *hdsp)
     613{
     614        if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     615                snd_printk("firmware not present.\n");
     616                hdsp->state &= ~HDSP_FirmwareLoaded;
     617                return -EIO;
     618        }
     619        return 0;
     620}
     621
    447622
    448623static inline int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
     
    454629        */
    455630       
    456         for (i = 0; i < timeout; i++)
     631        for (i = 0; i < timeout; i++) {
     632
    457633                if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
    458634                        return 0;
     635
     636                /* not very friendly, but we only do this during a firmware
     637                   load and changing the mixer, so we just put up with it.
     638                */
     639
     640                udelay (100);
     641        }
    459642
    460643        snd_printk ("wait for FIFO status <= %d failed after %d iterations\n",
     
    475658        unsigned int ad;
    476659
    477         if (addr >= HDSP_MATRIX_MIXER_SIZE)
    478                 return -1;
    479 
    480         ad = data + addr * 65536;
    481 
    482         if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
    483                 return -1;
    484         }
    485         hdsp_write (hdsp, HDSP_fifoData, ad);
    486         hdsp->mixer_matrix[addr] = data;
     660        if (hdsp_is_9652 (hdsp)) {
     661
     662                if ((ad = addr/2) < 676) {
     663
     664                        /* from martin björnsen:
     665
     666                           "You can only write dwords to the
     667                           mixer memory which contain two
     668                           mixer values in the low and high
     669                           word. So if you want to change
     670                           value 0 you have to read value 1
     671                           from the cache and write both to
     672                           the first dword in the mixer
     673                           memory."
     674                        */
     675
     676                        hdsp->mixer_matrix[addr] = data;
     677                        hdsp_write (hdsp, 1024 + ad,
     678                                    (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
     679                                    hdsp->mixer_matrix[addr&0x7fe]);
     680                        return 0;
     681                } else {
     682                        return -1;
     683                }
     684               
     685
     686        } else {
     687                if (addr >= HDSP_MATRIX_MIXER_SIZE)
     688                        return -1;
     689               
     690                ad = (addr << 16) + data;
     691               
     692                if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
     693                        return -1;
     694                }
     695
     696                hdsp_write (hdsp, HDSP_fifoData, ad);
     697                hdsp->mixer_matrix[addr] = data;
     698
     699        }
    487700
    488701        return 0;
     
    503716}
    504717
    505 static inline int hdsp_system_sample_rate (hdsp_t *hdsp)
     718static inline int hdsp_external_sample_rate (hdsp_t *hdsp)
    506719{
    507720        unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
     
    515728        case HDSP_systemFrequency88_2: return 88200;
    516729        case HDSP_systemFrequency96:   return 96000;
    517         default:                       return 0;
     730        default:
     731                return 0;
    518732        }
    519733}
     
    527741                return 0;
    528742        }
    529 
     743       
    530744        switch (rate_bits) {
    531745        case HDSP_spdifFrequency32KHz: return 32000;
     
    536750        case HDSP_spdifFrequency96KHz: return 96000;
    537751        default:
    538                 snd_printk ("unknown frequency status; bits = 0x%x, status = 0x%x", rate_bits, status);
     752                snd_printk ("unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
    539753                return 0;
    540754        }
     
    565779static inline void hdsp_reset_hw_pointer(hdsp_t *hdsp)
    566780{
    567 #if 0
    568         /* reset the hw pointer to zero. We do this by writing to 8
    569            registers, each of which is a 32bit wide register, and set
    570            them all to zero.
    571         */
    572 
    573         for (i = 0; i < 8; ++i) {
    574                 hdsp_write(hdsp, i, 0);
    575                 udelay(10);
    576         }
    577 #endif
     781        hdsp_write (hdsp, HDSP_resetPointer, 0);
    578782}
    579783
     
    620824}
    621825
    622 static int hdsp_set_rate(hdsp_t *hdsp, int rate)
     826static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
    623827{
    624828        int reject_if_open = 0;
    625829        int current_rate;
    626 
    627         if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
    628                 snd_printk ("device is not running as a clock master: cannot set sample rate.\n");
    629                 return -1;
    630         }
     830        int rate_bits;
     831
     832        if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
     833                if (called_internally) {
     834                        /* request from ctl or card initialization */
     835                        snd_printk("device is not running as a clock master: cannot set sample rate.\n");
     836                        return -1;
     837                } else {               
     838                        /* hw_param request while in AutoSync mode */
     839                        int external_freq = hdsp_external_sample_rate(hdsp);
     840                        int spdif_freq = hdsp_spdif_sample_rate(hdsp);
     841               
     842                        if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
     843                                snd_printk("Detected ADAT in double speed mode\n");
     844                        } else if (rate != external_freq) {
     845                                snd_printk("No AutoSync source for requested rate\n");
     846                                return -1;
     847                        }               
     848                }       
     849        }
     850
     851        current_rate = hdsp->system_sample_rate;
    631852
    632853        /* Changing from a "single speed" to a "double speed" rate is
     
    638859           Note that a similar but essentially insoluble problem
    639860           exists for externally-driven rate changes. All we can do
    640            is to flag rate changes in the read/write routines.
    641          */
     861           is to flag rate changes in the read/write routines.  */
    642862
    643863        spin_lock_irq(&hdsp->lock);
    644         current_rate = hdsp_system_sample_rate(hdsp);
    645864
    646865        switch (rate) {
     
    649868                        reject_if_open = 1;
    650869                }
    651                 rate = HDSP_Frequency32KHz;
     870                rate_bits = HDSP_Frequency32KHz;
    652871                break;
    653872        case 44100:
     
    655874                        reject_if_open = 1;
    656875                }
    657                 rate = HDSP_Frequency44_1KHz;
     876                rate_bits = HDSP_Frequency44_1KHz;
    658877                break;
    659878        case 48000:
     
    661880                        reject_if_open = 1;
    662881                }
    663                 rate = HDSP_Frequency48KHz;
     882                rate_bits = HDSP_Frequency48KHz;
    664883                break;
    665884        case 64000:
    666                 if (current_rate < 48000) {
     885                if (current_rate <= 48000) {
    667886                        reject_if_open = 1;
    668887                }
    669                 rate = HDSP_Frequency64KHz;
     888                rate_bits = HDSP_Frequency64KHz;
    670889                break;
    671890        case 88200:
    672                 if (current_rate < 48000) {
     891                if (current_rate <= 48000) {
    673892                        reject_if_open = 1;
    674893                }
    675                 rate = HDSP_Frequency88_2KHz;
     894                rate_bits = HDSP_Frequency88_2KHz;
    676895                break;
    677896        case 96000:
    678                 if (current_rate < 48000) {
     897                if (current_rate <= 48000) {
    679898                        reject_if_open = 1;
    680899                }
    681                 rate = HDSP_Frequency96KHz;
     900                rate_bits = HDSP_Frequency96KHz;
    682901                break;
    683902        default:
     903                spin_unlock_irq(&hdsp->lock);
    684904                return -EINVAL;
    685905        }
     
    694914
    695915        hdsp->control_register &= ~HDSP_FrequencyMask;
    696         hdsp->control_register |= rate;
     916        hdsp->control_register |= rate_bits;
    697917        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
    698918
     
    700920                hdsp->channel_map = channel_map_ds;
    701921        } else {
    702                 switch (hdsp->type) {
     922                switch (hdsp->io_type) {
    703923                case Multiface:
    704924                        hdsp->channel_map = channel_map_mf_ss;
     
    707927                        hdsp->channel_map = channel_map_df_ss;
    708928                        break;
    709                 }
     929                default:
     930                        /* should never happen */
     931                        break;
     932                }
     933        }
     934       
     935        hdsp->system_sample_rate = rate;
     936       
     937        if (reject_if_open) {
     938                hdsp_update_simple_mixer_controls (hdsp);
    710939        }
    711940
     
    727956                if (enable) {
    728957                        for (i = 0; i < 26; i++) {
    729                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(i,i), UNITY_GAIN);
     958                                hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), UNITY_GAIN);
    730959                        }
    731960                } else {
    732961                        for (i = 0; i < 26; i++) {
    733                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(i,i), MINUS_INFINITY_GAIN);
     962                                hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), MINUS_INFINITY_GAIN);
    734963                        }
    735964                }
     
    742971                mapped_channel = hdsp->channel_map[channel];
    743972
     973                snd_assert(mapped_channel > -1, return);
     974
    744975                if (enable) {
    745                         hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), UNITY_GAIN);
     976                        hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), UNITY_GAIN);
    746977                } else {
    747                         hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), MINUS_INFINITY_GAIN);
     978                        hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
    748979                }
    749980        }
     
    8091040static inline int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
    8101041{
     1042        int fifo_bytes_used;
     1043
    8111044        if (id) {
    812                 return (hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff) < 128;
     1045                fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
    8131046        } else {
    814                 return (hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff)< 128;
     1047                fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
     1048        }
     1049
     1050        if (fifo_bytes_used < 128) {
     1051                return  128 - fifo_bytes_used;
     1052        } else {
     1053                return 0;
    8151054        }
    8161055}
     
    8271066        unsigned long flags;
    8281067        int n_pending;
    829         int clear_timer = 0;
    8301068        int to_write;
    8311069        int i;
     
    8351073               
    8361074        spin_lock_irqsave (&hmidi->lock, flags);
    837 
    8381075        if (hmidi->output) {
    8391076                if (!snd_rawmidi_transmit_empty (hmidi->output)) {
     
    8451082                                        for (i = 0; i < to_write; ++i)
    8461083                                                snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
    847                                 } else {
    848                                         clear_timer = 1;
    8491084                                }
    8501085                        }
    851                 } else {
    852                         clear_timer = 1;
    853                 }
    854 
    855                 if (clear_timer && hmidi->istimer && --hmidi->istimer <= 0) {
    856                         del_timer(&hmidi->timer);
    857                 }
    858         }
    859 
     1086                }
     1087        }
    8601088        spin_unlock_irqrestore (&hmidi->lock, flags);
    8611089        return 0;
     
    8701098
    8711099        spin_lock_irqsave (&hmidi->lock, flags);
    872 
    8731100        if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
    8741101                if (hmidi->input) {
     
    8881115                        }
    8891116                }
    890         }
     1117        }
     1118        hmidi->pending = 0;
     1119        if (hmidi->id) {
     1120                hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
     1121        } else {
     1122                hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
     1123        }
     1124        hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
    8911125        spin_unlock_irqrestore (&hmidi->lock, flags);
    8921126        return snd_hdsp_midi_output_write (hmidi);
     
    9631197        }
    9641198        spin_unlock_irqrestore (&hmidi->lock, flags);
     1199        if (up)
     1200                snd_hdsp_midi_output_write(hmidi);
    9651201}
    9661202
     
    10461282        hdsp->midi[id].hdsp = hdsp;
    10471283        hdsp->midi[id].istimer = 0;
     1284        hdsp->midi[id].pending = 0;
    10481285        spin_lock_init (&hdsp->midi[id].lock);
    10491286
     
    11681405
    11691406#define HDSP_SPDIF_IN(xname, xindex) \
    1170 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     1407{ .iface = SNDRV_CTL_ELEM_IFACE_PCM,  \
     1408  .name = xname, \
     1409  .index = xindex, \
    11711410  .info = snd_hdsp_info_spdif_in, \
    1172   .get = snd_hdsp_get_spdif_in, .put = snd_hdsp_put_spdif_in }
     1411  .get = snd_hdsp_get_spdif_in, \
     1412  .put = snd_hdsp_put_spdif_in }
    11731413
    11741414static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
     
    12011441{
    12021442        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1203         unsigned long flags;
    1204        
    1205         spin_lock_irqsave(&hdsp->lock, flags);
     1443       
    12061444        ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
    1207         spin_unlock_irqrestore(&hdsp->lock, flags);
    12081445        return 0;
    12091446}
     
    12281465
    12291466#define HDSP_SPDIF_OUT(xname, xindex) \
    1230 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
    1231   .info = snd_hdsp_info_spdif_out, \
     1467{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1468  .info = snd_hdsp_info_spdif_bits, \
    12321469  .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
    12331470
     
    12481485}
    12491486
    1250 static int snd_hdsp_info_spdif_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1487static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    12511488{
    12521489        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     
    12601497{
    12611498        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1262         unsigned long flags;
    1263        
    1264         spin_lock_irqsave(&hdsp->lock, flags);
     1499       
    12651500        ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
    1266         spin_unlock_irqrestore(&hdsp->lock, flags);
    12671501        return 0;
    12681502}
     
    12851519}
    12861520
    1287 #define HDSP_SYNC_PREF(xname, xindex) \
    1288 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
    1289   .info = snd_hdsp_info_sync_pref, \
    1290   .get = snd_hdsp_get_sync_pref, .put = snd_hdsp_put_sync_pref }
    1291 
    1292 static int hdsp_sync_pref(hdsp_t *hdsp)
     1521#define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
     1522{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1523  .info = snd_hdsp_info_spdif_bits, \
     1524  .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
     1525
     1526static int hdsp_spdif_professional(hdsp_t *hdsp)
     1527{
     1528        return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
     1529}
     1530
     1531static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
     1532{
     1533        if (val) {
     1534                hdsp->control_register |= HDSP_SPDIFProfessional;
     1535        } else {
     1536                hdsp->control_register &= ~HDSP_SPDIFProfessional;
     1537        }
     1538        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1539        return 0;
     1540}
     1541
     1542static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1543{
     1544        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1545       
     1546        ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
     1547        return 0;
     1548}
     1549
     1550static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1551{
     1552        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1553        unsigned long flags;
     1554        int change;
     1555        unsigned int val;
     1556       
     1557        if (!snd_hdsp_use_is_exclusive(hdsp))
     1558                return -EBUSY;
     1559        val = ucontrol->value.integer.value[0] & 1;
     1560        spin_lock_irqsave(&hdsp->lock, flags);
     1561        change = (int)val != hdsp_spdif_professional(hdsp);
     1562        hdsp_set_spdif_professional(hdsp, val);
     1563        spin_unlock_irqrestore(&hdsp->lock, flags);
     1564        return change;
     1565}
     1566
     1567#define HDSP_SPDIF_EMPHASIS(xname, xindex) \
     1568{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1569  .info = snd_hdsp_info_spdif_bits, \
     1570  .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
     1571
     1572static int hdsp_spdif_emphasis(hdsp_t *hdsp)
     1573{
     1574        return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
     1575}
     1576
     1577static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
     1578{
     1579        if (val) {
     1580                hdsp->control_register |= HDSP_SPDIFEmphasis;
     1581        } else {
     1582                hdsp->control_register &= ~HDSP_SPDIFEmphasis;
     1583        }
     1584        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1585        return 0;
     1586}
     1587
     1588static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1589{
     1590        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1591       
     1592        ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
     1593        return 0;
     1594}
     1595
     1596static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1597{
     1598        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1599        unsigned long flags;
     1600        int change;
     1601        unsigned int val;
     1602       
     1603        if (!snd_hdsp_use_is_exclusive(hdsp))
     1604                return -EBUSY;
     1605        val = ucontrol->value.integer.value[0] & 1;
     1606        spin_lock_irqsave(&hdsp->lock, flags);
     1607        change = (int)val != hdsp_spdif_emphasis(hdsp);
     1608        hdsp_set_spdif_emphasis(hdsp, val);
     1609        spin_unlock_irqrestore(&hdsp->lock, flags);
     1610        return change;
     1611}
     1612
     1613#define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
     1614{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
     1615  .info = snd_hdsp_info_spdif_bits, \
     1616  .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
     1617
     1618static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
     1619{
     1620        return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
     1621}
     1622
     1623static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
     1624{
     1625        if (val) {
     1626                hdsp->control_register |= HDSP_SPDIFNonAudio;
     1627        } else {
     1628                hdsp->control_register &= ~HDSP_SPDIFNonAudio;
     1629        }
     1630        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1631        return 0;
     1632}
     1633
     1634static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1635{
     1636        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1637       
     1638        ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
     1639        return 0;
     1640}
     1641
     1642static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1643{
     1644        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1645        unsigned long flags;
     1646        int change;
     1647        unsigned int val;
     1648       
     1649        if (!snd_hdsp_use_is_exclusive(hdsp))
     1650                return -EBUSY;
     1651        val = ucontrol->value.integer.value[0] & 1;
     1652        spin_lock_irqsave(&hdsp->lock, flags);
     1653        change = (int)val != hdsp_spdif_nonaudio(hdsp);
     1654        hdsp_set_spdif_nonaudio(hdsp, val);
     1655        spin_unlock_irqrestore(&hdsp->lock, flags);
     1656        return change;
     1657}
     1658
     1659#define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
     1660{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1661  .name = xname, \
     1662  .index = xindex, \
     1663  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1664  .info = snd_hdsp_info_spdif_sample_rate, \
     1665  .get = snd_hdsp_get_spdif_sample_rate \
     1666}
     1667
     1668static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1669{
     1670        static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None"};
     1671        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1672        uinfo->count = 1;
     1673        uinfo->value.enumerated.items = 7 ;
     1674        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1675                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1676        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1677        return 0;
     1678}
     1679
     1680static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1681{
     1682        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1683       
     1684        switch (hdsp_spdif_sample_rate(hdsp)) {
     1685        case 32000:
     1686                ucontrol->value.enumerated.item[0] = 0;
     1687                break;
     1688        case 44100:
     1689                ucontrol->value.enumerated.item[0] = 1;
     1690                break;
     1691        case 48000:
     1692                ucontrol->value.enumerated.item[0] = 2;
     1693                break;
     1694        case 64000:
     1695                ucontrol->value.enumerated.item[0] = 3;
     1696                break;
     1697        case 88200:
     1698                ucontrol->value.enumerated.item[0] = 4;
     1699                break;
     1700        case 96000:
     1701                ucontrol->value.enumerated.item[0] = 5;
     1702                break;
     1703        default:
     1704                ucontrol->value.enumerated.item[0] = 6;         
     1705        }
     1706        return 0;
     1707}
     1708
     1709#define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
     1710{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1711  .name = xname, \
     1712  .index = xindex, \
     1713  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1714  .info = snd_hdsp_info_system_sample_rate, \
     1715  .get = snd_hdsp_get_system_sample_rate \
     1716}
     1717
     1718static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1719{
     1720        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     1721        uinfo->count = 1;
     1722        return 0;
     1723}
     1724
     1725static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1726{
     1727        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1728       
     1729        ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
     1730        return 0;
     1731}
     1732
     1733#define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
     1734{ .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     1735  .name = xname, \
     1736  .index = xindex, \
     1737  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1738  .info = snd_hdsp_info_autosync_sample_rate, \
     1739  .get = snd_hdsp_get_autosync_sample_rate \
     1740}
     1741
     1742static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1743{
     1744        static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None"}; 
     1745        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1746        uinfo->count = 1;
     1747        uinfo->value.enumerated.items = 7 ;
     1748        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1749                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1750        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1751        return 0;
     1752}
     1753
     1754static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1755{
     1756        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1757       
     1758        switch (hdsp_external_sample_rate(hdsp)) {
     1759        case 32000:
     1760                ucontrol->value.enumerated.item[0] = 0;
     1761                break;
     1762        case 44100:
     1763                ucontrol->value.enumerated.item[0] = 1;
     1764                break;
     1765        case 48000:
     1766                ucontrol->value.enumerated.item[0] = 2;
     1767                break;
     1768        case 64000:
     1769                ucontrol->value.enumerated.item[0] = 3;
     1770                break;
     1771        case 88200:
     1772                ucontrol->value.enumerated.item[0] = 4;
     1773                break;
     1774        case 96000:
     1775                ucontrol->value.enumerated.item[0] = 5;
     1776                break;
     1777        default:
     1778                ucontrol->value.enumerated.item[0] = 6;         
     1779        }
     1780        return 0;
     1781}
     1782
     1783#define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
     1784{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1785  .name = xname, \
     1786  .index = xindex, \
     1787  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     1788  .info = snd_hdsp_info_system_clock_mode, \
     1789  .get = snd_hdsp_get_system_clock_mode \
     1790}
     1791
     1792static int hdsp_system_clock_mode(hdsp_t *hdsp)
     1793{
     1794        if (hdsp->control_register & HDSP_ClockModeMaster) {
     1795                return 0;
     1796        } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
     1797                        return 0;
     1798        }
     1799        return 1;
     1800}
     1801
     1802static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1803{
     1804        static char *texts[] = {"Master", "Slave" };
     1805       
     1806        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1807        uinfo->count = 1;
     1808        uinfo->value.enumerated.items = 2;
     1809        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1810                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1811        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1812        return 0;
     1813}
     1814
     1815static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1816{
     1817        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1818       
     1819        ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
     1820        return 0;
     1821}
     1822
     1823#define HDSP_CLOCK_SOURCE(xname, xindex) \
     1824{ .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     1825  .name = xname, \
     1826  .index = xindex, \
     1827  .info = snd_hdsp_info_clock_source, \
     1828  .get = snd_hdsp_get_clock_source, \
     1829  .put = snd_hdsp_put_clock_source \
     1830}
     1831
     1832static int hdsp_clock_source(hdsp_t *hdsp)
     1833{
     1834        if (hdsp->control_register & HDSP_ClockModeMaster) {
     1835                switch (hdsp->system_sample_rate) {
     1836                case 32000:
     1837                        return 1;
     1838                case 44100:
     1839                        return 2;
     1840                case 48000:
     1841                        return 3;
     1842                case 64000:
     1843                        return 4;
     1844                case 88200:
     1845                        return 5;
     1846                case 96000:
     1847                        return 6;
     1848                default:
     1849                        return 3;       
     1850                }
     1851        } else {
     1852                return 0;
     1853        }
     1854}
     1855
     1856static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
     1857{
     1858        int rate;
     1859        switch (mode) {
     1860        case HDSP_CLOCK_SOURCE_AUTOSYNC:
     1861                if (hdsp_external_sample_rate(hdsp) != 0) {
     1862                    hdsp->control_register &= ~HDSP_ClockModeMaster;           
     1863                    hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1864                    return 0;
     1865                }
     1866                return -1;
     1867        case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
     1868                rate = 32000;
     1869                break;
     1870        case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
     1871                rate = 44100;
     1872                break;     
     1873        case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
     1874                rate = 48000;
     1875                break;
     1876        case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
     1877                rate = 64000;
     1878                break;
     1879        case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
     1880                rate = 88200;
     1881                break;
     1882        case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
     1883                rate = 96000;
     1884                break;
     1885        default:
     1886                rate = 48000;
     1887        }
     1888        hdsp->control_register |= HDSP_ClockModeMaster;
     1889        hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     1890        hdsp_set_rate(hdsp, rate, 1);
     1891        return 0;
     1892}
     1893
     1894static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1895{
     1896        static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz" };
     1897       
     1898        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     1899        uinfo->count = 1;
     1900        uinfo->value.enumerated.items = 7;
     1901        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     1902                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     1903        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     1904        return 0;
     1905}
     1906
     1907static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1908{
     1909        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1910       
     1911        ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
     1912        return 0;
     1913}
     1914
     1915static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     1916{
     1917        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     1918        unsigned long flags;
     1919        int change;
     1920        int val;
     1921       
     1922        if (!snd_hdsp_use_is_exclusive(hdsp))
     1923                return -EBUSY;
     1924        val = ucontrol->value.enumerated.item[0];
     1925        if (val < 0) val = 0;
     1926        if (val > 6) val = 6;
     1927        spin_lock_irqsave(&hdsp->lock, flags);
     1928        if (val != hdsp_clock_source(hdsp)) {
     1929                change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
     1930        } else {
     1931                change = 0;
     1932        }
     1933        spin_unlock_irqrestore(&hdsp->lock, flags);
     1934        return change;
     1935}
     1936
     1937#define HDSP_PREF_SYNC_REF(xname, xindex) \
     1938{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     1939  .name = xname, \
     1940  .index = xindex, \
     1941  .info = snd_hdsp_info_pref_sync_ref, \
     1942  .get = snd_hdsp_get_pref_sync_ref, \
     1943  .put = snd_hdsp_put_pref_sync_ref \
     1944}
     1945
     1946static int hdsp_pref_sync_ref(hdsp_t *hdsp)
    12931947{
    12941948        /* Notice that this looks at the requested sync source,
    12951949           not the one actually in use.
    12961950        */
    1297        
    1298         if (hdsp->control_register & HDSP_ClockModeMaster) {
    1299                 return HDSP_SYNC_FROM_SELF;
    1300         }
    13011951
    13021952        switch (hdsp->control_register & HDSP_SyncRefMask) {
     
    13141964                return HDSP_SYNC_FROM_ADAT_SYNC;
    13151965        default:
    1316                 return HDSP_SYNC_FROM_SELF;
    1317         }
    1318         return 0;
    1319 }
    1320 
    1321 static int hdsp_set_sync_pref(hdsp_t *hdsp, int pref)
     1966                return HDSP_SYNC_FROM_WORD;
     1967        }
     1968        return 0;
     1969}
     1970
     1971static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
    13221972{
    13231973        hdsp->control_register &= ~HDSP_SyncRefMask;
    13241974        switch (pref) {
    13251975        case HDSP_SYNC_FROM_ADAT1:
    1326                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13271976                hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
    13281977                break;
    13291978        case HDSP_SYNC_FROM_ADAT2:
    1330                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13311979                hdsp->control_register |= HDSP_SyncRef_ADAT2;
    13321980                break;
    13331981        case HDSP_SYNC_FROM_ADAT3:
    1334                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13351982                hdsp->control_register |= HDSP_SyncRef_ADAT3;
    13361983                break;
    13371984        case HDSP_SYNC_FROM_SPDIF:
    1338                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13391985                hdsp->control_register |= HDSP_SyncRef_SPDIF;
    13401986                break;
    13411987        case HDSP_SYNC_FROM_WORD:
    1342                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13431988                hdsp->control_register |= HDSP_SyncRef_WORD;
    13441989                break;
    13451990        case HDSP_SYNC_FROM_ADAT_SYNC:
    1346                 hdsp->control_register &= ~HDSP_ClockModeMaster;
    13471991                hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
    1348                 break;
    1349         case HDSP_SYNC_FROM_SELF:
    1350                 hdsp->control_register |= HDSP_ClockModeMaster;
    13511992                break;
    13521993        default:
     
    13571998}
    13581999
    1359 static int snd_hdsp_info_sync_pref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1360 {
    1361         static char *texts[] = {"Internal", "Word", "ADAT Sync", "IEC958", "ADAT1", "ADAT2", "ADAT3" };
     2000static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2001{
     2002        static char *texts[] = {"Word", "ADAT Sync", "IEC958", "ADAT1", "ADAT2", "ADAT3" };
    13622003        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    13632004       
    13642005        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    13652006        uinfo->count = 1;
    1366         uinfo->value.enumerated.items = (hdsp->type == Digiface) ? 7 : 6;
     2007        uinfo->value.enumerated.items = (hdsp->io_type == Digiface) ? 6 : 4;
    13672008        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
    13682009                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     
    13712012}
    13722013
    1373 static int snd_hdsp_get_sync_pref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2014static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13742015{
    13752016        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1376         unsigned long flags;
    1377        
    1378         spin_lock_irqsave(&hdsp->lock, flags);
    1379         ucontrol->value.enumerated.item[0] = hdsp_sync_pref(hdsp);
    1380         spin_unlock_irqrestore(&hdsp->lock, flags);
    1381         return 0;
    1382 }
    1383 
    1384 static int snd_hdsp_put_sync_pref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2017       
     2018        ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
     2019        return 0;
     2020}
     2021
     2022static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13852023{
    13862024        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     
    13912029        if (!snd_hdsp_use_is_exclusive(hdsp))
    13922030                return -EBUSY;
    1393         max = hdsp->ss_channels == (hdsp->type == Digiface) ? 7 : 6;
     2031        max = (hdsp->io_type == Digiface) ? 6 : 4;
    13942032        val = ucontrol->value.enumerated.item[0] % max;
    13952033        spin_lock_irqsave(&hdsp->lock, flags);
    1396         change = (int)val != hdsp_sync_pref(hdsp);
    1397         hdsp_set_sync_pref(hdsp, val);
     2034        change = (int)val != hdsp_pref_sync_ref(hdsp);
     2035        hdsp_set_pref_sync_ref(hdsp, val);
    13982036        spin_unlock_irqrestore(&hdsp->lock, flags);
    13992037        return change;
    14002038}
    14012039
     2040#define HDSP_AUTOSYNC_REF(xname, xindex) \
     2041{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2042  .name = xname, \
     2043  .index = xindex, \
     2044  .access = SNDRV_CTL_ELEM_ACCESS_READ, \
     2045  .info = snd_hdsp_info_autosync_ref, \
     2046  .get = snd_hdsp_get_autosync_ref, \
     2047}
     2048
     2049static int hdsp_autosync_ref(hdsp_t *hdsp)
     2050{
     2051        /* This looks at the autosync selected sync reference */
     2052        unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
     2053
     2054        switch (status2 & HDSP_SelSyncRefMask) {
     2055        case HDSP_SelSyncRef_WORD:
     2056                return HDSP_AUTOSYNC_FROM_WORD;
     2057        case HDSP_SelSyncRef_ADAT_SYNC:
     2058                return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
     2059        case HDSP_SelSyncRef_SPDIF:
     2060                return HDSP_AUTOSYNC_FROM_SPDIF;
     2061        case HDSP_SelSyncRefMask:
     2062                return HDSP_AUTOSYNC_FROM_NONE;
     2063        case HDSP_SelSyncRef_ADAT1:
     2064                return HDSP_AUTOSYNC_FROM_ADAT1;
     2065        case HDSP_SelSyncRef_ADAT2:
     2066                return HDSP_AUTOSYNC_FROM_ADAT2;
     2067        case HDSP_SelSyncRef_ADAT3:
     2068                return HDSP_AUTOSYNC_FROM_ADAT3;
     2069        default:
     2070                return HDSP_AUTOSYNC_FROM_WORD;
     2071        }
     2072        return 0;
     2073}
     2074
     2075static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2076{
     2077        static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
     2078       
     2079        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2080        uinfo->count = 1;
     2081        uinfo->value.enumerated.items = 7;
     2082        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     2083                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     2084        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2085        return 0;
     2086}
     2087
     2088static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2089{
     2090        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
     2091       
     2092        ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
     2093        return 0;
     2094}
     2095
    14022096#define HDSP_PASSTHRU(xname, xindex) \
    1403 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2097{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2098  .name = xname, \
     2099  .index = xindex, \
    14042100  .info = snd_hdsp_info_passthru, \
    14052101  .put = snd_hdsp_put_passthru, \
    1406   .get = snd_hdsp_get_passthru }
     2102  .get = snd_hdsp_get_passthru \
     2103}
    14072104
    14082105static int snd_hdsp_info_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
     
    14472144
    14482145#define HDSP_LINE_OUT(xname, xindex) \
    1449 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2146{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2147  .name = xname, \
     2148  .index = xindex, \
    14502149  .info = snd_hdsp_info_line_out, \
    1451   .get = snd_hdsp_get_line_out, .put = snd_hdsp_put_line_out }
     2150  .get = snd_hdsp_get_line_out, \
     2151  .put = snd_hdsp_put_line_out \
     2152}
    14522153
    14532154static int hdsp_line_out(hdsp_t *hdsp)
     
    15052206
    15062207#define HDSP_MIXER(xname, xindex) \
    1507 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = xname, .index = xindex, \
     2208{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2209  .name = xname, \
     2210  .index = xindex, \
     2211  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
     2212                 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    15082213  .info = snd_hdsp_info_mixer, \
    1509   .get = snd_hdsp_get_mixer, .put = snd_hdsp_put_mixer }
     2214  .get = snd_hdsp_get_mixer, \
     2215  .put = snd_hdsp_put_mixer \
     2216}
    15102217
    15112218static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     
    15312238
    15322239        if (source > 25) {
    1533                 addr = PLAYBACK_TO_OUTPUT_KEY(source-26,destination);
     2240                addr = hdsp_playback_to_output_key(hdsp,source-26,destination);
    15342241        } else {
    1535                 addr = INPUT_TO_OUTPUT_KEY(source, destination);
     2242                addr = hdsp_input_to_output_key(hdsp,source, destination);
    15362243        }
    15372244       
    15382245        spin_lock_irqsave(&hdsp->lock, flags);
    1539         ucontrol->value.integer.value[0] = hdsp_read_gain (hdsp, addr);
     2246        ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
    15402247        spin_unlock_irqrestore(&hdsp->lock, flags);
    15412248        return 0;
     
    15592266
    15602267        if (source > 25) {
    1561                 addr = PLAYBACK_TO_OUTPUT_KEY(source-26, destination);
     2268                addr = hdsp_playback_to_output_key(hdsp,source-26, destination);
    15622269        } else {
    1563                 addr = INPUT_TO_OUTPUT_KEY(source, destination);
     2270                addr = hdsp_input_to_output_key(hdsp,source, destination);
    15642271        }
    15652272
     
    15842291                 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    15852292  .info = snd_hdsp_info_playback_mixer, \
    1586   .get = snd_hdsp_get_playback_mixer, .put = snd_hdsp_put_playback_mixer }
     2293  .get = snd_hdsp_get_playback_mixer, \
     2294  .put = snd_hdsp_put_playback_mixer \
     2295}
    15872296
    15882297static int snd_hdsp_info_playback_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     
    16012310        unsigned long flags;
    16022311        int addr;
    1603         int chn;
    1604 
    1605         chn = ucontrol->id.index - 1;
    1606         addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
     2312        int channel;
     2313        int mapped_channel;
     2314
     2315        channel = ucontrol->id.index - 1;
     2316
     2317        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
     2318       
     2319        if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
     2320                return -EINVAL;
     2321        }
     2322
     2323        addr = hdsp_playback_to_output_key(hdsp,mapped_channel, mapped_channel);
    16072324
    16082325        spin_lock_irqsave(&hdsp->lock, flags);
     
    16182335        int change;
    16192336        int addr;
    1620         int chn;
     2337        int channel;
     2338        int mapped_channel;
    16212339        int gain;
    16222340
     
    16242342                return -EBUSY;
    16252343       
    1626         chn = ucontrol->id.index - 1;
    1627         addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
     2344        channel = ucontrol->id.index - 1;
     2345
     2346        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
     2347       
     2348        if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
     2349                return -EINVAL;
     2350        }
     2351
     2352        addr = hdsp_playback_to_output_key(hdsp,mapped_channel, mapped_channel);
    16282353        gain = ucontrol->value.integer.value[0];
    16292354
     
    16372362}
    16382363
    1639 #define HDSP_PEAK_PLAYBACK \
    1640 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2364#define HDSP_WC_SYNC_CHECK(xname, xindex) \
     2365{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2366  .name = xname, \
     2367  .index = xindex, \
    16412368  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1642   .info = snd_hdsp_info_peak_playback, \
    1643   .get = snd_hdsp_get_peak_playback \
    1644 }
    1645 
    1646 static int snd_hdsp_info_peak_playback(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1647 {
    1648         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1649         uinfo->count = 2;
    1650         return 0;
    1651 }
    1652 
    1653 static int snd_hdsp_get_peak_playback(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2369  .info = snd_hdsp_info_sync_check, \
     2370  .get = snd_hdsp_get_wc_sync_check \
     2371}
     2372
     2373static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2374{
     2375        static char *texts[] = {"No Lock", "Lock", "Sync" };   
     2376        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
     2377        uinfo->count = 1;
     2378        uinfo->value.enumerated.items = 3;
     2379        if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
     2380                uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
     2381        strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
     2382        return 0;
     2383}
     2384
     2385static int hdsp_wc_sync_check(hdsp_t *hdsp)
     2386{
     2387        int status2 = hdsp_read(hdsp, HDSP_status2Register);
     2388        if (status2 & HDSP_wc_lock) {
     2389                if (status2 & HDSP_wc_sync) {
     2390                        return 2;
     2391                } else {
     2392                         return 1;
     2393                }
     2394        } else {               
     2395                return 0;
     2396        }
     2397        return 0;
     2398}
     2399
     2400static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    16542401{
    16552402        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1656         unsigned int peakval = hdsp_read (hdsp, HDSP_playbackPeakLevel + (4 * (ucontrol->id.index-1)));
    1657         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1658         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1659         return 0;
    1660 }
    1661 
    1662 #define HDSP_PEAK_INPUT \
    1663 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2403
     2404        ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
     2405        return 0;
     2406}
     2407
     2408#define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
     2409{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2410  .name = xname, \
     2411  .index = xindex, \
    16642412  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1665   .info = snd_hdsp_info_peak_input, \
    1666   .get = snd_hdsp_get_peak_input \
    1667 }
    1668 
    1669 static int snd_hdsp_info_peak_input(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1670 {
    1671         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1672         uinfo->count = 2;
    1673         return 0;
    1674 }
    1675 
    1676 static int snd_hdsp_get_peak_input(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2413  .info = snd_hdsp_info_sync_check, \
     2414  .get = snd_hdsp_get_spdif_sync_check \
     2415}
     2416
     2417static int hdsp_spdif_sync_check(hdsp_t *hdsp)
     2418{
     2419        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2420        if (status & HDSP_SPDIFErrorFlag) {
     2421                return 0;
     2422        } else {       
     2423                if (status & HDSP_SPDIFSync) {
     2424                        return 2;
     2425                } else {
     2426                        return 1;
     2427                }
     2428        }
     2429        return 0;
     2430}
     2431
     2432static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    16772433{
    16782434        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1679         unsigned int peakval = hdsp_read (hdsp, HDSP_inputPeakLevel + (4 * (ucontrol->id.index-1)));
    1680         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1681         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1682         return 0;
    1683 }
    1684 
    1685 #define HDSP_PEAK_OUTPUT \
    1686 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2435
     2436        ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
     2437        return 0;
     2438}
     2439
     2440#define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
     2441{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
     2442  .name = xname, \
     2443  .index = xindex, \
    16872444  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1688   .info = snd_hdsp_info_peak_output, \
    1689   .get = snd_hdsp_get_peak_output \
    1690 }
    1691 
    1692 static int snd_hdsp_info_peak_output(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1693 {
    1694         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1695         uinfo->count = 2;
    1696         return 0;
    1697 }
    1698 
    1699 static int snd_hdsp_get_peak_output(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2445  .info = snd_hdsp_info_sync_check, \
     2446  .get = snd_hdsp_get_adatsync_sync_check \
     2447}
     2448
     2449static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
     2450{
     2451        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2452        if (status & HDSP_TimecodeLock) {
     2453                if (status & HDSP_TimecodeSync) {
     2454                        return 2;
     2455                } else {
     2456                        return 1;
     2457                }
     2458        } else {
     2459                return 0;
     2460        }
     2461}       
     2462
     2463static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    17002464{
    17012465        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1702         unsigned int peakval = hdsp_read (hdsp, HDSP_outputPeakLevel + (4 * (ucontrol->id.index-1)));
    1703         ucontrol->value.integer.value[0] = peakval & 0xffffff00;  /* peak */
    1704         ucontrol->value.integer.value[1] = peakval & 0xf;         /* overs */
    1705         return 0;
    1706 }
    1707 
    1708 #define HDSP_RMS_INPUT \
    1709 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
     2466
     2467        ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
     2468        return 0;
     2469}
     2470
     2471#define HDSP_ADAT_SYNC_CHECK \
     2472{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
    17102473  .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1711   .info = snd_hdsp_info_rms_input, \
    1712   .get = snd_hdsp_get_rms_input \
    1713 }
    1714 
    1715 static int snd_hdsp_info_rms_input(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1716 {
    1717         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER64;
    1718         uinfo->count = 1;
    1719         return 0;
    1720 }
    1721 
    1722 static int snd_hdsp_get_rms_input(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1723 {
     2474  .info = snd_hdsp_info_sync_check, \
     2475  .get = snd_hdsp_get_adat_sync_check \
     2476}
     2477
     2478static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
     2479{       
     2480        int status = hdsp_read(hdsp, HDSP_statusRegister);
     2481       
     2482        if (status & (HDSP_Lock0>>idx)) {
     2483                if (status & (HDSP_Sync0>>idx)) {
     2484                        return 2;
     2485                } else {
     2486                        return 1;               
     2487                }
     2488        } else {
     2489                return 0;
     2490        }               
     2491}
     2492
     2493static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
     2494{
     2495        int offset;
    17242496        hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1725         ucontrol->value.integer64.value[0] = hdsp_read64 (hdsp, HDSP_inputRmsLevel + (8 * (ucontrol->id.index-1)));
    1726         return 0;
    1727 }
    1728 
    1729 #define HDSP_RMS_PLAYBACK \
    1730 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
    1731   .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
    1732   .info = snd_hdsp_info_rms_playback, \
    1733   .get = snd_hdsp_get_rms_playback \
    1734 }
    1735 
    1736 static int snd_hdsp_info_rms_playback(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    1737 {
    1738         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER64;
    1739         uinfo->count = 1;
    1740         return 0;
    1741 }
    1742 
    1743 static int snd_hdsp_get_rms_playback(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1744 {
    1745         hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
    1746         ucontrol->value.integer64.value[0] = hdsp_read64 (hdsp, HDSP_playbackRmsLevel + (8 * (ucontrol->id.index-1)));
     2497
     2498        offset = ucontrol->id.index - 1;
     2499        snd_assert(offset >= 0 || offset < ((hdsp->io_type == Digiface) ? 3 : 1), return -EINVAL);
     2500        ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
    17472501        return 0;
    17482502}
     
    17712525        .get =          snd_hdsp_control_spdif_mask_get,
    17722526        .private_value = IEC958_AES0_NONAUDIO |
    1773                         IEC958_AES0_PROFESSIONAL |
    1774                         IEC958_AES0_CON_EMPHASIS,                                                                                             
     2527                         IEC958_AES0_PROFESSIONAL |
     2528                         IEC958_AES0_CON_EMPHASIS,                                                                                           
    17752529},
    17762530{
     
    17812535        .get =          snd_hdsp_control_spdif_mask_get,
    17822536        .private_value = IEC958_AES0_NONAUDIO |
    1783                         IEC958_AES0_PROFESSIONAL |
    1784                         IEC958_AES0_PRO_EMPHASIS,
     2537                         IEC958_AES0_PROFESSIONAL |
     2538                         IEC958_AES0_PRO_EMPHASIS,
    17852539},
    17862540HDSP_MIXER("Mixer", 0),
    17872541HDSP_SPDIF_IN("IEC958 Input Connector", 0),
    17882542HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
    1789 HDSP_SYNC_PREF("Preferred Sync Source", 0),
     2543HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
     2544HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
     2545HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
     2546/* 'Sample Clock Source' complies with the alsa control naming scheme */
     2547HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
     2548HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
     2549HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
     2550HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
     2551HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
     2552HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
     2553/* 'External Rate' complies with the alsa control naming scheme */
     2554HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
     2555HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
     2556HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
     2557HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
    17902558HDSP_PASSTHRU("Passthru", 0),
    17912559HDSP_LINE_OUT("Line Out", 0),
     
    17952563
    17962564static snd_kcontrol_new_t snd_hdsp_playback_mixer = HDSP_PLAYBACK_MIXER;
    1797 static snd_kcontrol_new_t snd_hdsp_input_peak = HDSP_PEAK_INPUT;
    1798 static snd_kcontrol_new_t snd_hdsp_output_peak = HDSP_PEAK_OUTPUT;
    1799 static snd_kcontrol_new_t snd_hdsp_playback_peak = HDSP_PEAK_PLAYBACK;
    1800 static snd_kcontrol_new_t snd_hdsp_input_rms = HDSP_RMS_INPUT;
    1801 static snd_kcontrol_new_t snd_hdsp_playback_rms = HDSP_RMS_PLAYBACK;
     2565static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
     2566
     2567
     2568static int hdsp_update_simple_mixer_controls(hdsp_t *hdsp)
     2569{
     2570    int i;
     2571
     2572    for (i = hdsp->ds_channels; i < hdsp->ss_channels; ++i) {
     2573            if (hdsp->system_sample_rate > 48000) {
     2574                    hdsp->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_INACTIVE |
     2575                                                            SNDRV_CTL_ELEM_ACCESS_READ |
     2576                                                             SNDRV_CTL_ELEM_ACCESS_VOLATILE;
     2577            } else {
     2578                    hdsp->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
     2579                                                             SNDRV_CTL_ELEM_ACCESS_VOLATILE;
     2580            }
     2581            snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
     2582                            SNDRV_CTL_EVENT_MASK_INFO, &hdsp->playback_mixer_ctls[i]->id);
     2583    }
     2584
     2585    return 0;
     2586}
     2587
    18022588
    18032589int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
     
    18142600        }
    18152601
    1816         if (hdsp->type == Digiface) {
     2602        snd_hdsp_playback_mixer.name = "Chn";
     2603        snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
     2604
     2605        if (hdsp->io_type == Digiface) {
    18172606                limit = DIGIFACE_SS_CHANNELS;
    18182607        } else {
    18192608                limit = MULTIFACE_SS_CHANNELS;
    18202609        }
    1821 
     2610       
    18222611        /* The index values are one greater than the channel ID so that alsamixer
    18232612           will display them correctly. We want to use the index for fast lookup
     
    18262615        */
    18272616
    1828         snd_hdsp_playback_mixer.name = "Chn";
    1829         snd_hdsp_input_peak.name = "Input Peak";
    1830         snd_hdsp_output_peak.name = "Output Peak";
    1831         snd_hdsp_playback_peak.name = "Playback Peak";
    1832         snd_hdsp_playback_rms.name = "Playback RMS";
    1833         snd_hdsp_input_rms.name = "Input RMS";
    1834 
    18352617        for (idx = 0; idx < limit; ++idx) {
    18362618                snd_hdsp_playback_mixer.index = idx+1;
     
    18382620                        return err;
    18392621                }
    1840                 snd_hdsp_input_peak.index = idx+1;
    1841                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_input_peak, hdsp)))) {
    1842                         return err;
    1843                 }
    1844                 snd_hdsp_output_peak.index = idx+1;
    1845                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_output_peak, hdsp)))) {
    1846                         return err;
    1847                 }
    1848                 snd_hdsp_playback_peak.index = idx+1;
    1849                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_playback_peak, hdsp)))) {
    1850                         return err;
    1851                 }
    1852                 snd_hdsp_playback_rms.index = idx+1;
    1853                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_playback_rms, hdsp)))) {
    1854                         return err;
    1855                 }
    1856                 snd_hdsp_input_rms.index = idx+1;
    1857                 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_input_rms, hdsp)))) {
    1858                         return err;
     2622                hdsp->playback_mixer_ctls[idx] = kctl;
     2623        }
     2624       
     2625        /* ADAT SyncCheck status */
     2626        snd_hdsp_adat_sync_check.index = 1;
     2627        if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
     2628                return err;
     2629        }       
     2630        if (hdsp->io_type == Digiface) {
     2631                for (idx = 1; idx < 3; ++idx) {
     2632                        snd_hdsp_adat_sync_check.index = idx+1;
     2633                        if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
     2634                                return err;
     2635                        }
    18592636                }
    18602637        }
     
    18732650        unsigned int status;
    18742651        unsigned int status2;
    1875         char *requested_sync_ref;
     2652        char *pref_sync_ref;
     2653        char *autosync_ref;
     2654        char *system_clock_mode;
     2655        char *clock_source;
    18762656        int x;
    18772657
    18782658        if (hdsp_check_for_iobox (hdsp)) {
     2659                snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
    18792660                return;
    18802661        }
    18812662
     2663        if (hdsp_check_for_firmware(hdsp)) {
     2664                if (hdsp->state & HDSP_FirmwareCached) {
     2665                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     2666                                snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
     2667                                return;
     2668                        }
     2669                } else {
     2670                        snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
     2671                        return;
     2672                }
     2673        }
     2674       
    18822675        status = hdsp_read(hdsp, HDSP_statusRegister);
    18832676        status2 = hdsp_read(hdsp, HDSP_status2Register);
     
    19022695        x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
    19032696
    1904         snd_iprintf(buffer, "Latency: %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
     2697        snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
    19052698        snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
    19062699        snd_iprintf(buffer, "Passthru: %s\n", hdsp->passthru ? "yes" : "no");
     
    19092702        snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
    19102703
    1911         switch (hdsp_sync_pref (hdsp)) {
     2704        snd_iprintf(buffer, "\n");
     2705
     2706
     2707        switch (hdsp_clock_source(hdsp)) {
     2708        case HDSP_CLOCK_SOURCE_AUTOSYNC:
     2709                clock_source = "AutoSync";
     2710                break;
     2711        case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
     2712                clock_source = "Internal 32 kHz";
     2713                break;
     2714        case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
     2715                clock_source = "Internal 44.1 kHz";
     2716                break;
     2717        case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
     2718                clock_source = "Internal 48 kHz";
     2719                break;
     2720        case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
     2721                clock_source = "Internal 64 kHz";
     2722                break;
     2723        case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
     2724                clock_source = "Internal 88.2 kHz";
     2725                break;
     2726        case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
     2727                clock_source = "Internal 96 kHz";
     2728                break;
     2729        default:
     2730                clock_source = "Error";         
     2731        }
     2732        snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
     2733                       
     2734        if (hdsp_system_clock_mode(hdsp)) {
     2735                system_clock_mode = "Slave";
     2736        } else {
     2737                system_clock_mode = "Master";
     2738        }
     2739       
     2740        switch (hdsp_pref_sync_ref (hdsp)) {
    19122741        case HDSP_SYNC_FROM_WORD:
    1913                 requested_sync_ref = "Word";
     2742                pref_sync_ref = "Word Clock";
    19142743                break;
    19152744        case HDSP_SYNC_FROM_ADAT_SYNC:
    1916                 requested_sync_ref = "ADAT Sync";
     2745                pref_sync_ref = "ADAT Sync";
    19172746                break;
    19182747        case HDSP_SYNC_FROM_SPDIF:
    1919                 requested_sync_ref = "SPDIF";
     2748                pref_sync_ref = "SPDIF";
    19202749                break;
    19212750        case HDSP_SYNC_FROM_ADAT1:
    1922                 requested_sync_ref = "ADAT1";
     2751                pref_sync_ref = "ADAT1";
    19232752                break;
    19242753        case HDSP_SYNC_FROM_ADAT2:
    1925                 requested_sync_ref = "ADAT2";
     2754                pref_sync_ref = "ADAT2";
    19262755                break;
    19272756        case HDSP_SYNC_FROM_ADAT3:
    1928                 requested_sync_ref = "ADAT3";
    1929                 break;
    1930         case HDSP_SYNC_FROM_SELF:
     2757                pref_sync_ref = "ADAT3";
     2758                break;
    19312759        default:
    1932                 requested_sync_ref = "Master";
    1933                 break;
    1934         }
    1935 
    1936         if ((hdsp->control_register & HDSP_ClockModeMaster)) {
    1937                 snd_iprintf (buffer, "Sync reference: %s/Master (chosen)\n", requested_sync_ref);
    1938         } else if (hdsp_system_sample_rate(hdsp) == 0) {
    1939                 snd_iprintf (buffer, "Sync reference: %s/Master (forced)\n", requested_sync_ref);
    1940         } else {
    1941                 switch (status2 & HDSP_SelSyncRefMask) {
    1942                 case HDSP_SelSyncRef_ADAT1:
    1943                         snd_iprintf (buffer, "Sync reference: %s/ADAT1\n", requested_sync_ref);
    1944                         break;
    1945                 case HDSP_SelSyncRef_ADAT2:
    1946                         snd_iprintf (buffer, "Sync reference: %s/ADAT2\n", requested_sync_ref);
    1947                         break;
    1948                 case HDSP_SelSyncRef_ADAT3:
    1949                         snd_iprintf (buffer, "Sync reference: %s/ADAT3\n", requested_sync_ref);
    1950                         break;
    1951                 case HDSP_SelSyncRef_SPDIF:
    1952                         snd_iprintf (buffer, "Sync reference: %s/SPDIF\n", requested_sync_ref);
    1953                         break;
    1954                 case HDSP_SelSyncRef_WORD:
    1955                         snd_iprintf (buffer, "Sync reference: %s/WORD\n", requested_sync_ref);
    1956                         break;
    1957                 case HDSP_SelSyncRef_ADAT_SYNC:
    1958                         snd_iprintf (buffer, "Sync reference: %s/ADAT Sync\n", requested_sync_ref);
    1959                         break;
    1960                 default:
    1961                         snd_iprintf (buffer, "Sync reference: %s/Master (fallback)\n", requested_sync_ref);
    1962                         break;
    1963                 }
    1964         }
    1965         snd_iprintf (buffer, "Sample rate: %d\n", hdsp_system_sample_rate(hdsp));
    1966 
     2760                pref_sync_ref = "Word Clock";
     2761                break;
     2762        }
     2763        snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
     2764       
     2765        switch (hdsp_autosync_ref (hdsp)) {
     2766        case HDSP_AUTOSYNC_FROM_WORD:
     2767                autosync_ref = "Word Clock";
     2768                break;
     2769        case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
     2770                autosync_ref = "ADAT Sync";
     2771                break;
     2772        case HDSP_AUTOSYNC_FROM_SPDIF:
     2773                autosync_ref = "SPDIF";
     2774                break;
     2775        case HDSP_AUTOSYNC_FROM_NONE:
     2776                autosync_ref = "None";
     2777                break; 
     2778        case HDSP_AUTOSYNC_FROM_ADAT1:
     2779                autosync_ref = "ADAT1";
     2780                break;
     2781        case HDSP_AUTOSYNC_FROM_ADAT2:
     2782                autosync_ref = "ADAT2";
     2783                break;
     2784        case HDSP_AUTOSYNC_FROM_ADAT3:
     2785                autosync_ref = "ADAT3";
     2786                break;
     2787        default:
     2788                autosync_ref = "---";
     2789                break;
     2790        }
     2791        snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
     2792       
     2793        snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
     2794       
     2795        snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
     2796
     2797        snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
     2798               
    19672799        snd_iprintf(buffer, "\n");
    19682800
     
    20052837                snd_iprintf(buffer, "IEC958 NonAudio: off\n");
    20062838        }
    2007 
    2008         snd_iprintf(buffer, "\n");
    2009 
    20102839        if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
    20112840                snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
     
    20242853        }
    20252854
    2026         x = status & HDSP_Sync1;
    2027         if (status & HDSP_Lock1) {
    2028                 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
    2029         } else {
    2030                 snd_iprintf(buffer, "ADAT2: No Lock\n");
    2031         }
    2032 
    2033         if (hdsp->type == Digiface) {
     2855        switch (hdsp->io_type) {
     2856        case Digiface:
     2857                x = status & HDSP_Sync1;
     2858                if (status & HDSP_Lock1) {
     2859                        snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
     2860                } else {
     2861                        snd_iprintf(buffer, "ADAT2: No Lock\n");
     2862                }
    20342863                x = status & HDSP_Sync2;
    20352864                if (status & HDSP_Lock2) {
     
    20382867                        snd_iprintf(buffer, "ADAT3: No Lock\n");
    20392868                }
     2869        default:
     2870                /* relax */
     2871                break;
     2872        }
     2873
     2874        x = status & HDSP_SPDIFSync;
     2875        if (status & HDSP_SPDIFErrorFlag) {
     2876                snd_iprintf (buffer, "SPDIF: No Lock\n");
     2877        } else {
     2878                snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
     2879        }
     2880       
     2881        x = status2 & HDSP_wc_sync;
     2882        if (status2 & HDSP_wc_lock) {
     2883                snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
     2884        } else {
     2885                snd_iprintf (buffer, "Word Clock: No Lock\n");
     2886        }
     2887       
     2888        x = status & HDSP_TimecodeSync;
     2889        if (status & HDSP_TimecodeLock) {
     2890                snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
     2891        } else {
     2892                snd_iprintf(buffer, "ADAT Sync: No Lock\n");
    20402893        }
    20412894
     
    20542907        snd_info_entry_t *entry;
    20552908
    2056         if ((entry = snd_info_create_card_entry(hdsp->card, "hdsp", hdsp->card->proc_root)) !=
    2057             NULL) {
    2058                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    2059                 entry->private_data = hdsp;
    2060                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    2061                 entry->c.text.read_size = 256;
    2062                 entry->c.text.read = snd_hdsp_proc_read;
    2063                 if (snd_info_register(entry) < 0) {
    2064                         snd_info_free_entry(entry);
    2065                         entry = NULL;
    2066                 }
    2067         }
    2068         hdsp->proc_entry = entry;
    2069 }
    2070 
    2071 static void snd_hdsp_proc_done(hdsp_t *hdsp)
    2072 {
    2073         if (hdsp->proc_entry) {
    2074                 snd_info_unregister(hdsp->proc_entry);
    2075                 hdsp->proc_entry = NULL;
    2076         }
     2909        if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
     2910                snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
    20772911}
    20782912
     
    21592993}
    21602994
    2161 static void snd_hdsp_set_defaults(hdsp_t *hdsp)
     2995static int snd_hdsp_set_defaults(hdsp_t *hdsp)
    21622996{
    21632997        unsigned int i;
     
    21923026        }
    21933027
    2194         for (i = 0; i < 2048; i++)
    2195                 hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN);
    2196 
    2197         if (line_outs_monitor[hdsp->dev]) {
     3028        for (i = 0; i < (hdsp_is_9652(hdsp) ? 1352 : HDSP_MATRIX_MIXER_SIZE); i++) {
     3029                if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
     3030                        return -EIO;
     3031                }
     3032        }
     3033       
     3034        if (!hdsp_is_9652(hdsp) && line_outs_monitor[hdsp->dev]) {
    21983035               
    21993036                snd_printk ("sending all inputs and playback streams to line outs.\n");
     
    22053042                for (i = 0; i < HDSP_MAX_CHANNELS; i++) {
    22063043                        if (i & 1) {
    2207                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY (i, 26), UNITY_GAIN);
    2208                                 hdsp_write_gain (hdsp, PLAYBACK_TO_OUTPUT_KEY (i, 26), UNITY_GAIN);
     3044                                if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, 26), UNITY_GAIN) ||
     3045                                    hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, 26), UNITY_GAIN)) {
     3046                                    return -EIO;
     3047                                }   
    22093048                        } else {
    2210                                 hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY (i, 27), UNITY_GAIN);
    2211                                 hdsp_write_gain (hdsp, PLAYBACK_TO_OUTPUT_KEY (i, 27), UNITY_GAIN);
     3049                                if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, 27), UNITY_GAIN) ||
     3050                                    hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, 27), UNITY_GAIN)) {
     3051                                    return -EIO;
     3052                                }
    22123053                        }
    22133054                }
     
    22193060         */
    22203061
    2221         hdsp_set_rate(hdsp, 48000);
    2222 }
    2223 
    2224 void snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     3062        hdsp_set_rate(hdsp, 48000, 1);
     3063
     3064        return 0;
     3065}
     3066
     3067void hdsp_midi_tasklet(unsigned long arg)
     3068{
     3069        hdsp_t *hdsp = (hdsp_t *)arg;
     3070       
     3071        if (hdsp->midi[0].pending) {
     3072                snd_hdsp_midi_input_read (&hdsp->midi[0]);
     3073        }
     3074        if (hdsp->midi[1].pending) {
     3075                snd_hdsp_midi_input_read (&hdsp->midi[1]);
     3076        }
     3077}
     3078
     3079static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    22253080{
    22263081        hdsp_t *hdsp = (hdsp_t *) dev_id;
     
    22313086        unsigned int midi0status;
    22323087        unsigned int midi1status;
    2233 
     3088        int schedule = 0;
     3089       
    22343090        status = hdsp_read(hdsp, HDSP_statusRegister);
    22353091
     
    22393095
    22403096        if (!audio && !midi0 && !midi1) {
    2241                 return;
     3097                return IRQ_NONE;
    22423098        }
    22433099
     
    22463102        midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
    22473103        midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
    2248 
     3104       
    22493105        if (audio) {
    22503106                if (hdsp->capture_substream) {
     
    22563112                }
    22573113        }
    2258 
    2259         /* note: snd_hdsp_midi_input_read() calls output_write() because
    2260            output is not interrupt-driven ...
    2261         */
    2262 
    2263         if (midi0status)
    2264                 snd_hdsp_midi_input_read (&hdsp->midi[0]);
    2265         if (midi1status)
    2266                 snd_hdsp_midi_input_read (&hdsp->midi[1]);
     3114       
     3115        if (midi0 && midi0status) {
     3116                /* we disable interrupts for this input until processing is done */
     3117                hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
     3118                hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     3119                hdsp->midi[0].pending = 1;
     3120                schedule = 1;
     3121        }
     3122        if (midi1 && midi1status) {
     3123                /* we disable interrupts for this input until processing is done */
     3124                hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
     3125                hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
     3126                hdsp->midi[1].pending = 1;
     3127                schedule = 1;
     3128        }
     3129        if (schedule)
     3130            tasklet_hi_schedule(&hdsp->midi_tasklet);
     3131        return IRQ_HANDLED;
    22673132}
    22683133
     
    23033168        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23043169        snd_assert(channel_buf != NULL, return -EIO);
    2305         if (copy_from_user(channel_buf + pos * 4, src, count * 4))
    2306                 return -EFAULT;
     3170        copy_from_user(channel_buf + pos * 4, src, count * 4);
    23073171        return count;
    23083172}
     
    23183182        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23193183        snd_assert(channel_buf != NULL, return -EIO);
    2320         if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
    2321                 return -EFAULT;
     3184        copy_to_user(dst, channel_buf + pos * 4, count * 4);
    23223185        return count;
    23233186}
     
    23493212                runtime->status->hw_ptr = 0;
    23503213        if (other) {
    2351                 snd_pcm_substream_t *s = substream;
     3214                struct list_head *pos;
     3215                snd_pcm_substream_t *s;
    23523216                snd_pcm_runtime_t *oruntime = other->runtime;
    2353                 do {
    2354                         s = s->link_next;
     3217                snd_pcm_group_for_each(pos, substream) {
     3218                        s = snd_pcm_group_substream_entry(pos);
    23553219                        if (s == other) {
    23563220                                oruntime->status->hw_ptr = runtime->status->hw_ptr;
    23573221                                break;
    23583222                        }
    2359                 } while (s != substream);
     3223                }
    23603224        }
    23613225        return 0;
     
    23713235
    23723236        if (hdsp_check_for_iobox (hdsp)) {
     3237                return -EIO;
     3238        }
     3239
     3240        if (hdsp_check_for_firmware(hdsp)) {
     3241                if (hdsp->state & HDSP_FirmwareCached) {
     3242                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3243                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3244                        }
     3245                } else {
     3246                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3247                }
    23733248                return -EIO;
    23743249        }
     
    23933268                 */
    23943269
    2395                 if ((int)params_rate(params) != hdsp_system_sample_rate(hdsp)) {
     3270                if (params_rate(params) != hdsp->system_sample_rate) {
    23963271                        spin_unlock_irq(&hdsp->lock);
    23973272                        _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
     
    24173292         */
    24183293
    2419         if ((err = hdsp_set_rate(hdsp, params_rate(params))) < 0) {
     3294        if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
    24203295                _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
    24213296                return err;
     
    24343309{
    24353310        hdsp_t *hdsp = _snd_pcm_substream_chip(substream);
    2436         int chn;
     3311        int mapped_channel;
    24373312
    24383313        snd_assert(info->channel < HDSP_MAX_CHANNELS, return -EINVAL);
    24393314
    2440         if ((chn = hdsp->channel_map[info->channel]) < 0) {
     3315        if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
    24413316                return -EINVAL;
    24423317        }
    24433318
    2444         info->offset = chn * HDSP_CHANNEL_BUFFER_BYTES;
     3319        info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
    24453320        info->first = 0;
    24463321        info->step = 32;
     
    24753350       
    24763351        if (hdsp_check_for_iobox (hdsp)) {
     3352                return -EIO;
     3353        }
     3354
     3355        if (hdsp_check_for_firmware(hdsp)) {
     3356                if (hdsp->state & HDSP_FirmwareCached) {
     3357                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3358                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3359                        }
     3360                } else {
     3361                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3362                }
    24773363                return -EIO;
    24783364        }
     
    24983384
    24993385        if (other) {
    2500                 snd_pcm_substream_t *s = substream;
    2501                 do {
    2502                         s = s->link_next;
     3386                struct list_head *pos;
     3387                snd_pcm_substream_t *s;
     3388                snd_pcm_group_for_each(pos, substream) {
     3389                        s = snd_pcm_group_substream_entry(pos);
    25033390                        if (s == other) {
    25043391                                snd_pcm_trigger_done(s, substream);
     
    25093396                                goto _ok;
    25103397                        }
    2511                 } while (s != substream);
     3398                }
    25123399                if (cmd == SNDRV_PCM_TRIGGER_START) {
    25133400                        if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
     
    25413428
    25423429        if (hdsp_check_for_iobox (hdsp)) {
     3430                return -EIO;
     3431        }
     3432
     3433        if (hdsp_check_for_firmware(hdsp)) {
     3434                if (hdsp->state & HDSP_FirmwareCached) {
     3435                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3436                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3437                        }
     3438                } else {
     3439                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3440                }
    25433441                return -EIO;
    25443442        }
     
    25673465        .rate_min =             32000,
    25683466        .rate_max =             96000,
    2569         .channels_min =         10,
     3467        .channels_min =         14,
    25703468        .channels_max =         HDSP_MAX_CHANNELS,
    25713469        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
    2572         .period_bytes_min =     (64 * 4) *10,
     3470        .period_bytes_min =     (64 * 4) * 10,
    25733471        .period_bytes_max =     (8192 * 4) * HDSP_MAX_CHANNELS,
    25743472        .periods_min =          2,
    25753473        .periods_max =          2,
    2576         .fifo_size =            0,
     3474        .fifo_size =            0
    25773475};
    25783476
     
    25923490        .rate_min =             32000,
    25933491        .rate_max =             96000,
    2594         .channels_min =         10,
     3492        .channels_min =         14,
    25953493        .channels_max =         HDSP_MAX_CHANNELS,
    25963494        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
     
    25993497        .periods_min =          2,
    26003498        .periods_max =          2,
    2601         .fifo_size =            0,
     3499        .fifo_size =            0
    26023500};
    26033501
     
    26793577        }
    26803578
     3579        if (hdsp_check_for_firmware(hdsp)) {
     3580                if (hdsp->state & HDSP_FirmwareCached) {
     3581                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3582                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3583                        }
     3584                } else {
     3585                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3586                }
     3587                return -EIO;
     3588        }
     3589
    26813590        spin_lock_irqsave(&hdsp->lock, flags);
    26823591
     
    27103619
    27113620        hdsp->creg_spdif_stream = hdsp->creg_spdif;
    2712         hdsp->spdif_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     3621        hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    27133622        snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
    27143623                       SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
     
    27283637        spin_unlock_irqrestore(&hdsp->lock, flags);
    27293638
    2730         hdsp->spdif_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     3639        hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    27313640        snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
    27323641                       SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
     
    27423651
    27433652        if (hdsp_check_for_iobox (hdsp)) {
     3653                return -EIO;
     3654        }
     3655
     3656        if (hdsp_check_for_firmware(hdsp)) {
     3657                if (hdsp->state & HDSP_FirmwareCached) {
     3658                        if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
     3659                                snd_printk("Firmware loading from cache failed, please upload manually.\n");
     3660                        }
     3661                } else {
     3662                        snd_printk("No firmware loaded nor cached, please upload firmware.\n");
     3663                }
    27443664                return -EIO;
    27453665        }
     
    27913711}
    27923712
     3713static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
     3714{
     3715    /* we have nothing to initialize but the call is required */
     3716    return 0;
     3717}
     3718
     3719
     3720static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
     3721{
     3722        hdsp_t *hdsp = (hdsp_t *)hw->private_data;     
     3723        hdsp_peak_rms_t *peak_rms;
     3724        hdsp_firmware_t *firmware;
     3725        hdsp_mixer_t    *mixer;
     3726        hdsp_config_info_t info;
     3727        hdsp_version_t hdsp_version;
     3728        int i;
     3729        int err;
     3730        unsigned long flags;
     3731       
     3732        switch (cmd) {
     3733        case SNDRV_HDSP_IOCTL_GET_PEAK_RMS:
     3734                if (!(hdsp->state & HDSP_FirmwareLoaded)) {
     3735                        snd_printk("firmware needs to be uploaded to the card.\n");     
     3736                        return -EINVAL;
     3737                }
     3738                peak_rms = (hdsp_peak_rms_t *)arg;
     3739                if (copy_to_user_fromio((void *)peak_rms->playback_peaks, hdsp->iobase+HDSP_playbackPeakLevel, 26*4) != 0) {
     3740                        return -EFAULT;
     3741                }
     3742                if (copy_to_user_fromio((void *)peak_rms->input_peaks, hdsp->iobase+HDSP_inputPeakLevel, 26*4) != 0) {
     3743                        return -EFAULT;
     3744                }
     3745                if (copy_to_user_fromio((void *)peak_rms->output_peaks, hdsp->iobase+HDSP_outputPeakLevel, 28*4) != 0) {
     3746                        return -EFAULT;
     3747                }
     3748                if (copy_to_user_fromio((void *)peak_rms->playback_rms, hdsp->iobase+HDSP_playbackRmsLevel, 26*8) != 0) {
     3749                        return -EFAULT;
     3750                }
     3751                if (copy_to_user_fromio((void *)peak_rms->input_rms, hdsp->iobase+HDSP_inputRmsLevel, 26*8) != 0) {
     3752                        return -EFAULT;
     3753                }
     3754                break;
     3755        case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO:
     3756                if (!(hdsp->state & HDSP_FirmwareLoaded)) {
     3757                        snd_printk("Firmware needs to be uploaded to the card.\n");     
     3758                        return -EINVAL;
     3759                }
     3760                spin_lock_irqsave(&hdsp->lock, flags);
     3761                info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
     3762                info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
     3763                info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
     3764                info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
     3765                for (i = 0; i < ((hdsp->io_type != Multiface) ? 3 : 1); ++i) {
     3766                        info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
     3767                }
     3768                info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
     3769                info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
     3770                info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
     3771                info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
     3772                info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
     3773                info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
     3774                info.system_sample_rate = hdsp->system_sample_rate;
     3775                info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
     3776                info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
     3777                info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
     3778                info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
     3779                info.line_out = (unsigned char)hdsp_line_out(hdsp);
     3780                info.passthru = (unsigned char)hdsp->passthru;
     3781                spin_unlock_irqrestore(&hdsp->lock, flags);
     3782                if (copy_to_user((void *)arg, &info, sizeof(info)))
     3783                        return -EFAULT;
     3784                break;
     3785        case SNDRV_HDSP_IOCTL_GET_VERSION:
     3786                if (hdsp_is_9652(hdsp)) return -EINVAL;
     3787                if (hdsp->io_type == Undefined) {
     3788                        if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
     3789                                return err;
     3790                        }
     3791                }
     3792                hdsp_version.io_type = hdsp->io_type;
     3793                hdsp_version.firmware_rev = hdsp->firmware_rev;
     3794                if ((err = copy_to_user((void *)arg, &hdsp_version, sizeof(hdsp_version)))) {
     3795                        return -EFAULT;
     3796                }
     3797                break;
     3798        case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE:
     3799                if (hdsp_is_9652(hdsp)) return -EINVAL;
     3800                /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
     3801                if (hdsp->io_type == Undefined) return -EINVAL;
     3802
     3803                snd_printk("initializing firmware upload\n");
     3804                firmware = (hdsp_firmware_t *)arg;
     3805
     3806                if (hdsp_check_for_iobox (hdsp)) {
     3807                        return -EIO;
     3808                }
     3809
     3810                if (copy_from_user(hdsp->firmware_cache, firmware->firmware_data, sizeof(unsigned long)*24413) != 0) {
     3811                        return -EFAULT;
     3812                }
     3813               
     3814                hdsp->state |= HDSP_FirmwareCached;
     3815
     3816                if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
     3817                        return err;
     3818                }
     3819               
     3820               
     3821                if (!(hdsp->state & HDSP_InitializationComplete)) {
     3822                        snd_hdsp_initialize_channels(hdsp);
     3823               
     3824                        snd_hdsp_initialize_midi_flush(hdsp);
     3825           
     3826                        if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
     3827                                snd_printk("error creating alsa devices\n");
     3828                            return err;
     3829                        }
     3830                }
     3831                break;
     3832        case SNDRV_HDSP_IOCTL_GET_MIXER:
     3833                mixer = (hdsp_mixer_t *)arg;
     3834                if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
     3835                        return -EFAULT;
     3836                break;
     3837        default:
     3838                return -EINVAL;
     3839        }
     3840        return 0;
     3841}
     3842
    27933843static snd_pcm_ops_t snd_hdsp_playback_ops = {
    27943844        .open =         snd_hdsp_playback_open,
     
    28143864};
    28153865
     3866static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
     3867                                           hdsp_t *hdsp)
     3868{
     3869        snd_hwdep_t *hw;
     3870        int err;
     3871       
     3872        if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
     3873                return err;
     3874               
     3875        hdsp->hwdep = hw;
     3876        hw->private_data = hdsp;
     3877        strcpy(hw->name, "HDSP hwdep interface");
     3878
     3879        hw->ops.open = snd_hdsp_hwdep_dummy_op;
     3880        hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
     3881        hw->ops.release = snd_hdsp_hwdep_dummy_op;
     3882               
     3883        return 0;
     3884}
     3885
    28163886static int __devinit snd_hdsp_create_pcm(snd_card_t *card,
    28173887                                         hdsp_t *hdsp)
     
    28353905}
    28363906
    2837 static int __devinit snd_hdsp_initialize_firmware (hdsp_t *hdsp)
     3907static inline int snd_hdsp_initialize_input_enable (hdsp_t *hdsp)
    28383908{
    28393909        int i;
    2840         u32 *firmware_ptr;
    2841 
    2842         if (hdsp_check_for_iobox (hdsp)) {
    2843                 return -EIO;
    2844         }
    2845 
     3910       
    28463911        if (hdsp_fifo_wait (hdsp, 0, 100)) {
    28473912                return -EIO;
    28483913        }
    28493914       
    2850         /* enable all channels */
    2851 
    28523915        for (i = 0; i < HDSP_MAX_CHANNELS; ++i) {
    28533916                hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
    28543917                hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
    28553918        }
    2856 
    2857         if (force_firmware[hdsp->dev] || (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
    2858 
    2859                 snd_printk ("loading firmware\n");
    2860 
    2861                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_PROGRAM);
    2862                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2863                 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
    2864                         snd_printk ("timeout waiting for firmware setup\n");
    2865                         return -EIO;
    2866                 }
    2867 
    2868                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2869                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2870 
    2871                 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
    2872                         hdsp->type = Multiface;
    2873                         hdsp_write (hdsp, HDSP_jtagReg, HDSP_VERSION_BIT);
    2874                         hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2875                         hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
    2876                 } else {
    2877                         hdsp->type = Digiface;
    2878                 }
    2879 
    2880                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_PROGRAM);
    2881                 hdsp_write (hdsp, HDSP_fifoData, 0);
    2882                
    2883                 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
    2884                         snd_printk ("timeout waiting for download preparation\n");
    2885                         return -EIO;
    2886                 }
    2887                
    2888                 hdsp_write (hdsp, HDSP_jtagReg, HDSP_S_LOAD);
    2889                
    2890                 if (hdsp->type == Digiface) {
    2891                         firmware_ptr = (u32 *) digiface_firmware;
    2892                 } else {
    2893                         firmware_ptr = (u32 *) multiface_firmware;
    2894                 }
    2895                
    2896                 for (i = 0; i < 24413; ++i) {
    2897                         hdsp_write(hdsp, HDSP_fifoData, firmware_ptr[i]);
    2898                         if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
    2899                                 snd_printk ("timeout during firmware loading\n");
    2900                                 return -EIO;
    2901                         }
    2902                 }
    2903                
    2904                 if (hdsp_fifo_wait (hdsp, 3, HDSP_LONG_WAIT)) {
    2905                         snd_printk ("timeout at end of firmware loading\n");
    2906                         return -EIO;
    2907                 }
    2908 
    2909         } else {
    2910 
    2911                 /* firmware already loaded, but we need to know what type
    2912                    of I/O box is connected.
    2913                 */
    2914 
    2915                 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
    2916                         hdsp->type = Multiface;
    2917                 } else {
    2918                         hdsp->type = Digiface;
    2919                 }
    2920         }
    2921 
    2922         if (hdsp->type == Digiface) {
    2923                 snd_printk ("I/O Box is a Digiface\n");
    2924                 hdsp->card_name = "RME Hammerfall DSP (Digiface)";
     3919       
     3920        return 0;
     3921}
     3922
     3923static inline void snd_hdsp_initialize_channels(hdsp_t *hdsp)
     3924{
     3925        if (hdsp->io_type == Digiface) {
     3926                hdsp->card_name = "RME Hammerfall DSP + Digiface";
    29253927                hdsp->ss_channels = DIGIFACE_SS_CHANNELS;
    29263928                hdsp->ds_channels = DIGIFACE_DS_CHANNELS;
    29273929        } else {
    2928                 snd_printk ("I/O Box is a Multiface\n");
    2929                 hdsp->card_name = "RME Hammerfall DSP (Multiface)";
     3930                hdsp->card_name = "RME Hammerfall DSP + Multiface";
    29303931                hdsp->ss_channels = MULTIFACE_SS_CHANNELS;
    29313932                hdsp->ds_channels = MULTIFACE_DS_CHANNELS;
    29323933        }
    2933        
     3934}
     3935
     3936static inline void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
     3937{
    29343938        snd_hdsp_flush_midi_input (hdsp, 0);
    29353939        snd_hdsp_flush_midi_input (hdsp, 1);
     
    29383942        hdsp_write(hdsp, HDSP_jtagReg, HDSP_BIGENDIAN_MODE);
    29393943#endif
    2940 
     3944}
     3945
     3946static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
     3947{
     3948        int err;
     3949       
     3950        if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
     3951                return err;
     3952        }
     3953       
     3954        if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
     3955                return err;
     3956        }
     3957
     3958        if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
     3959                return err;
     3960        }
     3961
     3962        if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
     3963                return err;
     3964        }
     3965
     3966        snd_hdsp_proc_init(hdsp);
     3967
     3968        hdsp->last_spdif_sample_rate = -1;
     3969        hdsp->system_sample_rate = -1;
     3970        hdsp->last_external_sample_rate = -1;
     3971        hdsp->last_internal_sample_rate = -1;
     3972        hdsp->playback_pid = -1;
     3973        hdsp->capture_pid = -1;
     3974        hdsp->capture_substream = NULL;
     3975        hdsp->playback_substream = NULL;
     3976
     3977        if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
     3978                return err;
     3979        }
     3980       
     3981        hdsp_update_simple_mixer_controls(hdsp);
     3982       
     3983        if (!(hdsp->state & HDSP_InitializationComplete)) {
     3984                sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
     3985                        hdsp->port, hdsp->irq);
     3986           
     3987                if ((err = snd_card_register(card)) < 0) {
     3988                        snd_printk("error registering card\n");
     3989                        return err;
     3990                }
     3991                hdsp->state |= HDSP_InitializationComplete;
     3992        }
     3993       
    29413994        return 0;
    29423995}
     
    29484001        struct pci_dev *pci = hdsp->pci;
    29494002        int err;
    2950         unsigned short rev;
     4003        int i;
    29514004
    29524005        hdsp->irq = -1;
     4006        hdsp->state = 0;
    29534007        hdsp->midi[0].rmidi = 0;
    29544008        hdsp->midi[1].rmidi = 0;
     
    29614015        hdsp->iobase = 0;
    29624016        hdsp->res_port = 0;
     4017        hdsp->io_type = Undefined;
     4018        for (i = 0; i < HDSP_MAX_CHANNELS; ++i)
     4019                hdsp->playback_mixer_ctls[i] = 0;
    29634020
    29644021        hdsp->card = card;
     
    29664023        spin_lock_init(&hdsp->lock);
    29674024
    2968         pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &rev);
     4025        tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
     4026       
     4027        pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
    29694028        strcpy(card->driver, "H-DSP");
    29704029        strcpy(card->mixername, "Xilinx FPGA");
    29714030       
    2972         switch (rev & 0xff) {
     4031        switch (hdsp->firmware_rev & 0xff) {
    29734032        case 0xa:
    29744033        case 0xb:
     4034                hdsp->card_name = "RME Hammerfall DSP";
     4035                break;
    29754036        case 0x64:
    2976                 /* hdsp_initialize_firmware() will reset this */
    2977                 hdsp->card_name = "RME Hammerfall DSP";
    2978                 break;
    2979 
     4037        case 0x65:
     4038        case 0x68:
     4039                hdsp->card_name = "RME HDSP 9652";
     4040                break;
    29804041        default:
    29814042                return -ENODEV;
     
    30104071                return err;
    30114072        }
    3012 
    3013         if ((err = snd_hdsp_initialize_firmware(hdsp)) < 0) {
     4073       
     4074        if (hdsp_is_9652(hdsp)) {
     4075               
     4076                if ((err = snd_hdsp_initialize_input_enable(hdsp)) != 0) {
     4077                        return err;
     4078                }
     4079
     4080                hdsp->io_type = Digiface;               
     4081       
     4082                hdsp->ss_channels = DIGIFACE_SS_CHANNELS;
     4083                hdsp->ds_channels = DIGIFACE_DS_CHANNELS;
     4084       
     4085                snd_hdsp_initialize_midi_flush(hdsp);
     4086       
     4087                if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4088                        return err;
     4089                }
     4090
     4091        } else {
     4092       
     4093                if (hdsp_check_for_iobox (hdsp)) {
     4094                        /* no iobox connected, we defer initialization */
     4095                        snd_printk("card initialization pending : waiting for firmware\n");
     4096                        if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4097                                return err;
     4098                        }
     4099                        return 0;
     4100                }
     4101
     4102                if ((err = snd_hdsp_initialize_input_enable(hdsp)) != 0) {
     4103                        return err;
     4104                }
     4105               
     4106                if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
     4107                        snd_printk("card initialization pending : waiting for firmware\n");
     4108                        if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4109                                return err;
     4110                        }
     4111                return 0;
     4112                }
     4113               
     4114                snd_printk("Firmware already loaded, initializing card.\n");
     4115
     4116                if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
     4117                        hdsp->io_type = Multiface;
     4118                } else {
     4119                        hdsp->io_type = Digiface;
     4120                }
     4121               
     4122                if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
     4123                        return err;
     4124                }
     4125               
     4126                snd_hdsp_initialize_channels(hdsp);
     4127               
     4128                snd_hdsp_initialize_midi_flush(hdsp);
     4129               
     4130        }
     4131       
     4132        hdsp->state |= HDSP_FirmwareLoaded;     
     4133       
     4134        if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
    30144135                return err;
    30154136        }
    3016 
    3017         if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
    3018                 return err;
    3019         }
    3020 
    3021         if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
    3022                 return err;
    3023         }
    3024 
    3025         if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
    3026                 return err;
    3027         }
    3028 
    3029         if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
    3030                 return err;
    3031         }
    3032 
    3033         snd_hdsp_proc_init(hdsp);
    3034 
    3035         hdsp->last_spdif_sample_rate = -1;
    3036         hdsp->last_adat_sample_rate = -1;
    3037         hdsp->playback_pid = -1;
    3038         hdsp->capture_pid = -1;
    3039         hdsp->capture_substream = NULL;
    3040         hdsp->playback_substream = NULL;
    3041 
    3042         snd_hdsp_set_defaults(hdsp);
    3043 
    3044         return 0;
     4137       
     4138        return 0;       
    30454139}
    30464140
    30474141static int snd_hdsp_free(hdsp_t *hdsp)
    30484142{
    3049         /* stop the audio, and cancel all interrupts */
    3050         hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
    3051         hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
     4143        if (hdsp->res_port) {
     4144                /* stop the audio, and cancel all interrupts */
     4145                hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
     4146                hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
     4147        }
    30524148
    30534149        if (hdsp->irq >= 0)
    30544150                free_irq(hdsp->irq, (void *)hdsp);
    30554151
    3056         snd_hdsp_proc_done(hdsp);
    30574152        snd_hdsp_free_buffers(hdsp);
    30584153       
     
    31244219
    31254220static struct pci_driver driver = {
    3126         .name = "RME Hammerfall DSP",
     4221        .name =     "RME Hammerfall DSP",
    31274222        .id_table = snd_hdsp_ids,
    3128         .probe = snd_hdsp_probe,
     4223        .probe =    snd_hdsp_probe,
    31294224        .remove = __devexit_p(snd_hdsp_remove),
    31304225};
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/rme9652.c

    r224 r246  
    19471947}
    19481948
    1949 void snd_rme9652_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     1949static irqreturn_t snd_rme9652_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    19501950{
    19511951        rme9652_t *rme9652 = (rme9652_t *) dev_id;
    19521952
    19531953        if (!(rme9652_read(rme9652, RME9652_status_register) & RME9652_IRQ)) {
    1954                 return;
     1954                return IRQ_NONE;
    19551955        }
    19561956
     
    19641964                snd_pcm_period_elapsed(rme9652->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
    19651965        }
     1966        return IRQ_HANDLED;
    19661967}
    19671968
     
    20542055                runtime->status->hw_ptr = 0;
    20552056        if (other) {
    2056                 snd_pcm_substream_t *s = substream;
     2057                struct list_head *pos;
     2058                snd_pcm_substream_t *s;
    20572059                snd_pcm_runtime_t *oruntime = other->runtime;
    2058                 do {
    2059                         s = s->link_next;
     2060                snd_pcm_group_for_each(pos, substream) {
     2061                        s = snd_pcm_group_substream_entry(pos);
    20602062                        if (s == other) {
    20612063                                oruntime->status->hw_ptr = runtime->status->hw_ptr;
    20622064                                break;
    20632065                        }
    2064                 } while (s != substream);
     2066                }
    20652067        }
    20662068        return 0;
     
    22002202
    22012203        if (other) {
    2202                 snd_pcm_substream_t *s = substream;
    2203                 do {
    2204                         s = s->link_next;
     2204                struct list_head *pos;
     2205                snd_pcm_substream_t *s;
     2206                snd_pcm_group_for_each(pos, substream) {
     2207                        s = snd_pcm_group_substream_entry(pos);
    22052208                        if (s == other) {
    22062209                                snd_pcm_trigger_done(s, substream);
     
    22112214                                goto _ok;
    22122215                        }
    2213                 } while (s != substream);
     2216                }
    22142217                if (cmd == SNDRV_PCM_TRIGGER_START) {
    22152218                        if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
     
    24052408
    24062409        rme9652->creg_spdif_stream = rme9652->creg_spdif;
    2407         rme9652->spdif_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     2410        rme9652->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    24082411        snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
    24092412                       SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id);
     
    24232426        spin_unlock_irqrestore(&rme9652->lock, flags);
    24242427
    2425         rme9652->spdif_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
     2428        rme9652->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    24262429        snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
    24272430                       SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/sonicvibes.c

    r224 r246  
    602602}
    603603
    604 static void snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    605 {
    606         sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, dev_id, return);
     604static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     605{
     606        sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, dev_id, return IRQ_NONE);
    607607        unsigned char status;
    608608
    609609        status = inb(SV_REG(sonic, STATUS));
    610610        if (!(status & (SV_DMAA_IRQ | SV_DMAC_IRQ | SV_MIDI_IRQ)))
    611                 return;
     611                return IRQ_NONE;
    612612        if (status == 0xff) {   /* failure */
    613613                outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
    614614                snd_printk("IRQ failure - interrupts disabled!!\n");
    615                 return;
     615                return IRQ_HANDLED;
    616616        }
    617617        if (sonic->pcm) {
     
    660660                snd_ctl_notify(sonic->card, SNDRV_CTL_EVENT_MASK_VALUE, &sonic->master_volume->id);
    661661        }
     662        return IRQ_HANDLED;
    662663}
    663664
  • GPL/branches/alsa-resync1/alsa-kernel/pci/trident/trident_main.c

    r224 r246  
    27152715        .name =         "PCM Front Playback Volume",
    27162716        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2717        .count =        32,
    27172718        .info =         snd_trident_pcm_vol_control_info,
    27182719        .get =          snd_trident_pcm_vol_control_get,
     
    27762777        .name =         "PCM Pan Playback Control",
    27772778        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2779        .count =        32,
    27782780        .info =         snd_trident_pcm_pan_control_info,
    27792781        .get =          snd_trident_pcm_pan_control_get,
     
    28292831        .name =         "PCM Reverb Playback Volume",
    28302832        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     2833        .count =        32,
    28312834        .info =         snd_trident_pcm_rvol_control_info,
    28322835        .get =          snd_trident_pcm_rvol_control_get,
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ymfpci/ymfpci_main.c

    r224 r246  
    13681368{
    13691369        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    1370         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    1371         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
     1370        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1371        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
    13721372        .info =         snd_ymfpci_spdif_stream_info,
    13731373        .get =          snd_ymfpci_spdif_stream_get,
Note: See TracChangeset for help on using the changeset viewer.