Ignore:
Timestamp:
Jul 26, 2007, 7:21:09 AM (18 years ago)
Author:
Brendan Oakley
Message:

Merged to Alsa 0.9.1

Location:
GPL/branches/alsa-resync1/alsa-kernel/pci
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/alsa-resync1/alsa-kernel/pci/emu10k1/emuproc.c

    r210 r224  
    478478
    479479
    480 #ifdef TARGET_OS2
    481480static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
    482     0, 0, snd_emu10k1_fx8010_read, 0, 0,0,0,0
     481        .read = snd_emu10k1_fx8010_read,
    483482};
    484 #else
    485 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
    486 read: snd_emu10k1_fx8010_read,
    487 };
    488 #endif
     483
    489484int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
    490485{
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ak4524.c

    r215 r224  
    22 *   ALSA driver for ICEnsemble ICE1712 (Envy24)
    33 *
    4  *   AK4524 / AK4528 / AK4529 interface
     4 *   AK4524 / AK4528 / AK4529 / AK4355 / AK4381 interface
    55 *
    66 *      Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
     
    3232
    3333/*
    34  * write AK4524 register
     34 * write AK4xxx register
    3535 */
    36 void snd_ice1712_ak4524_write(ice1712_t *ice, int chip,
    37                                      unsigned char addr, unsigned char data)
    38 {
    39         unsigned char tmp, saved[2];
     36void snd_ice1712_akm4xxx_write(akm4xxx_t *ak, int chip,
     37                              unsigned char addr, unsigned char data)
     38{
     39        unsigned int tmp;
    4040        int idx;
    4141        unsigned int addrdata;
    42         ak4524_t *ak = &ice->ak4524;
     42        ice1712_t *ice = ak->chip;
    4343
    4444        snd_assert(chip >= 0 && chip < 4, return);
    4545
    4646        if (ak->ops.start) {
    47                 if (ak->ops.start(ice, saved, chip) < 0)
     47                if (ak->ops.start(ak, chip) < 0)
    4848                        return;
    4949        } else
    50                 snd_ice1712_save_gpio_status(ice, saved);
    51 
    52         tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
     50                snd_ice1712_save_gpio_status(ice);
     51
     52        tmp = snd_ice1712_gpio_read(ice);
    5353        tmp |= ak->add_flags;
    5454        tmp &= ~ak->mask_flags;
     
    5656                if (ak->cif) {
    5757                        tmp |= ak->cs_mask; /* start without chip select */
     58                }  else {
     59                        tmp &= ~ak->cs_mask; /* chip select low */
     60                        snd_ice1712_gpio_write(ice, tmp);
     61                        udelay(1);
     62                }
    5863        } else {
    59                         tmp &= ~ak->cs_mask; /* chip select low */
    60                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    61                 udelay(1);
    62                 }
    63         } else {
     64                /* doesn't handle cf=1 yet */
    6465                tmp &= ~ak->cs_mask;
    6566                tmp |= ak->cs_addr;
    66         }
    67 
    68         addr &= 0x07;
     67                snd_ice1712_gpio_write(ice, tmp);
     68                udelay(1);
     69        }
     70
    6971        /* build I2C address + data byte */
    70         /* assume C1=1, C0=0 */
    71         addrdata = 0xa000 | (addr << 8) | data;
     72        addrdata = (ak->caddr << 6) | 0x20 | (addr & 0x1f);
     73        addrdata = (addrdata << 8) | data;
    7274        for (idx = 15; idx >= 0; idx--) {
    73                 tmp &= ~(ak->data_mask | ak->clk_mask);
     75                /* drop clock */
     76                tmp &= ~ak->clk_mask;
     77                snd_ice1712_gpio_write(ice, tmp);
     78                udelay(1);
     79                /* set data */
    7480                if (addrdata & (1 << idx))
    7581                        tmp |= ak->data_mask;
    76                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    77                 //udelay(200);
     82                else
     83                        tmp &= ~ak->data_mask;
     84                snd_ice1712_gpio_write(ice, tmp);
    7885                udelay(1);
     86                /* raise clock */
    7987                tmp |= ak->clk_mask;
    80                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
     88                snd_ice1712_gpio_write(ice, tmp);
    8189                udelay(1);
    8290        }
    8391
    84         if (ak->type == SND_AK4524) {
    85         if ((addr != 0x04 && addr != 0x05) || (data & 0x80) == 0)
     92        /* save the data */
     93        if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
     94                if ((addr != 0x04 && addr != 0x05) || (data & 0x80) == 0)
     95                        ak->images[chip][addr] = data;
     96                else
     97                        ak->ipga_gain[chip][addr-4] = data;
     98        } else {
     99                /* AK4529, or else */
    86100                ak->images[chip][addr] = data;
    87         else
    88                 ak->ipga_gain[chip][addr-4] = data;
    89         }
    90 
     101        }
     102       
    91103        if (ak->cs_mask == ak->cs_addr) {
    92104                if (ak->cif) {
    93105                        /* assert a cs pulse to trigger */
    94106                        tmp &= ~ak->cs_mask;
    95                         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
     107                        snd_ice1712_gpio_write(ice, tmp);
    96108                        udelay(1);
    97109                }
     
    101113                tmp |= ak->cs_none; /* deselect address */
    102114        }
    103                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    104                 udelay(1);
     115        snd_ice1712_gpio_write(ice, tmp);
     116        udelay(1);
    105117
    106118        if (ak->ops.stop)
    107                 ak->ops.stop(ice, saved);
     119                ak->ops.stop(ak);
    108120        else
    109                 snd_ice1712_restore_gpio_status(ice, saved);
    110 }
    111 
    112 void snd_ice1712_ak4524_reset(ice1712_t *ice, int state)
    113 {
    114         int chip;
     121                snd_ice1712_restore_gpio_status(ice);
     122}
     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 */
     130void snd_ice1712_akm4xxx_reset(akm4xxx_t *ak, int state)
     131{
     132        unsigned int chip;
    115133        unsigned char reg;
    116         ak4524_t *ak = &ice->ak4524;
    117134       
    118135        switch (ak->type) {
    119136        case SND_AK4524:
    120137        case SND_AK4528:
    121         for (chip = 0; chip < ak->num_dacs/2; chip++) {
    122                 snd_ice1712_ak4524_write(ice, chip, 0x01, state ? 0x00 : 0x03);
    123                 if (state)
    124                         continue;
     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;
    125142                        /* DAC volumes */
    126143                        for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
    127                         snd_ice1712_ak4524_write(ice, chip, reg, ak->images[chip][reg]);
     144                                snd_ice1712_akm4xxx_write(ak, chip, reg, ak->images[chip][reg]);
    128145                        if (ak->type == SND_AK4528)
    129                         continue;
     146                                continue;
    130147                        /* IPGA */
    131                 for (reg = 0x04; reg < 0x06; reg++)
    132                         snd_ice1712_ak4524_write(ice, chip, reg, ak->ipga_gain[chip][reg-4]);
     148                        for (reg = 0x04; reg < 0x06; reg++)
     149                                snd_ice1712_akm4xxx_write(ak, chip, reg, ak->ipga_gain[chip][reg-4]);
    133150                }
    134151                break;
     
    136153                /* FIXME: needed for ak4529? */
    137154                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;
    138172        }
    139173}
    140174
    141175/*
    142  * initialize all the ak4524/4528 chips
     176 * initialize all the ak4xxx chips
    143177 */
    144 void __devinit snd_ice1712_ak4524_init(ice1712_t *ice)
     178static void __devinit snd_ice1712_akm4xxx_init_chip(akm4xxx_t *ak)
    145179{
    146180        static unsigned char inits_ak4524[] = {
     
    171205                0x09, 0x01, /* 9: ATS=0, RSTN=1 */
    172206                0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
    173                 0x00, 0x08, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
     207                0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
    174208                0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
    175209                0x02, 0xff, /* 2: LOUT1 muted */
     
    184218                0xff, 0xff
    185219        };
     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
    186247        int chip, num_chips;
    187248        unsigned char *ptr, reg, data, *inits;
    188         ak4524_t *ak = &ice->ak4524;
    189249
    190250        switch (ak->type) {
     
    198258                break;
    199259        case SND_AK4529:
    200         default:
    201260                inits = inits_ak4529;
    202261                num_chips = 1;
    203262                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;
    204274        }
    205275
     
    209279                        reg = *ptr++;
    210280                        data = *ptr++;
    211                         snd_ice1712_ak4524_write(ice, chip, reg, data);
    212                 }
    213         }
     281                        snd_ice1712_akm4xxx_write(ak, chip, reg, data);
     282                }
     283        }
     284}
     285
     286
     287/*
     288 * initialize the akm4xxx_t record with the template
     289 */
     290void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp, ice1712_t *ice)
     291{
     292        *ak = *temp;
     293        ak->chip = ice;
     294        snd_ice1712_akm4xxx_init_chip(ak);
    214295}
    215296
     
    217298#define AK_GET_CHIP(val)                (((val) >> 8) & 0xff)
    218299#define AK_GET_ADDR(val)                ((val) & 0xff)
    219 #define AK_GET_SHIFT(val)               (((val) >> 16) & 0xff)
    220 #define AK_COMPOSE(chip,addr,shift)     (((chip) << 8) | (addr) | ((shift) << 16))
    221 
    222 static int snd_ice1712_ak4524_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    223 {
     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
     306static 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
    224310        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    225311        uinfo->count = 1;
    226312        uinfo->value.integer.min = 0;
    227         uinfo->value.integer.max = 127;
    228         return 0;
    229 }
    230 
    231 static int snd_ice1712_ak4524_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    232 {
    233         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     313        uinfo->value.integer.max = mask;
     314        return 0;
     315}
     316
     317static int snd_ice1712_akm4xxx_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     318{
     319        akm4xxx_t *ak = _snd_kcontrol_chip(kcontrol);
    234320        int chip = AK_GET_CHIP(kcontrol->private_value);
    235321        int addr = AK_GET_ADDR(kcontrol->private_value);
    236         ucontrol->value.integer.value[0] = ice->ak4524.images[chip][addr];
    237         return 0;
    238 }
    239 
    240 static int snd_ice1712_ak4524_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    241 {
    242         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     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
     330static 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);
    243333        int chip = AK_GET_CHIP(kcontrol->private_value);
    244334        int addr = AK_GET_ADDR(kcontrol->private_value);
    245         unsigned char nval = ucontrol->value.integer.value[0];
    246         int change = ice->ak4524.images[chip][addr] != nval;
     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;
    247343        if (change)
    248                 snd_ice1712_ak4524_write(ice, chip, addr, nval);
     344                snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    249345        return change;
    250346}
    251347
    252 static int snd_ice1712_ak4524_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     348static int snd_ice1712_akm4xxx_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    253349{
    254350        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     
    259355}
    260356
    261 static int snd_ice1712_ak4524_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    262 {
    263         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     357static 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);
    264360        int chip = AK_GET_CHIP(kcontrol->private_value);
    265361        int addr = AK_GET_ADDR(kcontrol->private_value);
    266         ucontrol->value.integer.value[0] = ice->ak4524.ipga_gain[chip][addr-4] & 0x7f;
    267         return 0;
    268 }
    269 
    270 static int snd_ice1712_ak4524_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    271 {
    272         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     362        ucontrol->value.integer.value[0] = ak->ipga_gain[chip][addr-4] & 0x7f;
     363        return 0;
     364}
     365
     366static 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);
    273369        int chip = AK_GET_CHIP(kcontrol->private_value);
    274370        int addr = AK_GET_ADDR(kcontrol->private_value);
    275371        unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
    276         int change = ice->ak4524.ipga_gain[chip][addr] != nval;
     372        int change = ak->ipga_gain[chip][addr] != nval;
    277373        if (change)
    278                 snd_ice1712_ak4524_write(ice, chip, addr, nval);
     374                snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    279375        return change;
    280376}
    281377
    282 static int snd_ice1712_ak4524_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
     378static int snd_ice1712_akm4xxx_deemphasis_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
    283379{
    284380        static char *texts[4] = {
     
    294390}
    295391
    296 static int snd_ice1712_ak4524_deemphasis_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
    297 {
    298         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     392static 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);
    299395        int chip = AK_GET_CHIP(kcontrol->private_value);
    300396        int addr = AK_GET_ADDR(kcontrol->private_value);
    301397        int shift = AK_GET_SHIFT(kcontrol->private_value);
    302         ucontrol->value.enumerated.item[0] = (ice->ak4524.images[chip][addr] >> shift) & 3;
    303         return 0;
    304 }
    305 
    306 static int snd_ice1712_ak4524_deemphasis_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    307 {
    308         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     398        ucontrol->value.enumerated.item[0] = (ak->images[chip][addr] >> shift) & 3;
     399        return 0;
     400}
     401
     402static 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);
    309405        int chip = AK_GET_CHIP(kcontrol->private_value);
    310406        int addr = AK_GET_ADDR(kcontrol->private_value);
     
    313409        int change;
    314410       
    315         nval = (nval << shift) | (ice->ak4524.images[chip][addr] & ~(3 << shift));
    316         change = ice->ak4524.images[chip][addr] != nval;
     411        nval = (nval << shift) | (ak->images[chip][addr] & ~(3 << shift));
     412        change = ak->images[chip][addr] != nval;
    317413        if (change)
    318                 snd_ice1712_ak4524_write(ice, chip, addr, nval);
     414                snd_ice1712_akm4xxx_write(ak, chip, addr, nval);
    319415        return change;
    320416}
     
    324420 */
    325421
    326 int __devinit snd_ice1712_ak4524_build_controls(ice1712_t *ice)
    327 {
    328         int err, idx;
    329         ak4524_t *ak = &ice->ak4524;
    330 
    331         for (idx = 0; idx < ak->num_dacs; ++idx) {
     422int __devinit snd_ice1712_akm4xxx_build_controls(ice1712_t *ice)
     423{
     424        unsigned int idx;
     425        int err;
     426        unsigned int akidx;
     427
     428        for (akidx = 0; akidx < ice->akm_codecs; akidx++) {
     429                akm4xxx_t *ak = &ice->akm[akidx];
     430                for (idx = 0; idx < ak->num_dacs; ++idx) {
    332431                        snd_kcontrol_t ctl;
    333432                        memset(&ctl, 0, sizeof(ctl));
    334433                        strcpy(ctl.id.name, "DAC Volume");
    335                         ctl.id.index = idx;
     434                        ctl.id.index = idx + ak->idx_offset * 2;
    336435                        ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    337                         ctl.info = snd_ice1712_ak4524_volume_info;
     436                        ctl.info = snd_ice1712_akm4xxx_volume_info;
    338437                        ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    339                         ctl.get = snd_ice1712_ak4524_volume_get;
    340                         ctl.put = snd_ice1712_ak4524_volume_put;
    341                 switch (ak->type) {
    342                 case SND_AK4524:
    343                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0); /* register 6 & 7 */
    344                         break;
    345                 case SND_AK4528:
    346                         ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
    347                         break;
    348                 case SND_AK4529: {
    349                         int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
    350                         ctl.private_value = AK_COMPOSE(0, val, 0);
    351                         break;
    352                 }
    353                 }
    354                         ctl.private_data = ice;
     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;
    355462                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    356463                                return err;
    357464                }
    358         for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
     465                for (idx = 0; idx < ak->num_adcs && ak->type == SND_AK4524; ++idx) {
    359466                        snd_kcontrol_t ctl;
    360467                        memset(&ctl, 0, sizeof(ctl));
     
    362469                        ctl.id.index = idx;
    363470                        ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    364                         ctl.info = snd_ice1712_ak4524_volume_info;
     471                        ctl.info = snd_ice1712_akm4xxx_volume_info;
    365472                        ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    366                         ctl.get = snd_ice1712_ak4524_volume_get;
    367                         ctl.put = snd_ice1712_ak4524_volume_put;
    368                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
    369                         ctl.private_data = ice;
     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;
    370477                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    371478                                return err;
     
    374481                        ctl.id.index = idx;
    375482                        ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    376                         ctl.info = snd_ice1712_ak4524_ipga_gain_info;
     483                        ctl.info = snd_ice1712_akm4xxx_ipga_gain_info;
    377484                        ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    378                         ctl.get = snd_ice1712_ak4524_ipga_gain_get;
    379                         ctl.put = snd_ice1712_ak4524_ipga_gain_put;
    380                 ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
    381                         ctl.private_data = ice;
     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;
    382489                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    383490                                return err;
    384491                }
    385         for (idx = 0; idx < ak->num_dacs/2; idx++) {
     492                for (idx = 0; idx < ak->num_dacs/2; idx++) {
    386493                        snd_kcontrol_t ctl;
    387494                        memset(&ctl, 0, sizeof(ctl));
    388495                        strcpy(ctl.id.name, "Deemphasis");
    389                         ctl.id.index = idx;
     496                        ctl.id.index = idx + ak->idx_offset;
    390497                        ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
    391                         ctl.info = snd_ice1712_ak4524_deemphasis_info;
     498                        ctl.info = snd_ice1712_akm4xxx_deemphasis_info;
    392499                        ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
    393                         ctl.get = snd_ice1712_ak4524_deemphasis_get;
    394                         ctl.put = snd_ice1712_ak4524_deemphasis_put;
    395                 switch (ak->type) {
    396                 case SND_AK4524:
    397                 case SND_AK4528:
    398                         ctl.private_value = AK_COMPOSE(idx, 3, 0); /* register 3 */
    399                         break;
    400                 case SND_AK4529: {
    401                         int shift = idx == 3 ? 6 : (2 - idx) * 2;
    402                         ctl.private_value = AK_COMPOSE(0, 8, shift); /* register 8 with shift */
    403                         break;
    404                 }
    405                 }
    406                         ctl.private_data = ice;
     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;
    407520                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    408521                                return err;
    409522                }
    410         return 0;
    411 }
    412 
    413 
     523        }
     524        return 0;
     525}
     526
     527
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/delta.c

    r215 r224  
    190190static int delta_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
    191191{
    192         unsigned long flags;
    193192        unsigned int val;
    194193        int change;
    195194
    196195        val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
    197         spin_lock_irqsave(&ice->reg_lock, flags);
     196        spin_lock_irq(&ice->reg_lock);
    198197        change = ice->spdif.cs8403_bits != val;
    199198        ice->spdif.cs8403_bits = val;
    200199        if (change && ice->playback_pro_substream == NULL) {
    201                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     200                spin_unlock_irq(&ice->reg_lock);
    202201                snd_ice1712_delta_cs8403_spdif_write(ice, val);
    203202        } else {
    204                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     203                spin_unlock_irq(&ice->reg_lock);
    205204        }
    206205        return change;
     
    214213static int delta_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
    215214{
    216         unsigned long flags;
    217215        unsigned int val;
    218216        int change;
    219217
    220218        val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
    221         spin_lock_irqsave(&ice->reg_lock, flags);
     219        spin_lock_irq(&ice->reg_lock);
    222220        change = ice->spdif.cs8403_stream_bits != val;
    223221        ice->spdif.cs8403_stream_bits = val;
    224222        if (change && ice->playback_pro_substream != NULL) {
    225                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     223                spin_unlock_irq(&ice->reg_lock);
    226224                snd_ice1712_delta_cs8403_spdif_write(ice, val);
    227225        } else {
    228                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     226                spin_unlock_irq(&ice->reg_lock);
    229227        }
    230228        return change;
     
    235233 * AK4524 on Delta 44 and 66 to choose the chip mask
    236234 */
    237 static int delta_ak4524_start(ice1712_t *ice, unsigned char *saved, int chip)
    238 {
    239         snd_ice1712_save_gpio_status(ice, saved);
    240         ice->ak4524.cs_mask =
    241         ice->ak4524.cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
    242                                           ICE1712_DELTA_CODEC_CHIP_B;
     235static 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;
    243241        return 0;
    244242}
     
    247245 * AK4524 on Delta1010LT to choose the chip address
    248246 */
    249 static int delta1010lt_ak4524_start(ice1712_t *ice, unsigned char *saved, int chip)
    250 {
    251         snd_ice1712_save_gpio_status(ice, saved);
    252         ice->ak4524.cs_mask = ICE1712_DELTA_1010LT_CS;
    253         ice->ak4524.cs_addr = chip << 4;
     247static 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;
    254252        return 0;
    255253}
     
    258256 * change the rate of AK4524 on Delta 44/66, AP, 1010LT
    259257 */
    260 static void delta_ak4524_set_rate_val(ice1712_t *ice, unsigned int rate)
     258static void delta_ak4524_set_rate_val(akm4xxx_t *ak, unsigned int rate)
    261259{
    262260        unsigned char tmp, tmp2;
     261        ice1712_t *ice = ak->chip;
    263262
    264263        if (rate == 0)  /* no hint - S/PDIF input is master, simply return */
     
    277276
    278277        /* do it again */
    279         snd_ice1712_ak4524_reset(ice, 1);
     278        snd_ice1712_akm4xxx_reset(ak, 1);
    280279        down(&ice->gpio_mutex);
    281280        tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
     
    284283        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    285284        up(&ice->gpio_mutex);
    286         snd_ice1712_ak4524_reset(ice, 0);
     285        snd_ice1712_akm4xxx_reset(ak, 0);
    287286}
    288287
     
    299298
    300299/* set up */
    301 static void delta_setup_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
     300static void delta_setup_spdif(ice1712_t *ice, int rate)
    302301{
    303302        unsigned long flags;
     
    309308        if (tmp & 0x01)         /* consumer */
    310309                tmp &= (tmp & 0x01) ? ~0x06 : ~0x18;
    311         switch (substream->runtime->rate) {
     310        switch (rate) {
    312311        case 32000: tmp |= (tmp & 0x01) ? 0x04 : 0x00; break;
    313312        case 44100: tmp |= (tmp & 0x01) ? 0x00 : 0x10; break;
     
    328327 */
    329328
     329static akm4xxx_t akm_audiophile __devinitdata = {
     330        .type = SND_AK4528,
     331        .num_adcs = 2,
     332        .num_dacs = 2,
     333        .caddr = 2,
     334        .cif = 0,
     335        .data_mask = ICE1712_DELTA_AP_DOUT,
     336        .clk_mask = ICE1712_DELTA_AP_CCLK,
     337        .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
     338        .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
     339        .cs_none = 0,
     340        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
     341        .mask_flags = 0,
     342        .ops = {
     343                .set_rate_val = delta_ak4524_set_rate_val
     344        }
     345};
     346
     347static akm4xxx_t akm_delta410 __devinitdata = {
     348        .type = SND_AK4529,
     349        .num_adcs = 2,
     350        .num_dacs = 8,
     351        .caddr = 0,
     352        .cif = 0,
     353        .data_mask = ICE1712_DELTA_AP_DOUT,
     354        .clk_mask = ICE1712_DELTA_AP_CCLK,
     355        .cs_mask = ICE1712_DELTA_AP_CS_CODEC,
     356        .cs_addr = ICE1712_DELTA_AP_CS_CODEC,
     357        .cs_none = 0,
     358        .add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
     359        .mask_flags = 0,
     360        .ops = {
     361                .set_rate_val = delta_ak4524_set_rate_val
     362        }
     363};
     364
     365static akm4xxx_t akm_delta1010lt __devinitdata = {
     366        .type = SND_AK4524,
     367        .num_adcs = 8,
     368        .num_dacs = 8,
     369        .caddr = 2,
     370        .cif = 0, /* the default level of the CIF pin from AK4524 */
     371        .data_mask = ICE1712_DELTA_1010LT_DOUT,
     372        .clk_mask = ICE1712_DELTA_1010LT_CCLK,
     373        .cs_mask = 0,
     374        .cs_addr = 0, /* set later */
     375        .cs_none = ICE1712_DELTA_1010LT_CS_NONE,
     376        .add_flags = 0,
     377        .mask_flags = 0,
     378        .ops = {
     379                .start = delta1010lt_ak4524_start,
     380                .set_rate_val = delta_ak4524_set_rate_val
     381        }
     382};
     383
     384static akm4xxx_t akm_delta44 __devinitdata = {
     385        .type = SND_AK4524,
     386        .num_adcs = 4,
     387        .num_dacs = 4,
     388        .caddr = 2,
     389        .cif = 0, /* the default level of the CIF pin from AK4524 */
     390        .data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA,
     391        .clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK,
     392        .cs_mask = 0,
     393        .cs_addr = 0, /* set later */
     394        .cs_none = 0,
     395        .add_flags = 0,
     396        .mask_flags = 0,
     397        .ops = {
     398                .start = delta_ak4524_start,
     399                .set_rate_val = delta_ak4524_set_rate_val
     400        }
     401};
     402
    330403static int __devinit snd_ice1712_delta_init(ice1712_t *ice)
    331404{
    332405        int err;
    333         ak4524_t *ak;
     406        akm4xxx_t *ak;
    334407
    335408        /* determine I2C, DACs and ADCs */
     
    369442        case ICE1712_SUBDEVICE_DELTA66:
    370443                ice->spdif.ops.open = delta_open_spdif;
    371                 ice->spdif.ops.setup = delta_setup_spdif;
     444                ice->spdif.ops.setup_rate = delta_setup_spdif;
    372445                ice->spdif.ops.default_get = delta_spdif_default_get;
    373446                ice->spdif.ops.default_put = delta_spdif_default_put;
     
    379452        }
    380453
     454        /* no analog? */
     455        switch (ice->eeprom.subvendor) {
     456        case ICE1712_SUBDEVICE_DELTA1010:
     457        case ICE1712_SUBDEVICE_DELTADIO2496:
     458                return 0;
     459        }
     460
    381461        /* second stage of initialization, analog parts and others */
    382         ak = &ice->ak4524;
     462        ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
     463        if (! ak)
     464                return -ENOMEM;
     465        ice->akm_codecs = 1;
     466
    383467        switch (ice->eeprom.subvendor) {
    384468        case ICE1712_SUBDEVICE_AUDIOPHILE:
     469                snd_ice1712_akm4xxx_init(ak, &akm_audiophile, ice);
     470                break;
    385471        case ICE1712_SUBDEVICE_DELTA410:
    386                 ak->num_adcs = ak->num_dacs = 2;
    387                 ak->type = SND_AK4528;
    388                 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA410) {
    389                         ak->num_dacs = 8;
    390                         ak->type = SND_AK4529;
    391                 }
    392                 ak->cif = 0; /* the default level of the CIF pin from AK4528/4529 */
    393                 ak->data_mask = ICE1712_DELTA_AP_DOUT;
    394                 ak->clk_mask = ICE1712_DELTA_AP_CCLK;
    395                 ak->cs_mask = ak->cs_addr = ICE1712_DELTA_AP_CS_CODEC; /* select AK4528/4529 codec */
    396                 ak->cs_none = 0;
    397                 ak->add_flags = ICE1712_DELTA_AP_CS_DIGITAL; /* assert digital high */
    398                 ak->mask_flags = 0;
    399                 ak->ops.set_rate_val = delta_ak4524_set_rate_val;
    400                 snd_ice1712_ak4524_init(ice);
     472                snd_ice1712_akm4xxx_init(ak, &akm_delta410, ice);
    401473                break;
    402474        case ICE1712_SUBDEVICE_DELTA1010LT:
    403                 ak->num_adcs = ak->num_dacs = 8;
    404                 ak->type = SND_AK4524;
    405                 ak->cif = 0; /* the default level of the CIF pin from AK4524 */
    406                 ak->data_mask = ICE1712_DELTA_1010LT_DOUT;
    407                 ak->clk_mask = ICE1712_DELTA_1010LT_CCLK;
    408                 ak->cs_mask = ak->cs_addr = 0; /* set later */
    409                 ak->cs_none = ICE1712_DELTA_1010LT_CS_NONE;
    410                 ak->add_flags = 0;
    411                 ak->mask_flags = 0;
    412                 ak->ops.start = delta1010lt_ak4524_start;
    413                 ak->ops.set_rate_val = delta_ak4524_set_rate_val;
    414                 snd_ice1712_ak4524_init(ice);
     475                snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, ice);
    415476                break;
    416477        case ICE1712_SUBDEVICE_DELTA66:
    417478        case ICE1712_SUBDEVICE_DELTA44:
    418                 ak->num_adcs = ak->num_dacs = 4;
    419                 ak->type = SND_AK4524;
    420                 ak->cif = 0; /* the default level of the CIF pin from AK4524 */
    421                 ak->data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA;
    422                 ak->clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK;
    423                 ak->cs_mask = ak->cs_addr = 0; /* set later */
    424                 ak->cs_none = 0;
    425                 ak->add_flags = 0;
    426                 ak->mask_flags = 0;
    427                 ak->ops.start = delta_ak4524_start;
    428                 ak->ops.set_rate_val = delta_ak4524_set_rate_val;
    429                 snd_ice1712_ak4524_init(ice);
    430                 break;
     479                snd_ice1712_akm4xxx_init(ak, &akm_delta44, ice);
     480                break;
     481        default:
     482                snd_BUG();
     483                return -EINVAL;
    431484        }
    432485
     
    509562        case ICE1712_SUBDEVICE_DELTA44:
    510563        case ICE1712_SUBDEVICE_DELTA66:
    511                 err = snd_ice1712_ak4524_build_controls(ice);
     564                err = snd_ice1712_akm4xxx_build_controls(ice);
    512565                if (err < 0)
    513566                        return err;
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ews.c

    r215 r224  
    8484        unsigned char mask;
    8585
    86         snd_ice1712_save_gpio_status(ice, (unsigned char *)&bus->private_value);
     86        snd_ice1712_save_gpio_status(ice);
    8787        /* set RW high */
    8888        mask = ICE1712_EWX2496_RW;
     
    101101{
    102102        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
    103         snd_ice1712_restore_gpio_status(ice, (unsigned char *)&bus->private_value);
     103        snd_ice1712_restore_gpio_status(ice);
    104104}
    105105
     
    113113        if (data)
    114114                mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
    115         ice->gpio_direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
    116         ice->gpio_direction |= mask;
    117         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
     115        ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
     116        ice->gpio.direction |= mask;
     117        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
    118118        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
    119119}
     
    156156
    157157/* start callback for EWS88MT, needs to select a certain chip mask */
    158 static int ews88mt_ak4524_start(ice1712_t *ice, unsigned char *saved, int chip)
    159 {
     158static int ews88mt_ak4524_start(akm4xxx_t *ak, int chip)
     159{
     160        ice1712_t *ice = ak->chip;
    160161        unsigned char tmp;
    161162        /* assert AK4524 CS */
    162163        if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
    163164                return -EINVAL;
    164         snd_ice1712_save_gpio_status(ice, saved);
     165        snd_ice1712_save_gpio_status(ice);
    165166        tmp = ICE1712_EWS88_SERIAL_DATA |
    166167                ICE1712_EWS88_SERIAL_CLOCK |
    167168                ICE1712_EWS88_RW;
    168169        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
    169                           ice->gpio_direction | tmp);
     170                          ice->gpio.direction | tmp);
    170171        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    171172        return 0;
     
    173174
    174175/* stop callback for EWS88MT, needs to deselect chip mask */
    175 static void ews88mt_ak4524_stop(ice1712_t *ice, unsigned char *saved)
    176 {
    177         snd_ice1712_restore_gpio_status(ice, saved);
     176static void ews88mt_ak4524_stop(akm4xxx_t *ak)
     177{
     178        ice1712_t *ice = ak->chip;
     179        snd_ice1712_restore_gpio_status(ice);
    178180        udelay(1);
    179181        snd_ice1712_ews88mt_chip_select(ice, 0x0f);
     
    181183
    182184/* start callback for EWX24/96 */
    183 static int ewx2496_ak4524_start(ice1712_t *ice, unsigned char *saved, int chip)
    184 {
     185static int ewx2496_ak4524_start(akm4xxx_t *ak, int chip)
     186{
     187        ice1712_t *ice = ak->chip;
    185188        unsigned char tmp;
    186         snd_ice1712_save_gpio_status(ice, saved);
     189        snd_ice1712_save_gpio_status(ice);
    187190        tmp =  ICE1712_EWX2496_SERIAL_DATA |
    188191                ICE1712_EWX2496_SERIAL_CLOCK |
     
    190193                ICE1712_EWX2496_RW;
    191194        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
    192                           ice->gpio_direction | tmp);
     195                          ice->gpio.direction | tmp);
    193196        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    194197        return 0;
     
    196199
    197200/* start callback for DMX 6fire */
    198 static int dmx6fire_ak4524_start(ice1712_t *ice, unsigned char *saved, int chip)
    199 {
     201static int dmx6fire_ak4524_start(akm4xxx_t *ak, int chip)
     202{
     203        ice1712_t *ice = ak->chip;
    200204        unsigned char tmp;
    201         snd_ice1712_save_gpio_status(ice, saved);
    202         tmp = ice->ak4524.cs_mask = ice->ak4524.cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
     205        snd_ice1712_save_gpio_status(ice);
     206        tmp = ak->cs_mask = ak->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
    203207        tmp |= ICE1712_6FIRE_SERIAL_DATA |
    204208                ICE1712_6FIRE_SERIAL_CLOCK |
    205209                ICE1712_6FIRE_RW;
    206210        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
    207                           ice->gpio_direction | tmp);
     211                          ice->gpio.direction | tmp);
    208212        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
    209213        return 0;
     
    222226        switch (ice->eeprom.subvendor) {
    223227        case ICE1712_SUBDEVICE_EWS88MT:
     228        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    224229                snd_runtime_check(snd_i2c_sendbytes(ice->cs8404, &bits, 1) == 1, goto _error);
    225230                break;
     
    246251static int ews88_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
    247252{
    248         unsigned long flags;
    249253        unsigned int val;
    250254        int change;
    251255
    252256        val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
    253         spin_lock_irqsave(&ice->reg_lock, flags);
     257        spin_lock_irq(&ice->reg_lock);
    254258        change = ice->spdif.cs8403_bits != val;
    255259        ice->spdif.cs8403_bits = val;
    256260        if (change && ice->playback_pro_substream == NULL) {
    257                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     261                spin_unlock_irq(&ice->reg_lock);
    258262                snd_ice1712_ews_cs8404_spdif_write(ice, val);
    259263        } else {
    260                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     264                spin_unlock_irq(&ice->reg_lock);
    261265        }
    262266        return change;
     
    270274static int ews88_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
    271275{
    272         unsigned long flags;
    273276        unsigned int val;
    274277        int change;
    275278
    276279        val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
    277         spin_lock_irqsave(&ice->reg_lock, flags);
     280        spin_lock_irq(&ice->reg_lock);
    278281        change = ice->spdif.cs8403_stream_bits != val;
    279282        ice->spdif.cs8403_stream_bits = val;
    280283        if (change && ice->playback_pro_substream != NULL) {
    281                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     284                spin_unlock_irq(&ice->reg_lock);
    282285                snd_ice1712_ews_cs8404_spdif_write(ice, val);
    283286        } else {
    284                 spin_unlock_irqrestore(&ice->reg_lock, flags);
     287                spin_unlock_irq(&ice->reg_lock);
    285288        }
    286289        return change;
     
    295298
    296299/* set up SPDIF for EWS88MT / EWS88D */
    297 static void ews88_setup_spdif(ice1712_t *ice, snd_pcm_substream_t * substream)
     300static void ews88_setup_spdif(ice1712_t *ice, int rate)
    298301{
    299302        unsigned long flags;
     
    305308        if (tmp & 0x10)         /* consumer */
    306309                tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
    307         switch (substream->runtime->rate) {
     310        switch (rate) {
    308311        case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
    309312        case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
     
    321324
    322325/*
     326 */
     327static akm4xxx_t akm_ews88mt __devinitdata = {
     328        .num_adcs = 8,
     329        .num_dacs = 8,
     330        .type = SND_AK4524,
     331        .caddr = 2,
     332        .cif = 1, /* CIF high */
     333        .data_mask = ICE1712_EWS88_SERIAL_DATA,
     334        .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
     335        .cs_mask = 0,
     336        .cs_addr = 0,
     337        .cs_none = 0, /* no chip select on gpio */
     338        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
     339        .mask_flags = 0,
     340        .ops = {
     341                .start = ews88mt_ak4524_start,
     342                .stop = ews88mt_ak4524_stop
     343        }
     344};
     345
     346static akm4xxx_t akm_ewx2496 __devinitdata = {
     347        .num_adcs = 2,
     348        .num_dacs = 2,
     349        .type = SND_AK4524,
     350        .caddr = 2,
     351        .cif = 1, /* CIF high */
     352        .data_mask = ICE1712_EWS88_SERIAL_DATA,
     353        .clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
     354        .cs_mask = ICE1712_EWX2496_AK4524_CS,
     355        .cs_addr = ICE1712_EWX2496_AK4524_CS,
     356        .cs_none = 0,
     357        .add_flags = ICE1712_EWS88_RW, /* set rw bit high */
     358        .mask_flags = 0,
     359        .ops = {
     360                .start = ewx2496_ak4524_start
     361        }
     362};
     363
     364static akm4xxx_t akm_6fire __devinitdata = {
     365        .num_adcs = 6,
     366        .num_dacs = 6,
     367        .type = SND_AK4524,
     368        .caddr = 2,
     369        .cif = 1, /* CIF high */
     370        .data_mask = ICE1712_6FIRE_SERIAL_DATA,
     371        .clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
     372        .cs_mask = 0,
     373        .cs_addr = 0, /* set later */
     374        .cs_none = 0,
     375        .add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
     376        .mask_flags = 0,
     377        .ops = {
     378                .start = dmx6fire_ak4524_start
     379        }
     380};
     381
     382
     383/*
    323384 * initialize the chip
    324385 */
     
    327388{
    328389        int err;
    329         ak4524_t *ak;
     390        akm4xxx_t *ak;
    330391
    331392        /* set the analog DACs */
     
    335396                break; 
    336397        case ICE1712_SUBDEVICE_EWS88MT:
     398        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    337399                ice->num_total_dacs = 8;
    338400                break;
     
    361423                break;
    362424        case ICE1712_SUBDEVICE_EWS88MT:
     425        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    363426                if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->cs8404)) < 0)
    364427                        return err;
     
    383446                        return err;
    384447                break;
    385 #if 0 // XXX not working...
    386448        case ICE1712_SUBDEVICE_DMX6FIRE:
    387449                if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
    388450                        return err;
    389 #endif
     451                break;
    390452        case ICE1712_SUBDEVICE_EWS88MT:
     453        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    391454        case ICE1712_SUBDEVICE_EWS88D:
    392455                /* set up CS8404 */
    393456                ice->spdif.ops.open = ews88_open_spdif;
    394                 ice->spdif.ops.setup = ews88_setup_spdif;
     457                ice->spdif.ops.setup_rate = ews88_setup_spdif;
    395458                ice->spdif.ops.default_get = ews88_spdif_default_get;
    396459                ice->spdif.ops.default_put = ews88_spdif_default_put;
     
    402465        }
    403466
     467        /* no analog? */
     468        switch (ice->eeprom.subvendor) {
     469        case ICE1712_SUBDEVICE_EWS88D:
     470                return 0;
     471        }
     472
    404473        /* analog section */
    405         ak = &ice->ak4524;
     474        ak = ice->akm = kmalloc(sizeof(akm4xxx_t), GFP_KERNEL);
     475        if (! ak)
     476                return -ENOMEM;
     477        ice->akm_codecs = 1;
     478
    406479        switch (ice->eeprom.subvendor) {
    407480        case ICE1712_SUBDEVICE_EWS88MT:
    408                 ak->num_adcs = ak->num_dacs = 8;
    409                 ak->type = SND_AK4524;
    410                 ak->cif = 1; /* CIF high */
    411                 ak->data_mask = ICE1712_EWS88_SERIAL_DATA;
    412                 ak->clk_mask = ICE1712_EWS88_SERIAL_CLOCK;
    413                 ak->cs_mask = ak->cs_addr = ak->cs_none = 0; /* no chip select on gpio */
    414                 ak->add_flags = ICE1712_EWS88_RW; /* set rw bit high */
    415                 ak->mask_flags = 0;
    416                 ak->ops.start = ews88mt_ak4524_start;
    417                 ak->ops.stop = ews88mt_ak4524_stop;
    418                 snd_ice1712_ak4524_init(ice);
     481        case ICE1712_SUBDEVICE_EWS88MT_NEW:
     482                snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, ice);
    419483                break;
    420484        case ICE1712_SUBDEVICE_EWX2496:
    421                 ak->num_adcs = ak->num_dacs = 2;
    422                 ak->type = SND_AK4524;
    423                 ak->cif = 1; /* CIF high */
    424                 ak->data_mask = ICE1712_EWS88_SERIAL_DATA;
    425                 ak->clk_mask = ICE1712_EWS88_SERIAL_CLOCK;
    426                 ak->cs_mask = ak->cs_addr = ICE1712_EWX2496_AK4524_CS;
    427                 ak->cs_none = 0;
    428                 ak->add_flags = ICE1712_EWS88_RW; /* set rw bit high */
    429                 ak->mask_flags = 0;
    430                 ak->ops.start = ewx2496_ak4524_start;
    431                 snd_ice1712_ak4524_init(ice);
     485                snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, ice);
    432486                break;
    433487        case ICE1712_SUBDEVICE_DMX6FIRE:
    434                 ak->num_adcs = ak->num_dacs = 6;
    435                 ak->type = SND_AK4524;
    436                 ak->cif = 1; /* CIF high */
    437                 ak->data_mask = ICE1712_6FIRE_SERIAL_DATA;
    438                 ak->clk_mask = ICE1712_6FIRE_SERIAL_CLOCK;
    439                 ak->cs_mask = ak->cs_addr = 0; /* set later */
    440                 ak->cs_none = 0;
    441                 ak->add_flags = ICE1712_6FIRE_RW; /* set rw bit high */
    442                 ak->mask_flags = 0;
    443                 ak->ops.start = dmx6fire_ak4524_start;
    444                 snd_ice1712_ak4524_init(ice);
     488                snd_ice1712_akm4xxx_init(ak, &akm_6fire, ice);
    445489                break;
    446490        }
     
    472516        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    473517        unsigned char mask = kcontrol->private_value & 0xff;
    474         unsigned char saved[2];
    475518       
    476         snd_ice1712_save_gpio_status(ice, saved);
     519        snd_ice1712_save_gpio_status(ice);
    477520        ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
    478         snd_ice1712_restore_gpio_status(ice, saved);
     521        snd_ice1712_restore_gpio_status(ice);
    479522        return 0;
    480523}
     
    484527        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    485528        unsigned char mask = kcontrol->private_value & 0xff;
    486         unsigned char saved[2];
    487529        int val, nval;
    488530
     
    490532                return -EPERM;
    491533        nval = ucontrol->value.enumerated.item[0] ? mask : 0;
    492         snd_ice1712_save_gpio_status(ice, saved);
     534        snd_ice1712_save_gpio_status(ice);
    493535        val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
    494536        nval |= val & ~mask;
    495537        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
    496         snd_ice1712_restore_gpio_status(ice, saved);
     538        snd_ice1712_restore_gpio_status(ice);
    497539        return val != nval;
    498540}
     
    851893static int __devinit snd_ice1712_ews_add_controls(ice1712_t *ice)
    852894{
    853         int err, idx;
     895        unsigned int idx;
     896        int err;
    854897        snd_kcontrol_t *kctl;
    855898       
     
    863906        case ICE1712_SUBDEVICE_EWX2496:
    864907        case ICE1712_SUBDEVICE_EWS88MT:
     908        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    865909        case ICE1712_SUBDEVICE_DMX6FIRE:
    866                 err = snd_ice1712_ak4524_build_controls(ice);
     910                err = snd_ice1712_akm4xxx_build_controls(ice);
    867911                if (err < 0)
    868912                        return err;
     
    873917        switch (ice->eeprom.subvendor) {
    874918        case ICE1712_SUBDEVICE_EWX2496:
    875                 for (idx = 0; idx < sizeof(snd_ice1712_ewx2496_controls)/sizeof(snd_ice1712_ewx2496_controls[0]); idx++) {
     919                for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
    876920                        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
    877921                        if (err < 0)
     
    880924                break;
    881925        case ICE1712_SUBDEVICE_EWS88MT:
     926        case ICE1712_SUBDEVICE_EWS88MT_NEW:
    882927                for (idx = 0; idx < 8; idx++) {
    883928                        kctl = snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice);
     
    892937                break;
    893938        case ICE1712_SUBDEVICE_EWS88D:
    894                 for (idx = 0; idx < sizeof(snd_ice1712_ews88d_controls)/sizeof(snd_ice1712_ews88d_controls[0]); idx++) {
     939                for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
    895940                        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
    896941                        if (err < 0)
     
    899944                break;
    900945        case ICE1712_SUBDEVICE_DMX6FIRE:
    901                 for (idx = 0; idx < sizeof(snd_ice1712_6fire_controls)/sizeof(snd_ice1712_6fire_controls[0]); idx++) {
     946                for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
    902947                        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
    903948                        if (err < 0)
     
    914959        {
    915960                ICE1712_SUBDEVICE_EWX2496,
    916                 "TerraTec EWX 24/96",
     961                "TerraTec EWX24/96",
    917962                snd_ice1712_ews_init,
    918963                snd_ice1712_ews_add_controls,
     
    920965        {
    921966                ICE1712_SUBDEVICE_EWS88MT,
    922                 "TerraTec EWS 88MT",
     967                "TerraTec EWS88MT",
     968                snd_ice1712_ews_init,
     969                snd_ice1712_ews_add_controls,
     970        },
     971        {
     972                ICE1712_SUBDEVICE_EWS88MT_NEW,
     973                "TerraTec EWS88MT",
    923974                snd_ice1712_ews_init,
    924975                snd_ice1712_ews_add_controls,
     
    926977        {
    927978                ICE1712_SUBDEVICE_EWS88D,
    928                 "TerraTec EWS 88D",
     979                "TerraTec EWS88D",
    929980                snd_ice1712_ews_init,
    930981                snd_ice1712_ews_add_controls,
     
    932983        {
    933984                ICE1712_SUBDEVICE_DMX6FIRE,
    934                 "TerraTec DMX 6Fire",
     985                "TerraTec DMX6Fire",
    935986                snd_ice1712_ews_init,
    936987                snd_ice1712_ews_add_controls,
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ews.h

    r212 r224  
    3434#define ICE1712_SUBDEVICE_EWX2496       0x3b153011
    3535#define ICE1712_SUBDEVICE_EWS88MT       0x3b151511
     36#define ICE1712_SUBDEVICE_EWS88MT_NEW   0x3b152511
    3637#define ICE1712_SUBDEVICE_EWS88D        0x3b152b11
    3738#define ICE1712_SUBDEVICE_DMX6FIRE      0x3b153811
     
    7778
    7879#define ICE1712_6FIRE_PCF9554_ADDR      (0x40>>1)
    79 #define ICE1712_6FIRE_CS8427_ADDR       (0x22>>1)
     80#define ICE1712_6FIRE_CS8427_ADDR       (0x22)
    8081
    8182#endif /* __SOUND_EWS_H */
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.c

    r215 r224  
    3333 *      is stored in the local file and called from registration
    3434 *      function from card_info struct.
     35 *
     36 *  2002.11.26  James Stafford <jstafford@ampltd.com>
     37 *      Added support for VT1724 (Envy24HT)
     38 *      I have left out support for 176.4 and 192 KHz for the moment.
     39 *  I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
     40 *
     41 *  2003.02.20  Taksahi Iwai <tiwai@suse.de>
     42 *      Split vt1724 part to an independent driver.
     43 *      The GPIO is accessed through the callback functions now.
    3544 */
    3645
     
    96105
    97106static struct pci_device_id snd_ice1712_ids[] __devinitdata = {
    98         { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* ICE1712 */
     107        { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },   /* ICE1712 */
    99108        { 0, }
    100109};
     
    113122 */
    114123 
     124/* check whether the clock mode is spdif-in */
    115125static inline int is_spdif_master(ice1712_t *ice)
    116126{
     
    240250}
    241251
     252/*
     253 * consumer ac97 digital mix
     254 */
    242255static int snd_ice1712_digmix_route_ac97_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
    243256{
     
    252265{
    253266        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    254         unsigned long flags;
    255267       
    256         spin_lock_irqsave(&ice->reg_lock, flags);
    257268        ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
    258         spin_unlock_irqrestore(&ice->reg_lock, flags);
    259269        return 0;
    260270}
     
    264274        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    265275        unsigned char val, nval;
    266         unsigned long flags;
    267276       
    268         spin_lock_irqsave(&ice->reg_lock, flags);
     277        spin_lock_irq(&ice->reg_lock);
    269278        val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
    270279        nval = val & ~ICE1712_ROUTE_AC97;
    271280        if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
    272281        outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
    273         spin_unlock_irqrestore(&ice->reg_lock, flags);
     282        spin_unlock_irq(&ice->reg_lock);
    274283        return val != nval;
    275284}
     
    284293
    285294
    286 
    287295/*
    288  * set gpio direction, write mask and data
     296 * gpio operations
    289297 */
    290 void snd_ice1712_gpio_write_bits(ice1712_t *ice, int mask, int bits)
    291 {
    292         ice->gpio_direction |= mask;
    293         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
    294         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
    295         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, mask & bits);
    296 }
    297 
    298 /*
    299  */
    300 void snd_ice1712_save_gpio_status(ice1712_t *ice, unsigned char *tmp)
    301 {
    302         down(&ice->gpio_mutex);
    303         tmp[0] = ice->gpio_direction;
    304         tmp[1] = ice->gpio_write_mask;
    305 }
    306 
    307 void snd_ice1712_restore_gpio_status(ice1712_t *ice, unsigned char *tmp)
    308 {
    309         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, tmp[0]);
    310         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, tmp[1]);
    311         ice->gpio_direction = tmp[0];
    312         ice->gpio_write_mask = tmp[1];
    313         up(&ice->gpio_mutex);
     298static void snd_ice1712_set_gpio_dir(ice1712_t *ice, unsigned int data)
     299{
     300        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
     301}
     302
     303static void snd_ice1712_set_gpio_mask(ice1712_t *ice, unsigned int data)
     304{
     305        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
     306}
     307
     308static unsigned int snd_ice1712_get_gpio_data(ice1712_t *ice)
     309{
     310        return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
     311}
     312
     313static void snd_ice1712_set_gpio_data(ice1712_t *ice, unsigned int val)
     314{
     315        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
    314316}
    315317
     
    370372}
    371373
    372 static void setup_cs8427(ice1712_t *ice, snd_pcm_substream_t * substream)
    373 {
    374         snd_cs8427_iec958_pcm(ice->cs8427, substream->runtime->rate);
     374static void setup_cs8427(ice1712_t *ice, int rate)
     375{
     376        snd_cs8427_iec958_pcm(ice->cs8427, rate);
    375377}
    376378
     
    388390        ice->spdif.ops.open = open_cs8427;
    389391        ice->spdif.ops.close = close_cs8427;
    390         ice->spdif.ops.setup = setup_cs8427;
     392        ice->spdif.ops.setup_rate = setup_cs8427;
    391393        return 0;
    392394}
     
    556558static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
    557559{
    558         unsigned long flags;
    559560        ice1712_t *ice = snd_pcm_substream_chip(substream);
    560561        snd_pcm_runtime_t *runtime = substream->runtime;
     
    571572        if (rate > 0x000fffff)
    572573                rate = 0x000fffff;
    573         spin_lock_irqsave(&ice->reg_lock, flags);
     574        spin_lock(&ice->reg_lock);
    574575        outb(0, ice->ddma_port + 15);
    575576        outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
     
    584585        snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
    585586        snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
    586         spin_unlock_irqrestore(&ice->reg_lock, flags);
     587        spin_unlock(&ice->reg_lock);
    587588        return 0;
    588589}
     
    590591static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
    591592{
    592         unsigned long flags;
    593593        ice1712_t *ice = snd_pcm_substream_chip(substream);
    594594        snd_pcm_runtime_t *runtime = substream->runtime;
     
    608608        ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
    609609        chn = substream->number * 2;
    610         spin_lock_irqsave(&ice->reg_lock, flags);
     610        spin_lock(&ice->reg_lock);
    611611        snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
    612612        snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
     
    620620                snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
    621621        }
    622         spin_unlock_irqrestore(&ice->reg_lock, flags);
     622        spin_unlock(&ice->reg_lock);
    623623        return 0;
    624624}
     
    626626static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
    627627{
    628         unsigned long flags;
    629628        ice1712_t *ice = snd_pcm_substream_chip(substream);
    630629        snd_pcm_runtime_t *runtime = substream->runtime;
     
    639638        if (runtime->channels == 2)
    640639                tmp &= ~0x02;
    641         spin_lock_irqsave(&ice->reg_lock, flags);
     640        spin_lock(&ice->reg_lock);
    642641        outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
    643642        outw(buf_size, ICEREG(ice, CONCAP_COUNT));
     
    645644        snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
    646645        snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
    647         spin_unlock_irqrestore(&ice->reg_lock, flags);
     646        spin_unlock(&ice->reg_lock);
    648647        snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
    649648        return 0;
     
    763762        snd_pcm_runtime_t *runtime = substream->runtime;
    764763        ice1712_t *ice = snd_pcm_substream_chip(substream);
    765         unsigned long flags;
    766764        u32 tmp;
    767765
    768766        ice->playback_con_substream_ds[substream->number] = substream;
    769767        runtime->hw = snd_ice1712_playback_ds;
    770         spin_lock_irqsave(&ice->reg_lock, flags);
     768        spin_lock_irq(&ice->reg_lock);
    771769        tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
    772770        outw(tmp, ICEDS(ice, INTMASK));
    773         spin_unlock_irqrestore(&ice->reg_lock, flags);
     771        spin_unlock_irq(&ice->reg_lock);
    774772        return 0;
    775773}
     
    799797{
    800798        ice1712_t *ice = snd_pcm_substream_chip(substream);
    801         unsigned long flags;
    802799        u32 tmp;
    803800
    804         spin_lock_irqsave(&ice->reg_lock, flags);
     801        spin_lock_irq(&ice->reg_lock);
    805802        tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
    806803        outw(tmp, ICEDS(ice, INTMASK));
    807         spin_unlock_irqrestore(&ice->reg_lock, flags);
     804        spin_unlock_irq(&ice->reg_lock);
    808805        ice->playback_con_substream_ds[substream->number] = NULL;
    809806        return 0;
     
    967964                unsigned int old;
    968965                snd_pcm_substream_t *s = substream;
     966
    969967                do {
    970968                        if (s == ice->playback_pro_substream) {
     
    995993/*
    996994 */
    997 static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int do_not_lock)
     995static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
    998996{
    999997        unsigned long flags;
    1000998        unsigned char val;
    1001         int old_lock_value;
     999        unsigned int i;
    10021000
    10031001        spin_lock_irqsave(&ice->reg_lock, flags);
    1004         old_lock_value = PRO_RATE_LOCKED;
    1005         if (do_not_lock)
    1006                 PRO_RATE_LOCKED = 0;
    10071002        if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
    10081003                                                  ICE1712_PLAYBACK_PAUSE|
     
    10111006                return;
    10121007        }
    1013         if (!is_pro_rate_locked(ice))
    1014                 goto __unlock;
     1008        if (!force && is_pro_rate_locked(ice)) {
     1009                spin_unlock_irqrestore(&ice->reg_lock, flags);
     1010                return;
     1011        }
    10151012
    10161013        switch (rate) {
     
    10341031        }
    10351032        outb(val, ICEMT(ice, RATE));
    1036         PRO_RATE_LOCKED = old_lock_value;
    1037 
    1038       __unlock:
     1033
    10391034        spin_unlock_irqrestore(&ice->reg_lock, flags);
    10401035
    1041         if (ice->ak4524.ops.set_rate_val)
    1042                 ice->ak4524.ops.set_rate_val(ice, rate);
     1036        for (i = 0; i < ice->akm_codecs; i++) {
     1037                if (ice->akm[i].ops.set_rate_val)
     1038                        ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
     1039        }
    10431040}
    10441041
    10451042static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
    10461043{
    1047         unsigned long flags;
    10481044        ice1712_t *ice = snd_pcm_substream_chip(substream);
    10491045
    10501046        ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
    1051         snd_ice1712_set_pro_rate(ice, substream->runtime->rate, 0);
    1052         spin_lock_irqsave(&ice->reg_lock, flags);
     1047        spin_lock(&ice->reg_lock);
    10531048        outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
    10541049        outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
    10551050        outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
    1056                 spin_unlock_irqrestore(&ice->reg_lock, flags);
    1057 
    1058         if (ice->spdif.ops.setup)
    1059                 ice->spdif.ops.setup(ice, substream);
    1060 
    1061         return 0;
     1051        spin_unlock(&ice->reg_lock);
     1052
     1053        return 0;
     1054}
     1055
     1056static int snd_ice1712_playback_pro_hw_params(snd_pcm_substream_t * substream,
     1057                                              snd_pcm_hw_params_t * hw_params)
     1058{
     1059        ice1712_t *ice = snd_pcm_substream_chip(substream);
     1060
     1061        snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
     1062        if (ice->spdif.ops.setup_rate)
     1063                ice->spdif.ops.setup_rate(ice, params_rate(hw_params));
     1064        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    10621065}
    10631066
    10641067static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
    10651068{
    1066         unsigned long flags;
    10671069        ice1712_t *ice = snd_pcm_substream_chip(substream);
    10681070
    10691071        ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
    1070         snd_ice1712_set_pro_rate(ice, substream->runtime->rate, 0);
    1071         spin_lock_irqsave(&ice->reg_lock, flags);
     1072        spin_lock(&ice->reg_lock);
    10721073        outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
    10731074        outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
    10741075        outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
    1075         spin_unlock_irqrestore(&ice->reg_lock, flags);
    1076         return 0;
     1076        spin_unlock(&ice->reg_lock);
     1077        return 0;
     1078}
     1079
     1080static int snd_ice1712_capture_pro_hw_params(snd_pcm_substream_t * substream,
     1081                                             snd_pcm_hw_params_t * hw_params)
     1082{
     1083        ice1712_t *ice = snd_pcm_substream_chip(substream);
     1084
     1085        snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
     1086        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    10771087}
    10781088
     
    12031213        .close =        snd_ice1712_playback_pro_close,
    12041214        .ioctl =        snd_pcm_lib_ioctl,
    1205         .hw_params =    snd_ice1712_hw_params,
     1215        .hw_params =    snd_ice1712_playback_pro_hw_params,
    12061216        .hw_free =      snd_ice1712_hw_free,
    12071217        .prepare =      snd_ice1712_playback_pro_prepare,
     
    12141224        .close =        snd_ice1712_capture_pro_close,
    12151225        .ioctl =        snd_pcm_lib_ioctl,
    1216         .hw_params =    snd_ice1712_hw_params,
     1226        .hw_params =    snd_ice1712_capture_pro_hw_params,
    12171227        .hw_free =      snd_ice1712_hw_free,
    12181228        .prepare =      snd_ice1712_capture_pro_prepare,
     
    12871297{
    12881298        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1289         unsigned long flags;
    12901299        int index = kcontrol->private_value;
    12911300       
    1292         spin_lock_irqsave(&ice->reg_lock, flags);
     1301        spin_lock_irq(&ice->reg_lock);
    12931302        ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
    12941303        ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
    1295         spin_unlock_irqrestore(&ice->reg_lock, flags);
     1304        spin_unlock_irq(&ice->reg_lock);
    12961305        return 0;
    12971306}
     
    12991308static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13001309{
    1301         unsigned long flags;
    13021310        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    13031311        int index = kcontrol->private_value;
     
    13061314        nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
    13071315               (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
    1308         spin_lock_irqsave(&ice->reg_lock, flags);
     1316        spin_lock_irq(&ice->reg_lock);
    13091317        nval |= ice->pro_volumes[index] & ~0x80008000;
    13101318        change = nval != ice->pro_volumes[index];
    13111319        ice->pro_volumes[index] = nval;
    13121320        snd_ice1712_update_volume(ice, index);
    1313         spin_unlock_irqrestore(&ice->reg_lock, flags);
     1321        spin_unlock_irq(&ice->reg_lock);
    13141322        return change;
    13151323}
     
    13271335{
    13281336        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1329         unsigned long flags;
    13301337        int index = kcontrol->private_value;
    13311338       
    1332         spin_lock_irqsave(&ice->reg_lock, flags);
     1339        spin_lock_irq(&ice->reg_lock);
    13331340        ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
    13341341        ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
    1335         spin_unlock_irqrestore(&ice->reg_lock, flags);
     1342        spin_unlock_irq(&ice->reg_lock);
    13361343        return 0;
    13371344}
     
    13391346static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    13401347{
    1341         unsigned long flags;
    13421348        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    13431349        int index = kcontrol->private_value;
     
    13461352        nval = (ucontrol->value.integer.value[0] & 127) |
    13471353               ((ucontrol->value.integer.value[1] & 127) << 16);
    1348         spin_lock_irqsave(&ice->reg_lock, flags);
     1354        spin_lock_irq(&ice->reg_lock);
    13491355        nval |= ice->pro_volumes[index] & ~0x007f007f;
    13501356        change = nval != ice->pro_volumes[index];
    13511357        ice->pro_volumes[index] = nval;
    13521358        snd_ice1712_update_volume(ice, index);
    1353         spin_unlock_irqrestore(&ice->reg_lock, flags);
     1359        spin_unlock_irq(&ice->reg_lock);
    13541360        return change;
    13551361}
    13561362
    13571363
    1358 static int __init snd_ice1712_build_pro_mixer(ice1712_t *ice)
     1364static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
    13591365{
    13601366        snd_card_t * card = ice->card;
     
    14361442        int err;
    14371443
    1438         if (!(ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97)) {
     1444        if (ice_has_con_ac97(ice)) {
    14391445                ac97_t ac97;
    14401446                memset(&ac97, 0, sizeof(ac97));
     
    14511457                }
    14521458        }
    1453         /* hmm.. can we have both consumer and pro ac97 mixers? */
    1454         if (! (ice->eeprom.aclink & ICE1712_CFG_PRO_I2S)) {
     1459
     1460        if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
    14551461                ac97_t ac97;
    14561462                memset(&ac97, 0, sizeof(ac97));
     
    14731479 */
    14741480
     1481static inline unsigned int eeprom_double(ice1712_t *ice, int idx)
     1482{
     1483        return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
     1484}
     1485
    14751486static void snd_ice1712_proc_read(snd_info_entry_t *entry,
    14761487                                  snd_info_buffer_t * buffer)
     
    14791490        unsigned int idx;
    14801491
    1481         snd_iprintf(buffer, "ICE1712\n\n");
     1492        snd_iprintf(buffer, "%s\n\n", ice->card->longname);
    14821493        snd_iprintf(buffer, "EEPROM:\n");
     1494
    14831495        snd_iprintf(buffer, "  Subvendor        : 0x%x\n", ice->eeprom.subvendor);
    14841496        snd_iprintf(buffer, "  Size             : %i bytes\n", ice->eeprom.size);
    14851497        snd_iprintf(buffer, "  Version          : %i\n", ice->eeprom.version);
    1486         snd_iprintf(buffer, "  Codec            : 0x%x\n", ice->eeprom.codec);
    1487         snd_iprintf(buffer, "  ACLink           : 0x%x\n", ice->eeprom.aclink);
    1488         snd_iprintf(buffer, "  I2S ID           : 0x%x\n", ice->eeprom.i2sID);
    1489         snd_iprintf(buffer, "  S/PDIF           : 0x%x\n", ice->eeprom.spdif);
     1498        snd_iprintf(buffer, "  Codec            : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
     1499        snd_iprintf(buffer, "  ACLink           : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
     1500        snd_iprintf(buffer, "  I2S ID           : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
     1501        snd_iprintf(buffer, "  S/PDIF           : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
    14901502        snd_iprintf(buffer, "  GPIO mask        : 0x%x\n", ice->eeprom.gpiomask);
    14911503        snd_iprintf(buffer, "  GPIO state       : 0x%x\n", ice->eeprom.gpiostate);
    14921504        snd_iprintf(buffer, "  GPIO direction   : 0x%x\n", ice->eeprom.gpiodir);
    1493         snd_iprintf(buffer, "  AC'97 main       : 0x%x\n", ice->eeprom.ac97main);
    1494         snd_iprintf(buffer, "  AC'97 pcm        : 0x%x\n", ice->eeprom.ac97pcm);
    1495         snd_iprintf(buffer, "  AC'97 record     : 0x%x\n", ice->eeprom.ac97rec);
    1496         snd_iprintf(buffer, "  AC'97 record src : 0x%x\n", ice->eeprom.ac97recsrc);
     1505        snd_iprintf(buffer, "  AC'97 main       : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
     1506        snd_iprintf(buffer, "  AC'97 pcm        : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
     1507        snd_iprintf(buffer, "  AC'97 record     : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
     1508        snd_iprintf(buffer, "  AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
    14971509        for (idx = 0; idx < 4; idx++)
    1498                 snd_iprintf(buffer, "  DAC ID #%i        : 0x%x\n", idx, ice->eeprom.dacID[idx]);
     1510                snd_iprintf(buffer, "  DAC ID #%i        : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
    14991511        for (idx = 0; idx < 4; idx++)
    1500                 snd_iprintf(buffer, "  ADC ID #%i        : 0x%x\n", idx, ice->eeprom.adcID[idx]);
    1501         for (idx = 0x1c; idx < ice->eeprom.size && idx < 0x1c + sizeof(ice->eeprom.extra); idx++)
    1502                 snd_iprintf(buffer, "  Extra #%02i        : 0x%x\n", idx, ice->eeprom.extra[idx - 0x1c]);
     1512                snd_iprintf(buffer, "  ADC ID #%i        : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
     1513        for (idx = 0x1c; idx < ice->eeprom.size; idx++)
     1514                snd_iprintf(buffer, "  Extra #%02i        : 0x%x\n", idx, ice->eeprom.data[idx]);
     1515
     1516        snd_iprintf(buffer, "\nRegisters:\n");
     1517        snd_iprintf(buffer, "  PSDOUT03         : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
     1518        snd_iprintf(buffer, "  CAPTURE          : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
     1519        snd_iprintf(buffer, "  SPDOUT           : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
     1520        snd_iprintf(buffer, "  RATE             : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
    15031521}
    15041522
     
    15071525        snd_info_entry_t *entry;
    15081526
    1509         if ((entry = snd_info_create_card_entry(ice->card, "ice1712", ice->card->proc_root)) != NULL) {
    1510                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    1511                 entry->private_data = ice;
    1512                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    1513                 entry->c.text.read_size = 2048;
    1514                 entry->c.text.read = snd_ice1712_proc_read;
    1515                 if (snd_info_register(entry) < 0) {
    1516                         snd_info_free_entry(entry);
    1517                         entry = NULL;
    1518                 }
    1519         }
    1520         ice->proc_entry = entry;
    1521 }
    1522 
    1523 static void snd_ice1712_proc_done(ice1712_t * ice)
    1524 {
    1525         if (ice->proc_entry) {
    1526                 snd_info_unregister(ice->proc_entry);
    1527                 ice->proc_entry = NULL;
    1528         }
     1527        if (! snd_card_proc_new(ice->card, "ice1712", &entry))
     1528                snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
    15291529}
    15301530
     
    15361536{
    15371537        uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
    1538         uinfo->count = 32;
     1538        uinfo->count = sizeof(ice1712_eeprom_t);
    15391539        return 0;
    15401540}
     
    15441544        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    15451545       
    1546         memcpy(ucontrol->value.bytes.data, &ice->eeprom, 32);
     1546        memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
    15471547        return 0;
    15481548}
     
    15851585static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
    15861586{
    1587         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    1588         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
     1587        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1588        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
    15891589        .info =         snd_ice1712_spdif_info,
    15901590        .get =          snd_ice1712_spdif_default_get,
     
    16361636static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
    16371637{
    1638         .access =               SNDRV_CTL_ELEM_ACCESS_READ,
    1639         .iface =                SNDRV_CTL_ELEM_IFACE_MIXER,
    1640         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
     1638        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     1639        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     1640        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
    16411641        .info =         snd_ice1712_spdif_info,
    16421642        .get =          snd_ice1712_spdif_maskc_get,
     
    16451645static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
    16461646{
    1647         .access =               SNDRV_CTL_ELEM_ACCESS_READ,
    1648         .iface =                SNDRV_CTL_ELEM_IFACE_MIXER,
    1649         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
     1647        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
     1648        .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
     1649        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
    16501650        .info =         snd_ice1712_spdif_info,
    16511651        .get =          snd_ice1712_spdif_maskp_get,
     
    16721672static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
    16731673{
    1674         .access =               SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
    1675         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    1676         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
     1674        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
     1675        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1676        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
    16771677        .info =         snd_ice1712_spdif_info,
    16781678        .get =          snd_ice1712_spdif_stream_get,
     
    16941694        unsigned char mask = kcontrol->private_value & 0xff;
    16951695        int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
    1696         unsigned char saved[2];
    16971696       
    1698         snd_ice1712_save_gpio_status(ice, saved);
    1699         ucontrol->value.integer.value[0] = (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0) ^ invert;
    1700         snd_ice1712_restore_gpio_status(ice, saved);
     1697        snd_ice1712_save_gpio_status(ice);
     1698        ucontrol->value.integer.value[0] = (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
     1699        snd_ice1712_restore_gpio_status(ice);
    17011700        return 0;
    17021701}
     
    17071706        unsigned char mask = kcontrol->private_value & 0xff;
    17081707        int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
    1709         unsigned char saved[2];
    1710         int val, nval;
     1708        unsigned int val, nval;
    17111709
    17121710        if (kcontrol->private_value & (1 << 31))
    17131711                return -EPERM;
    17141712        nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
    1715         snd_ice1712_save_gpio_status(ice, saved);
    1716         val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
     1713        snd_ice1712_save_gpio_status(ice);
     1714        val = snd_ice1712_gpio_read(ice);
    17171715        nval |= val & ~mask;
    1718         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
    1719         snd_ice1712_restore_gpio_status(ice, saved);
     1716        if (val != nval)
     1717                snd_ice1712_gpio_write(ice, nval);
     1718        snd_ice1712_restore_gpio_status(ice);
    17201719        return val != nval;
    17211720}
     
    17901789        } else {
    17911790                PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
     1791                spin_unlock_irq(&ice->reg_lock);
    17921792                snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
     1793                spin_lock_irq(&ice->reg_lock);
    17931794        }
    17941795        change = inb(ICEMT(ice, RATE)) != oval;
     1796        spin_unlock_irq(&ice->reg_lock);
    17951797
    17961798        if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
     
    18001802                }
    18011803                /* notify ak4524 chip as well */
    1802                 if (is_spdif_master(ice) && ice->ak4524.ops.set_rate_val)
    1803                         ice->ak4524.ops.set_rate_val(ice, 0);
     1804                if (is_spdif_master(ice)) {
     1805                        unsigned int i;
     1806                        for (i = 0; i < ice->akm_codecs; i++) {
     1807                                if (ice->akm[i].ops.set_rate_val)
     1808                                        ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
     1809                        }
     1810                }
    18041811        }
    18051812
     
    19061913        int idx = kcontrol->id.index;
    19071914        unsigned int val, cval;
     1915
     1916        spin_lock_irq(&ice->reg_lock);
    19081917        val = inw(ICEMT(ice, ROUTE_PSDOUT03));
     1918        cval = inl(ICEMT(ice, ROUTE_CAPTURE));
     1919        spin_unlock_irq(&ice->reg_lock);
     1920
    19091921        val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
    19101922        val &= 3;
    1911         cval = inl(ICEMT(ice, ROUTE_CAPTURE));
    19121923        cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
    19131924        if (val == 1 && idx < 2)
     
    19391950                nval = 0; /* pcm */
    19401951        shift = ((idx % 2) * 8) + ((idx / 2) * 2);
     1952        spin_lock_irq(&ice->reg_lock);
    19411953        val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
    19421954        val &= ~(0x03 << shift);
     
    19451957        if (change)
    19461958                outw(val, ICEMT(ice, ROUTE_PSDOUT03));
     1959        spin_unlock_irq(&ice->reg_lock);
    19471960        if (nval < 2) /* dig mixer of pcm */
    19481961                return change;
    19491962
    19501963        /* update CAPTURE */
     1964        spin_lock_irq(&ice->reg_lock);
    19511965        val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
    19521966        shift = ((idx / 2) * 8) + ((idx % 2) * 4);
     
    19641978                outl(val, ICEMT(ice, ROUTE_CAPTURE));
    19651979        }
     1980        spin_unlock_irq(&ice->reg_lock);
    19661981        return change;
    19671982}
     
    19942009       
    19952010        /* update SPDOUT */
     2011        spin_lock_irq(&ice->reg_lock);
    19962012        val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
    19972013        if (ucontrol->value.enumerated.item[0] >= 11)
     
    20192035        if (change)
    20202036                outw(val, ICEMT(ice, ROUTE_SPDOUT));
     2037        spin_unlock_irq(&ice->reg_lock);
    20212038        return change;
    20222039}
     
    20512068{
    20522069        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    2053         unsigned long flags;
    20542070       
    2055         spin_lock_irqsave(&ice->reg_lock, flags);
    20562071        ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
    2057         spin_unlock_irqrestore(&ice->reg_lock, flags);
    20582072        return 0;
    20592073}
     
    20612075static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    20622076{
    2063         unsigned long flags;
    20642077        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    20652078        int change;
    20662079
    2067         spin_lock_irqsave(&ice->reg_lock, flags);
     2080        spin_lock_irq(&ice->reg_lock);
    20682081        change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
    20692082        outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
    2070         spin_unlock_irqrestore(&ice->reg_lock, flags);
     2083        spin_unlock_irq(&ice->reg_lock);
    20712084        return change;
    20722085}
     
    20922105{
    20932106        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    2094         unsigned long flags;
    20952107        int idx;
    20962108       
    2097         spin_lock_irqsave(&ice->reg_lock, flags);
     2109        spin_lock_irq(&ice->reg_lock);
    20982110        for (idx = 0; idx < 22; idx++) {
    20992111                outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
    21002112                ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
    21012113        }
    2102         spin_unlock_irqrestore(&ice->reg_lock, flags);
     2114        spin_unlock_irq(&ice->reg_lock);
    21032115        return 0;
    21042116}
     
    21312143{
    21322144        int dev = 0xa0;         /* EEPROM device address */
    2133         unsigned int idx;
     2145        unsigned int i;
    21342146
    21352147        if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) == 0) {
     
    21422154                                (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
    21432155        ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
    2144         if (ice->eeprom.size < 28) {
     2156        if (ice->eeprom.size > 32) {
    21452157                snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size);
    21462158                return -EIO;
     
    21492161        if (ice->eeprom.version != 1) {
    21502162                snd_printk("invalid EEPROM version %i\n", ice->eeprom.version);
    2151                 return -EIO;
    2152         }
    2153         ice->eeprom.codec = snd_ice1712_read_i2c(ice, dev, 0x06);
    2154         ice->eeprom.aclink = snd_ice1712_read_i2c(ice, dev, 0x07);
    2155         ice->eeprom.i2sID = snd_ice1712_read_i2c(ice, dev, 0x08);
    2156         ice->eeprom.spdif = snd_ice1712_read_i2c(ice, dev, 0x09);
    2157         ice->eeprom.gpiomask = snd_ice1712_read_i2c(ice, dev, 0x0a);
    2158         ice->eeprom.gpiostate = snd_ice1712_read_i2c(ice, dev, 0x0b);
    2159         ice->eeprom.gpiodir = snd_ice1712_read_i2c(ice, dev, 0x0c);
    2160         ice->eeprom.ac97main = (snd_ice1712_read_i2c(ice, dev, 0x0d) << 0) |
    2161                                (snd_ice1712_read_i2c(ice, dev, 0x0e) << 8);
    2162         ice->eeprom.ac97pcm = (snd_ice1712_read_i2c(ice, dev, 0x0f) << 0) |
    2163                               (snd_ice1712_read_i2c(ice, dev, 0x10) << 8);
    2164         ice->eeprom.ac97rec = (snd_ice1712_read_i2c(ice, dev, 0x11) << 0) |
    2165                               (snd_ice1712_read_i2c(ice, dev, 0x12) << 8);
    2166         ice->eeprom.ac97recsrc = snd_ice1712_read_i2c(ice, dev, 0x13) << 0;
    2167         for (idx = 0; idx < 4; idx++) {
    2168                 ice->eeprom.dacID[idx] = snd_ice1712_read_i2c(ice, dev, 0x14 + idx);
    2169                 ice->eeprom.adcID[idx] = snd_ice1712_read_i2c(ice, dev, 0x18 + idx);
    2170         }
    2171         for (idx = 0x1c; idx < ice->eeprom.size && idx < 0x1c + sizeof(ice->eeprom.extra); idx++)
    2172                 ice->eeprom.extra[idx - 0x1c] = snd_ice1712_read_i2c(ice, dev, idx);
     2163                /* return -EIO; */
     2164        }
     2165        for (i = 0; i < ice->eeprom.size; i++)
     2166                ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
     2167
     2168        ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
     2169        ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
     2170        ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
     2171
    21732172        return 0;
    21742173}
     
    21822181        outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
    21832182        udelay(200);
    2184         pci_write_config_byte(ice->pci, 0x60, ice->eeprom.codec);
    2185         pci_write_config_byte(ice->pci, 0x61, ice->eeprom.aclink);
    2186         pci_write_config_byte(ice->pci, 0x62, ice->eeprom.i2sID);
    2187         pci_write_config_byte(ice->pci, 0x63, ice->eeprom.spdif);
     2183        pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
     2184        pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
     2185        pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
     2186        pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
    21882187        if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
    2189                 ice->gpio_write_mask = ice->eeprom.gpiomask;
    2190                 ice->gpio_direction = ice->eeprom.gpiodir;
     2188                ice->gpio.write_mask = ice->eeprom.gpiomask;
     2189                ice->gpio.direction = ice->eeprom.gpiodir;
    21912190                snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
    21922191                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
    21932192                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
    21942193        } else {
    2195                 ice->gpio_write_mask = 0xc0;
    2196                 ice->gpio_direction = 0xff;
     2194                ice->gpio.write_mask = 0xc0;
     2195                ice->gpio.direction = 0xff;
    21972196                snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
    21982197                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
     
    22002199        }
    22012200        snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
    2202         if (!(ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97)) {
     2201        if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
    22032202                outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
    22042203                udelay(100);
     
    22102209        return 0;
    22112210}
    2212 
    22132211
    22142212int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
     
    22512249        if (err < 0)
    22522250                return err;
     2251
    22532252        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
    22542253        if (err < 0)
     
    22572256        if (err < 0)
    22582257                return err;
     2258
    22592259        for (idx = 0; idx < ice->num_total_dacs; idx++) {
    22602260                kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
     
    22662266                        return err;
    22672267        }
     2268
    22682269        for (idx = 0; idx < 2; idx++) {
    22692270                kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice);
     
    22752276                        return err;
    22762277        }
     2278
    22772279        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
    22782280        if (err < 0)
     
    22812283        if (err < 0)
    22822284                return err;
     2285
    22832286        return 0;
    22842287}
     
    22932296        /* --- */
    22942297      __hw_end:
    2295         snd_ice1712_proc_done(ice);
    22962298        if (ice->irq >= 0) {
    22972299                synchronize_irq(ice->irq);
     
    23142316                kfree_nocheck(ice->res_profi_port);
    23152317        }
     2318        if (ice->akm)
     2319                kfree(ice->akm);
    23162320        snd_magic_kfree(ice);
    23172321        return 0;
     
    23532357        spin_lock_init(&ice->reg_lock);
    23542358        init_MUTEX(&ice->gpio_mutex);
     2359        ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
     2360        ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
     2361        ice->gpio.set_data = snd_ice1712_set_gpio_data;
     2362        ice->gpio.get_data = snd_ice1712_get_gpio_data;
     2363
    23552364        ice->spdif.cs8403_bits =
    23562365                ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
     
    23952404                return -EIO;
    23962405        }
     2406       
    23972407        ice->irq = pci->irq;
    23982408
     
    24072417
    24082418        /* unmask used interrupts */
    2409         outb((ice->eeprom.codec & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
    2410              (ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
     2419        outb((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
     2420             (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
    24112421             ICEREG(ice, IRQMASK));
    24122422        outb(0x00, ICEMT(ice, IRQ));
     
    24882498        }
    24892499       
    2490         if (!(ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97))
     2500        if (ice_has_con_ac97(ice))
    24912501                if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
    24922502                        snd_card_free(card);
     
    25112521        }
    25122522
    2513         if (!(ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97))
     2523        if (ice_has_con_ac97(ice))
    25142524                if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
    25152525                        snd_card_free(card);
     
    25262536        }
    25272537
    2528         if (ice->eeprom.codec & ICE1712_CFG_2xMPU401)
     2538                if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401)
    25292539                if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
    25302540                                               ICEREG(ice, MPU2_CTRL), 1,
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/ice1712.h

    r215 r224  
    215215
    216216typedef struct _snd_ice1712 ice1712_t;
    217 typedef struct snd_ak4524 ak4524_t;
     217typedef struct snd_ak4xxx akm4xxx_t;
    218218
    219219typedef struct {
    220220        unsigned int subvendor; /* PCI[2c-2f] */
    221221        unsigned char size;     /* size of EEPROM image in bytes */
    222         unsigned char version;  /* must be 1 */
    223         unsigned char codec;    /* codec configuration PCI[60] */
    224         unsigned char aclink;   /* ACLink configuration PCI[61] */
    225         unsigned char i2sID;    /* PCI[62] */
    226         unsigned char spdif;    /* S/PDIF configuration PCI[63] */
    227         unsigned char gpiomask; /* GPIO initial mask, 0 = write, 1 = don't */
    228         unsigned char gpiostate; /* GPIO initial state */
    229         unsigned char gpiodir;  /* GPIO direction state */
    230         unsigned short ac97main;
    231         unsigned short ac97pcm;
    232         unsigned short ac97rec;
    233         unsigned char ac97recsrc;
    234         unsigned char dacID[4]; /* I2S IDs for DACs */
    235         unsigned char adcID[4]; /* I2S IDs for ADCs */
    236         unsigned char extra[4];
     222        unsigned char version;  /* must be 1 (or 2 for vt1724) */
     223        unsigned char data[32];
     224        unsigned int gpiomask;
     225        unsigned int gpiostate;
     226        unsigned int gpiodir;
    237227} ice1712_eeprom_t;
    238228
    239 struct snd_ak4524 {
    240         int num_adcs;                   /* AK4524 or AK4528 ADCs */
    241         int num_dacs;                   /* AK4524 or AK4528 DACs */
    242         unsigned char images[4][16];
    243         unsigned char ipga_gain[4][2];
    244         /* */
     229enum {
     230        ICE_EEP1_CODEC = 0,     /* 06 */
     231        ICE_EEP1_ACLINK,        /* 07 */
     232        ICE_EEP1_I2SID,         /* 08 */
     233        ICE_EEP1_SPDIF,         /* 09 */
     234        ICE_EEP1_GPIO_MASK,     /* 0a */
     235        ICE_EEP1_GPIO_STATE,    /* 0b */
     236        ICE_EEP1_GPIO_DIR,      /* 0c */
     237        ICE_EEP1_AC97_MAIN_LO,  /* 0d */
     238        ICE_EEP1_AC97_MAIN_HI,  /* 0e */
     239        ICE_EEP1_AC97_PCM_LO,   /* 0f */
     240        ICE_EEP1_AC97_PCM_HI,   /* 10 */
     241        ICE_EEP1_AC97_REC_LO,   /* 11 */
     242        ICE_EEP1_AC97_REC_HI,   /* 12 */
     243        ICE_EEP1_AC97_RECSRC,   /* 13 */
     244        ICE_EEP1_DAC_ID,        /* 14 */
     245        ICE_EEP1_DAC_ID1,
     246        ICE_EEP1_DAC_ID2,
     247        ICE_EEP1_DAC_ID3,
     248        ICE_EEP1_ADC_ID,        /* 18 */
     249        ICE_EEP1_ADC_ID1,
     250        ICE_EEP1_ADC_ID2,
     251        ICE_EEP1_ADC_ID3
     252};
     253       
     254#define ice_has_con_ac97(ice)   (!((ice)->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97))
     255
     256
     257struct 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 */
    245265        enum {
    246                 SND_AK4524, SND_AK4528, SND_AK4529
     266                SND_AK4524, SND_AK4528, SND_AK4529, SND_AK4355, SND_AK4381
    247267        } type;
    248         unsigned int cif: 1;
    249         unsigned char data_mask;
    250         unsigned char clk_mask;
    251         unsigned char cs_mask;
    252         unsigned char cs_addr;
    253         unsigned char cs_none;
    254         unsigned char add_flags;
    255         unsigned char mask_flags;
    256         struct snd_ak4524_ops {
    257                 int (*start)(ice1712_t *, unsigned char *, int);
    258                 void (*stop)(ice1712_t *, unsigned char *);
    259                 void (*set_rate_val)(ice1712_t *, unsigned int);
     268        unsigned int cif: 1;            /* CIF mode */
     269        unsigned char caddr;            /* C0 and C1 bits */
     270        unsigned int data_mask;         /* DATA gpio bit */
     271        unsigned int clk_mask;          /* CLK gpio bit */
     272        unsigned int cs_mask;           /* bit mask for select/deselect address */
     273        unsigned int cs_addr;           /* bits to select address */
     274        unsigned int cs_none;           /* bits to deselect address */
     275        unsigned int add_flags;         /* additional bits at init */
     276        unsigned int mask_flags;        /* total mask bits */
     277        struct snd_akm4xxx_ops {
     278                int (*start)(akm4xxx_t *ak, int chip);
     279                void (*stop)(akm4xxx_t *ak);
     280                void (*set_rate_val)(akm4xxx_t *ak, unsigned int rate);
    260281        } ops;
    261282};
     
    268289        struct snd_ice1712_spdif_ops {
    269290                void (*open)(ice1712_t *, snd_pcm_substream_t *);
    270                 void (*setup)(ice1712_t *, snd_pcm_substream_t *);
     291                void (*setup_rate)(ice1712_t *, int rate);
    271292                void (*close)(ice1712_t *, snd_pcm_substream_t *);
    272293                void (*default_get)(ice1712_t *, snd_ctl_elem_value_t * ucontrol);
     
    293314        unsigned long profi_port;
    294315        struct resource *res_profi_port;
    295 
    296         unsigned int config;    /* system configuration */
    297316
    298317        struct pci_dev *pci;
     
    316335
    317336        spinlock_t reg_lock;
    318         struct semaphore gpio_mutex;
    319337        snd_info_entry_t *proc_entry;
    320338
     
    322340
    323341        unsigned int pro_volumes[20];
    324         int omni: 1;                    /* Delta Omni I/O */
    325         int num_total_dacs;             /* total DACs */
     342        unsigned int omni: 1;           /* Delta Omni I/O */
     343        unsigned int vt1724: 1;
     344        unsigned int num_total_dacs;    /* total DACs */
    326345        unsigned char hoontech_boxbits[4];
    327346        unsigned int hoontech_config;
    328347        unsigned short hoontech_boxconfig[4];
    329 
    330         struct snd_ak4524 ak4524;
     348        unsigned int cur_rate;          /* current rate */
     349
     350        unsigned int akm_codecs;
     351        akm4xxx_t *akm;
    331352        struct snd_ice1712_spdif spdif;
    332353
     
    336357        snd_i2c_device_t *i2cdevs[2];   /* additional i2c devices */
    337358       
    338         unsigned char gpio_direction, gpio_write_mask;
     359        struct ice1712_gpio {
     360                unsigned int direction;         /* current direction bits */
     361                unsigned int write_mask;        /* current mask bits */
     362                unsigned int saved[2];          /* for ewx_i2c */
     363                /* operators */
     364                void (*set_mask)(ice1712_t *ice, unsigned int data);
     365                void (*set_dir)(ice1712_t *ice, unsigned int data);
     366                void (*set_data)(ice1712_t *ice, unsigned int data);
     367                unsigned int (*get_data)(ice1712_t *ice);
     368        } gpio;
     369        struct semaphore gpio_mutex;
    339370};
    340371
     
    342373
    343374
     375/*
     376 * gpio access functions
     377 */
     378static inline void snd_ice1712_gpio_set_dir(ice1712_t *ice, unsigned int bits)
     379{
     380        ice->gpio.set_dir(ice, bits);
     381}
     382
     383static inline void snd_ice1712_gpio_set_mask(ice1712_t *ice, unsigned int bits)
     384{
     385        ice->gpio.set_mask(ice, bits);
     386}
     387
     388static inline void snd_ice1712_gpio_write(ice1712_t *ice, unsigned int val)
     389{
     390        ice->gpio.set_data(ice, val);
     391}
     392
     393static inline unsigned int snd_ice1712_gpio_read(ice1712_t *ice)
     394{
     395        return ice->gpio.get_data(ice);
     396}
     397
     398/*
     399 * save and restore gpio status
     400 * The access to gpio will be protected by mutex, so don't forget to
     401 * restore!
     402 */
     403static inline void snd_ice1712_save_gpio_status(ice1712_t *ice)
     404{
     405        down(&ice->gpio_mutex);
     406        ice->gpio.saved[0] = ice->gpio.direction;
     407        ice->gpio.saved[1] = ice->gpio.write_mask;
     408}
     409
     410static inline void snd_ice1712_restore_gpio_status(ice1712_t *ice)
     411{
     412        ice->gpio.set_dir(ice, ice->gpio.saved[0]);
     413        ice->gpio.set_mask(ice, ice->gpio.saved[1]);
     414        ice->gpio.direction = ice->gpio.saved[0];
     415        ice->gpio.write_mask = ice->gpio.saved[1];
     416        up(&ice->gpio_mutex);
     417}
     418
     419/* for bit controls */
    344420#define ICE1712_GPIO(xiface, xname, xindex, mask, invert, xaccess) \
    345421{ .iface = xiface, .name = xname, .access = xaccess, .info = snd_ice1712_gpio_info, \
     
    351427int snd_ice1712_gpio_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol);
    352428
    353 void snd_ice1712_gpio_write_bits(ice1712_t *ice, int mask, int bits);
    354 void snd_ice1712_save_gpio_status(ice1712_t *ice, unsigned char *tmp);
    355 void snd_ice1712_restore_gpio_status(ice1712_t *ice, unsigned char *tmp);
    356 
     429/*
     430 * set gpio direction, write mask and data
     431 */
     432static inline void snd_ice1712_gpio_write_bits(ice1712_t *ice, unsigned int mask, unsigned int bits)
     433{
     434        ice->gpio.direction |= mask;
     435        snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
     436        snd_ice1712_gpio_set_mask(ice, ~mask);
     437        snd_ice1712_gpio_write(ice, mask & bits);
     438}
    357439
    358440int snd_ice1712_spdif_build_controls(ice1712_t *ice);
    359441
    360 void snd_ice1712_ak4524_write(ice1712_t *ice, int chip, unsigned char addr, unsigned char data);
    361 void snd_ice1712_ak4524_reset(ice1712_t *ice, int state);
    362 void snd_ice1712_ak4524_init(ice1712_t *ice);
    363 int snd_ice1712_ak4524_build_controls(ice1712_t *ice);
     442void snd_ice1712_akm4xxx_write(akm4xxx_t *ice, int chip, unsigned char addr, unsigned char data);
     443void snd_ice1712_akm4xxx_reset(akm4xxx_t *ice, int state);
     444void snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *template, ice1712_t *ice);
     445int snd_ice1712_akm4xxx_build_controls(ice1712_t *ice);
    364446
    365447int snd_ice1712_init_cs8427(ice1712_t *ice, int addr);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ice1712/makefile.os2

    r212 r224  
    1414#===================================================================
    1515FILE1    = ak4524.obj delta.obj ews.obj hoontech.obj ice1712.obj
    16 FILE2    =
     16FILE2    = ice1724.obj revo.obj
    1717FILE3    =
    1818FILE4    =
  • GPL/branches/alsa-resync1/alsa-kernel/pci/korg1212/korg1212.c

    r212 r224  
    2121
    2222#include <sound/driver.h>
    23 #include <asm/io.h>
    2423#include <linux/delay.h>
    2524#include <linux/init.h>
     25#include <linux/interrupt.h>
    2626#include <linux/pci.h>
    2727#include <linux/slab.h>
     28#include <linux/wait.h>
     29
    2830#include <sound/core.h>
    2931#include <sound/info.h>
     
    3436#include <sound/initval.h>
    3537
     38#include <asm/io.h>
     39
    3640// ----------------------------------------------------------------------------
    3741// Debug Stuff
     
    3943#define K1212_DEBUG_LEVEL               0
    4044#define K1212_DEBUG_PRINTK              printk
     45//#define K1212_DEBUG_PRINTK(x...)      printk("<0>" x)
    4146
    4247// ----------------------------------------------------------------------------
     
    175180#define kPlayBufferFrames       1024
    176181
    177 #define K1212_CHANNELS          16
     182#define K1212_ANALOG_CHANNELS   2
     183#define K1212_SPDIF_CHANNELS    2
     184#define K1212_ADAT_CHANNELS     8
     185#define K1212_CHANNELS          (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS)
     186#define K1212_MIN_CHANNELS      1
     187#define K1212_MAX_CHANNELS      K1212_CHANNELS
    178188#define K1212_FRAME_SIZE        (sizeof(KorgAudioFrame))
    179189#define K1212_MAX_SAMPLES       (kPlayBufferFrames*kNumBuffers)
    180 #define K1212_PERIODS           (K1212_BUF_SIZE/K1212_BLOCK_SIZE)
    181 #define K1212_PERIOD_BYTES      (K1212_BLOCK_SIZE)
    182 #define K1212_BLOCK_SIZE        (K1212_FRAME_SIZE*kPlayBufferFrames)
    183 #define K1212_BUF_SIZE          (K1212_BLOCK_SIZE*kNumBuffers)
     190#define K1212_PERIODS           (kNumBuffers)
     191#define K1212_PERIOD_BYTES      (K1212_FRAME_SIZE*kPlayBufferFrames)
     192#define K1212_BUF_SIZE          (K1212_PERIOD_BYTES*kNumBuffers)
     193#define K1212_ANALOG_BUF_SIZE   (K1212_ANALOG_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
     194#define K1212_SPDIF_BUF_SIZE    (K1212_SPDIF_CHANNELS * 3 * kPlayBufferFrames * kNumBuffers)
     195#define K1212_ADAT_BUF_SIZE     (K1212_ADAT_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers)
     196#define K1212_MAX_BUF_SIZE      (K1212_ANALOG_BUF_SIZE + K1212_ADAT_BUF_SIZE)
    184197
    185198#define k1212MinADCSens     0x7f
     
    311324
    312325struct _snd_korg1212 {
     326        snd_card_t *card;
    313327        struct pci_dev *pci;
    314         snd_card_t *card;
    315         snd_pcm_t *pcm16;
     328        snd_pcm_t *pcm;
    316329        int irq;
    317330
     
    359372        u32 * idRegPtr;              // address of the device and vendor ID registers
    360373
    361 
    362374        size_t periodsize;
    363         size_t currentBuffer;
     375        int channels;
     376        int currentBuffer;
    364377
    365378        snd_pcm_substream_t *playback_substream;
    366379        snd_pcm_substream_t *capture_substream;
    367         snd_info_entry_t * proc_entry;
    368380
    369381        CardState cardState;
     
    381393        u16 leftADCInSens;           // ADC left channel input sensitivity
    382394        u16 rightADCInSens;          // ADC right channel input sensitivity
     395
     396        int opencnt;                    // Open/Close count
     397        int setcnt;                     // SetupForPlay count
     398        int playcnt;                    // TriggerPlay count
     399
    383400};
    384401
     
    404421
    405422static struct pci_device_id snd_korg1212_ids[] __devinitdata = {
    406         { 0x10b5, 0x906d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
    407         { 0, }
     423        {
     424                .vendor    = 0x10b5,
     425                .device    = 0x906d,
     426                .subvendor = PCI_ANY_ID,
     427                .subdevice = PCI_ANY_ID,
     428        },
     429        { 0, },
    408430};
    409431
     
    456478                            };
    457479
    458 snd_korg1212rc rc;
    459 
     480static snd_korg1212rc rc;
    460481
    461482MODULE_DEVICE_TABLE(pci, snd_korg1212_ids);
     
    514535#endif /* not used */
    515536
    516 void TickDelay(int time)
    517 {
    518         udelay(time);
    519 }
    520 
    521537#define SetBitInWord(theWord,bitPosition)       (*theWord) |= (0x0001 << bitPosition)
    522538#define SetBitInDWord(theWord,bitPosition)      (*theWord) |= (0x00000001 << bitPosition)
     
    529545        u32 retryCount;
    530546        u16 mailBox3Lo;
    531 
    532         if (korg1212->outDoorbellPtr) {
     547        snd_korg1212rc rc = K1212_CMDRET_Success;
     548
     549        if (!korg1212->outDoorbellPtr) {
     550#if K1212_DEBUG_LEVEL > 1
     551                K1212_DEBUG_PRINTK("K1212_DEBUG: CardUninitialized\n");
     552#endif
     553                return K1212_CMDRET_CardUninitialized;
     554        }
     555
    533556#if K1212_DEBUG_LEVEL > 0
    534557                K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n", doorbellVal, mailBox0Val, stateName[korg1212->cardState]);
    535558#endif
    536559                for (retryCount = 0; retryCount < MAX_COMMAND_RETRIES; retryCount++) {
    537 
    538560                        writel(mailBox3Val, korg1212->mailbox3Ptr);
    539561                        writel(mailBox2Val, korg1212->mailbox2Ptr);
     
    545567                        // the reboot command will not give an acknowledgement.
    546568                        // --------------------------------------------------------------
    547                         switch (doorbellVal) {
    548                                 case K1212_DB_RebootCard:
    549                                 case K1212_DB_BootFromDSPPage4:
    550                                 case K1212_DB_StartDSPDownload:
    551                                         return K1212_CMDRET_Success;
    552                                 default:
     569                if ( doorbellVal == K1212_DB_RebootCard ||
     570                        doorbellVal == K1212_DB_BootFromDSPPage4 ||
     571                        doorbellVal == K1212_DB_StartDSPDownload ) {
     572                        rc = K1212_CMDRET_Success;
    553573                                        break;
    554574                        }
     
    559579                        // low byte is equal to the doorbell value, then it ack'd.
    560580                        // --------------------------------------------------------------
    561                         TickDelay(COMMAND_ACK_DELAY);
     581                udelay(COMMAND_ACK_DELAY);
    562582                        mailBox3Lo = readl(korg1212->mailbox3Ptr);
    563583                        if (mailBox3Lo & COMMAND_ACK_MASK) {
    564584                                if ((mailBox3Lo & DOORBELL_VAL_MASK) == (doorbellVal & DOORBELL_VAL_MASK)) {
    565                                         korg1212->cmdRetryCount += retryCount;
    566                                         return K1212_CMDRET_Success;
    567                                 }
     585#if K1212_DEBUG_LEVEL > 1
     586                                K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- Success\n");
     587#endif
     588                                rc = K1212_CMDRET_Success;
     589                                break;
    568590                        }
    569591                }
    570                 korg1212->cmdRetryCount += retryCount;
    571                 return K1212_CMDRET_NoAckFromCard;
    572         } else {
    573                 return K1212_CMDRET_CardUninitialized;
    574         }
     592        }
     593                                        korg1212->cmdRetryCount += retryCount;
     594
     595        if (retryCount >= MAX_COMMAND_RETRIES) {
     596#if K1212_DEBUG_LEVEL > 1
     597                K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- NoAckFromCard\n");
     598#endif
     599                rc = K1212_CMDRET_NoAckFromCard;
     600        }
     601
     602        return rc;
    575603}
    576604
    577605static void snd_korg1212_WaitForCardStopAck(korg1212_t *korg1212)
    578606{
    579         unsigned long endtime = jiffies + 20 * HZ;
    580 
    581 #if K1212_DEBUG_LEVEL > 0
    582         K1212_DEBUG_PRINTK("K1212_DEBUG: WaitForCardStopAck [%s]\n", stateName[korg1212->cardState]);
     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);
    583611#endif
    584612
     
    587615
    588616        do {
    589                 if (readl(&korg1212->sharedBufferPtr->cardCommand) == 0)
     617                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
    590621                        return;
     622                }
    591623                if (!korg1212->inIRQ)
    592624                        schedule();
    593         } while (jiffies < endtime);
    594 
     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
    595630        writel(0, &korg1212->sharedBufferPtr->cardCommand);
    596631}
     
    598633static void snd_korg1212_TurnOnIdleMonitor(korg1212_t *korg1212)
    599634{
    600         TickDelay(INTERCOMMAND_DELAY);
     635        udelay(INTERCOMMAND_DELAY);
    601636        korg1212->idleMonitorOn = 1;
    602637        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
     
    634669{
    635670#if K1212_DEBUG_LEVEL > 0
    636         K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s]\n", stateName[korg1212->cardState]);
    637 #endif
     671        K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt);
     672#endif
     673        if (korg1212->opencnt++ == 0)
    638674        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    639675        return 1;
     
    643679{
    644680#if K1212_DEBUG_LEVEL > 0
    645         K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s]\n", stateName[korg1212->cardState]);
    646 #endif
     681        K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt);
     682#endif
     683
     684        if (--(korg1212->opencnt))
     685                return 0;
    647686
    648687        if (korg1212->cardState == K1212_STATE_SETUP) {
     
    669708{
    670709#if K1212_DEBUG_LEVEL > 0
    671         K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s]\n", stateName[korg1212->cardState]);
    672 #endif
     710        K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->setcnt);
     711#endif
     712
     713        if (korg1212->setcnt++)
     714                return 0;
    673715
    674716        snd_korg1212_setCardState(korg1212, K1212_STATE_SETUP);
     
    680722#endif
    681723        if (rc != K1212_CMDRET_Success) {
    682                 return 0;
    683         }
    684724        return 1;
    685725}
     726        return 0;
     727}
    686728
    687729static int snd_korg1212_TriggerPlay(korg1212_t * korg1212)
    688730{
    689731#if K1212_DEBUG_LEVEL > 0
    690         K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s]\n", stateName[korg1212->cardState]);
    691 #endif
     732        K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt);
     733#endif
     734
     735        if (korg1212->playcnt++)
     736                return 0;
    692737
    693738        snd_korg1212_setCardState(korg1212, K1212_STATE_PLAYING);
     
    699744
    700745        if (rc != K1212_CMDRET_Success) {
    701                 return 0;
    702         }
    703746        return 1;
    704747}
     748        return 0;
     749}
    705750
    706751static int snd_korg1212_StopPlay(korg1212_t * korg1212)
    707752{
    708753#if K1212_DEBUG_LEVEL > 0
    709         K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s]\n", stateName[korg1212->cardState]);
    710 #endif
     754        K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt);
     755#endif
     756
     757        if (--(korg1212->playcnt))
     758                return 0;
     759
     760        korg1212->setcnt = 0;
    711761
    712762        if (korg1212->cardState != K1212_STATE_ERRORSTOP) {
     
    715765        }
    716766        snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN);
    717         return 1;
     767        return 0;
    718768}
    719769
     
    795845        korg1212->clkRate = rate;
    796846
    797         TickDelay(INTERCOMMAND_DELAY);
     847        udelay(INTERCOMMAND_DELAY);
    798848        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate,
    799849                                          ClockSourceSelector[korg1212->clkSrcRate],
     
    862912        // ----------------------------------------------------------------------------
    863913        writel(0, korg1212->mailbox3Ptr);
    864         TickDelay(LOADSHIFT_DELAY);
     914        udelay(LOADSHIFT_DELAY);
    865915
    866916        // ----------------------------------------------------------------------------
     
    903953                ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS);
    904954                writew(controlValue, korg1212->sensRegPtr);                          // load/shift goes low
    905                 TickDelay(LOADSHIFT_DELAY);
     955                udelay(LOADSHIFT_DELAY);
    906956
    907957                for (bitPosition = 15; bitPosition >= 0; bitPosition--) {       // for all the bits
     
    922972                        ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS);
    923973                        writew(controlValue, korg1212->sensRegPtr);                       // clock goes low
    924                         TickDelay(SENSCLKPULSE_WIDTH);
     974                        udelay(SENSCLKPULSE_WIDTH);
    925975                        SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS);
    926976                        writew(controlValue, korg1212->sensRegPtr);                       // clock goes high
    927                         TickDelay(SENSCLKPULSE_WIDTH);
     977                        udelay(SENSCLKPULSE_WIDTH);
    928978                }
    929979
     
    936986                SetBitInWord(&controlValue, SET_SENS_LOADSHIFT_BITPOS);
    937987                writew(controlValue, korg1212->sensRegPtr);                   // load shift goes high - clk low
    938                 TickDelay(SENSCLKPULSE_WIDTH);
     988                udelay(SENSCLKPULSE_WIDTH);
    939989
    940990                if (clkIs48K)
     
    942992
    943993                writew(controlValue, korg1212->sensRegPtr);                   // set/clear data bit
    944                 TickDelay(ONE_RTC_TICK);
     994                udelay(ONE_RTC_TICK);
    945995                SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS);
    946996                writew(controlValue, korg1212->sensRegPtr);                   // clock goes high
    947                 TickDelay(SENSCLKPULSE_WIDTH);
     997                udelay(SENSCLKPULSE_WIDTH);
    948998                ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS);
    949999                writew(controlValue, korg1212->sensRegPtr);                   // clock goes low
    950                 TickDelay(SENSCLKPULSE_WIDTH);
     1000                udelay(SENSCLKPULSE_WIDTH);
    9511001        }
    9521002
     
    9561006        // ----------------------------------------------------------------------------
    9571007        for (count = 0; count < 10; count++)
    958                 TickDelay(SENSCLKPULSE_WIDTH);
     1008                udelay(SENSCLKPULSE_WIDTH);
    9591009
    9601010        if (monModeSet) {
     
    10041054#endif
    10051055
    1006         TickDelay(INTERCOMMAND_DELAY);
     1056        udelay(INTERCOMMAND_DELAY);
    10071057
    10081058        rc = snd_korg1212_Send1212Command(korg1212,
     
    10221072        // Initialize the routing and volume tables, then update the card's state.
    10231073        // --------------------------------------------------------------------------------
    1024         TickDelay(INTERCOMMAND_DELAY);
     1074        udelay(INTERCOMMAND_DELAY);
    10251075
    10261076        for (channel = 0; channel < kAudioChannels; channel++) {
     
    10321082        snd_korg1212_WriteADCSensitivity(korg1212);
    10331083
    1034         TickDelay(INTERCOMMAND_DELAY);
     1084        udelay(INTERCOMMAND_DELAY);
    10351085        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate,
    10361086                                          ClockSourceSelector[korg1212->clkSrcRate],
     
    10481098        wake_up_interruptible(&korg1212->wait);
    10491099}
    1050 
    10511100
    10521101static void snd_korg1212_interrupt(int irq, void *dev_id, struct pt_regs *regs)
     
    10851134                // ------------------------------------------------------------------------
    10861135                case K1212_ISRCODE_DMAERROR:
    1087 #if K1212_DEBUG_LEVEL > 0
     1136#if K1212_DEBUG_LEVEL > 1
    10881137                        K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);
    10891138#endif
    10901139                        writel(0, &korg1212->sharedBufferPtr->cardCommand);
     1140                        snd_korg1212_setCardState(korg1212, K1212_STATE_ERRORSTOP);
    10911141                        break;
    10921142
     
    10961146                // ------------------------------------------------------------------------
    10971147                case K1212_ISRCODE_CARDSTOPPED:
    1098 #if K1212_DEBUG_LEVEL > 0
     1148#if K1212_DEBUG_LEVEL > 1
    10991149                        K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]);
    11001150#endif
     
    11031153
    11041154                default:
    1105 #if K1212_DEBUG_LEVEL > 1
     1155#if K1212_DEBUG_LEVEL > 3
    11061156                        K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", korg1212->irqcount, doorbellValue,
    11071157                                korg1212->currentBuffer, stateName[korg1212->cardState]);
     
    11631213static snd_pcm_hardware_t snd_korg1212_playback_info =
    11641214{
    1165         .info =               (SNDRV_PCM_INFO_MMAP |
     1215        .info =              (SNDRV_PCM_INFO_MMAP |
    11661216                              SNDRV_PCM_INFO_MMAP_VALID |
    11671217                              SNDRV_PCM_INFO_INTERLEAVED),
     
    11711221        .rate_min =           44100,
    11721222        .rate_max =           48000,
    1173         .channels_min =       K1212_CHANNELS,
    1174         .channels_max =       K1212_CHANNELS,
    1175         .buffer_bytes_max =   K1212_BUF_SIZE,
    1176         .period_bytes_min =   K1212_PERIOD_BYTES,
    1177         .period_bytes_max =   K1212_PERIOD_BYTES,
     1223        .channels_min =       K1212_MIN_CHANNELS,
     1224        .channels_max =       K1212_MAX_CHANNELS,
     1225        .buffer_bytes_max =   K1212_MAX_BUF_SIZE,
     1226        .period_bytes_min =   K1212_MIN_CHANNELS * 2 * kPlayBufferFrames,
     1227        .period_bytes_max =   K1212_MAX_CHANNELS * 2 * kPlayBufferFrames,
    11781228        .periods_min =        K1212_PERIODS,
    11791229        .periods_max =        K1212_PERIODS,
     
    11831233static snd_pcm_hardware_t snd_korg1212_capture_info =
    11841234{
    1185         .info =               (SNDRV_PCM_INFO_MMAP |
     1235        .info =              (SNDRV_PCM_INFO_MMAP |
    11861236                              SNDRV_PCM_INFO_MMAP_VALID |
    11871237                              SNDRV_PCM_INFO_INTERLEAVED),
     
    11911241        .rate_min =           44100,
    11921242        .rate_max =           48000,
    1193         .channels_min =       K1212_CHANNELS,
    1194         .channels_max =       K1212_CHANNELS,
    1195         .buffer_bytes_max =   K1212_BUF_SIZE,
    1196         .period_bytes_min =   K1212_PERIOD_BYTES,
    1197         .period_bytes_max =   K1212_PERIOD_BYTES,
     1243        .channels_min =       K1212_MIN_CHANNELS,
     1244        .channels_max =       K1212_MAX_CHANNELS,
     1245        .buffer_bytes_max =   K1212_MAX_BUF_SIZE,
     1246        .period_bytes_min =   K1212_MIN_CHANNELS * 2 * kPlayBufferFrames,
     1247        .period_bytes_max =   K1212_MAX_CHANNELS * 2 * kPlayBufferFrames,
    11981248        .periods_min =        K1212_PERIODS,
    11991249        .periods_max =        K1212_PERIODS,
     
    12011251};
    12021252
     1253static int snd_korg1212_silence(korg1212_t *korg1212, int pos, int count, int offset, int size)
     1254{
     1255        KorgAudioFrame * dst =  korg1212->playDataBufsPtr[0].bufferData + pos;
     1256        int i;
     1257
     1258#if K1212_DEBUG_LEVEL > 2
     1259        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count);
     1260#endif
     1261        snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
     1262
     1263        for (i=0; i < count; i++) {
     1264#if K1212_DEBUG_LEVEL > 0
     1265                if ( (void *) dst < (void *) korg1212->playDataBufsPtr ||
     1266                     (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) {
     1267                        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", dst, i);
     1268                        return -EFAULT;
     1269                }
     1270#endif
     1271                memset((void*) dst + offset, 0, size);
     1272                dst++;
     1273        }
     1274
     1275        return 0;
     1276}
     1277
     1278static int snd_korg1212_copy_to(korg1212_t *korg1212, void *dst, int pos, int count, int offset, int size)
     1279{
     1280        KorgAudioFrame * src =  korg1212->recordDataBufsPtr[0].bufferData + pos;
     1281        int i, rc;
     1282
     1283#if K1212_DEBUG_LEVEL > 2
     1284        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to pos=%d offset=%d size=%d\n", pos, offset, size);
     1285#endif
     1286        snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
     1287
     1288        for (i=0; i < count; i++) {
     1289#if K1212_DEBUG_LEVEL > 0
     1290                if ( (void *) src < (void *) korg1212->recordDataBufsPtr ||
     1291                     (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) {
     1292                        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i);
     1293                        return -EFAULT;
     1294                }
     1295#endif
     1296                rc = copy_to_user((void*) dst + offset, src, size);
     1297                if (rc) {
     1298#if K1212_DEBUG_LEVEL > 0
     1299                        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_to USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i);
     1300#endif
     1301                        return -EFAULT;
     1302                }
     1303                src++;
     1304                dst += size;
     1305        }
     1306
     1307        return 0;
     1308}
     1309
     1310static int snd_korg1212_copy_from(korg1212_t *korg1212, void *src, int pos, int count, int offset, int size)
     1311{
     1312        KorgAudioFrame * dst =  korg1212->playDataBufsPtr[0].bufferData + pos;
     1313        int i, rc;
     1314
     1315#if K1212_DEBUG_LEVEL > 2
     1316        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count);
     1317#endif
     1318
     1319        snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
     1320
     1321        for (i=0; i < count; i++) {
     1322#if K1212_DEBUG_LEVEL > 0
     1323                if ( (void *) dst < (void *) korg1212->playDataBufsPtr ||
     1324                     (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) {
     1325                        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i);
     1326                        return -EFAULT;
     1327                }
     1328#endif
     1329                rc = copy_from_user((void*) dst + offset, src, size);
     1330                if (rc) {
     1331#if K1212_DEBUG_LEVEL > 0
     1332                        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_copy_from USER EFAULT src=%p dst=%p iter=%d\n", src, dst, i);
     1333#endif
     1334                        return -EFAULT;
     1335                }
     1336                dst++;
     1337                src += size;
     1338        }
     1339
     1340        return 0;
     1341}
     1342
    12031343static void snd_korg1212_free_pcm(snd_pcm_t *pcm)
    12041344{
     
    12091349#endif
    12101350
    1211         korg1212->pcm16 = NULL;
    1212 }
    1213 
    1214 static unsigned int period_bytes[] = { K1212_PERIOD_BYTES };
    1215 
    1216 #define PERIOD_BYTES sizeof(period_bytes) / sizeof(period_bytes[0])
    1217 
    1218 static snd_pcm_hw_constraint_list_t hw_constraints_period_bytes = {
    1219         .count = PERIOD_BYTES,
    1220         .list = period_bytes,
    1221         .mask = 0
    1222 };
     1351        korg1212->pcm = NULL;
     1352}
    12231353
    12241354static int snd_korg1212_playback_open(snd_pcm_substream_t *substream)
     
    12321362#endif
    12331363
     1364        snd_pcm_set_sync(substream);    // ???
     1365
    12341366        spin_lock_irqsave(&korg1212->lock, flags);
    12351367
    1236         snd_korg1212_OpenCard(korg1212);
    1237 
    1238         snd_pcm_set_sync(substream);    // ???
    1239 
    1240         runtime->hw = snd_korg1212_playback_info;
     1368        snd_korg1212_OpenCard(korg1212);
     1369
    12411370        runtime->dma_area = (char *) korg1212->playDataBufsPtr;
    12421371        runtime->dma_bytes = K1212_BUF_SIZE;
     
    12441373        korg1212->playback_substream = substream;
    12451374        korg1212->periodsize = K1212_PERIODS;
     1375        korg1212->channels = K1212_CHANNELS;
    12461376
    12471377        spin_unlock_irqrestore(&korg1212->lock, flags);
    12481378
    1249         snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, K1212_BUF_SIZE, K1212_BUF_SIZE);
    1250         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     1379        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames);
    12511380        return 0;
    12521381}
     1382
    12531383
    12541384static int snd_korg1212_capture_open(snd_pcm_substream_t *substream)
     
    12621392#endif
    12631393
     1394        snd_pcm_set_sync(substream);    // ???
     1395
    12641396        spin_lock_irqsave(&korg1212->lock, flags);
    12651397
    1266         snd_korg1212_OpenCard(korg1212);
    1267 
    1268         snd_pcm_set_sync(substream);    // ???
     1398        snd_korg1212_OpenCard(korg1212);
    12691399
    12701400        runtime->hw = snd_korg1212_capture_info;
     
    12741404        korg1212->capture_substream = substream;
    12751405        korg1212->periodsize = K1212_PERIODS;
     1406        korg1212->channels = K1212_CHANNELS;
    12761407
    12771408        spin_unlock_irqrestore(&korg1212->lock, flags);
    12781409
    1279         snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, K1212_BUF_SIZE, K1212_BUF_SIZE);
    1280         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     1410        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames, kPlayBufferFrames);
    12811411        return 0;
    12821412}
     
    12911421#endif
    12921422
     1423        snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2);
     1424
    12931425        spin_lock_irqsave(&korg1212->lock, flags);
    12941426
     
    13221454}
    13231455
    1324 static int snd_korg1212_channel_info(snd_pcm_substream_t *substream,
    1325                                     snd_pcm_channel_info_t *info)
    1326 {
    1327         int chn = info->channel;
    1328 
    1329         // snd_assert(info->channel < kAudioChannels + 1, return -EINVAL);
    1330 
    1331         info->offset = 0;
    1332         // if (chn < k16BitChannels) {
    1333                 info->first = chn * 16;
    1334         // } else {
    1335         //         info->first = k16BitChannels * 16 + (chn - k16BitChannels - 1) * 32;
    1336         // }
    1337         info->step = sizeof(KorgAudioFrame) * 8;
    1338 
    1339 #if K1212_DEBUG_LEVEL > 0
    1340                 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_channel_info %d:, offset=%ld, first=%d, step=%d\n", chn, info->offset, info->first, info->step);
    1341 #endif
    1342 
    1343         return 0;
    1344 }
    1345 
    13461456static int snd_korg1212_ioctl(snd_pcm_substream_t *substream,
    13471457                             unsigned int cmd, void *arg)
     
    13501460                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd);
    13511461#endif
     1462
    13521463        if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) {
    13531464                snd_pcm_channel_info_t *info = arg;
    1354                 return snd_korg1212_channel_info(substream, info);
     1465                info->offset = 0;
     1466                info->first = info->channel * 16;
     1467                info->step = 256;
     1468#if K1212_DEBUG_LEVEL > 0
     1469                K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step);
     1470#endif
     1471                return 0;
    13551472        }
    13561473
     
    13741491                return err;
    13751492        }
    1376 
     1493/*
    13771494        if (params_format(params) != SNDRV_PCM_FORMAT_S16_LE) {
    13781495                spin_unlock_irqrestore(&korg1212->lock, flags);
    13791496                return -EINVAL;
    13801497        }
    1381 
    1382         korg1212->periodsize = K1212_BLOCK_SIZE;
     1498*/
     1499        korg1212->channels = params_channels(params);
     1500        korg1212->periodsize = K1212_PERIOD_BYTES;
    13831501
    13841502        spin_unlock_irqrestore(&korg1212->lock, flags);
     
    13911509        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    13921510        unsigned long flags;
     1511        int rc;
    13931512
    13941513#if K1212_DEBUG_LEVEL > 0
     
    13981517        spin_lock_irqsave(&korg1212->lock, flags);
    13991518
    1400         snd_korg1212_SetupForPlay(korg1212);
    1401 
    1402         korg1212->currentBuffer = -1;
     1519        rc = snd_korg1212_SetupForPlay(korg1212);
     1520        korg1212->currentBuffer = 0;
    14031521
    14041522        spin_unlock_irqrestore(&korg1212->lock, flags);
    1405         return 0;
     1523
     1524        return rc ? -EINVAL : 0;
    14061525}
    14071526
     
    14101529{
    14111530        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
     1531        int rc;
    14121532
    14131533#if K1212_DEBUG_LEVEL > 0
     
    14171537        switch (cmd) {
    14181538                case SNDRV_PCM_TRIGGER_START:
    1419                         korg1212->running = 1;
    1420                         snd_korg1212_TriggerPlay(korg1212);
     1539/*
     1540                        if (korg1212->running) {
     1541#if K1212_DEBUG_LEVEL > 1
     1542                                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already running?\n");
     1543#endif
    14211544                        break;
     1545                        }
     1546*/
     1547                        korg1212->running++;
     1548                        rc = snd_korg1212_TriggerPlay(korg1212);
     1549                        break;
    14221550
    14231551                case SNDRV_PCM_TRIGGER_STOP:
    1424                         korg1212->running = 0;
    1425                         snd_korg1212_StopPlay(korg1212);
     1552/*
     1553                        if (!korg1212->running) {
     1554#if K1212_DEBUG_LEVEL > 1
     1555                                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n");
     1556#endif
     1557                                break;
     1558                        }
     1559*/
     1560                        korg1212->running--;
     1561                        rc = snd_korg1212_StopPlay(korg1212);
    14261562                        break;
    14271563
    14281564                default:
    1429                         return -EINVAL;
    1430         }
    1431         return 0;
    1432 }
    1433 
    1434 static snd_pcm_uframes_t snd_korg1212_pointer(snd_pcm_substream_t *substream)
     1565                        rc = 1;
     1566                        break;
     1567        }
     1568        return rc ? -EINVAL : 0;
     1569}
     1570
     1571static snd_pcm_uframes_t snd_korg1212_playback_pointer(snd_pcm_substream_t *substream)
    14351572{
    14361573        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    14371574        snd_pcm_uframes_t pos;
    14381575
    1439         if (korg1212->currentBuffer < 0)
    1440                 return 0;
    1441 
    14421576        pos = korg1212->currentBuffer * kPlayBufferFrames;
    14431577
    1444 #if K1212_DEBUG_LEVEL > 1
    1445                 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_pointer [%s] %ld\n", stateName[korg1212->cardState], pos);
     1578#if K1212_DEBUG_LEVEL > 2
     1579        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n",
     1580                        stateName[korg1212->cardState], pos);
     1581#endif
     1582
     1583        return pos;
     1584}
     1585
     1586static snd_pcm_uframes_t snd_korg1212_capture_pointer(snd_pcm_substream_t *substream)
     1587{
     1588        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
     1589        snd_pcm_uframes_t pos;
     1590
     1591        pos = korg1212->currentBuffer * kPlayBufferFrames;
     1592
     1593#if K1212_DEBUG_LEVEL > 2
     1594        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n",
     1595                        stateName[korg1212->cardState], pos);
    14461596#endif
    14471597
     
    14561606{
    14571607        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    1458         KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos;
    1459 
    1460 #if K1212_DEBUG_LEVEL > 0
     1608
     1609#if K1212_DEBUG_LEVEL > 2
    14611610                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);
    14621611#endif
    14631612 
    1464         snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
    1465 
    1466         return copy_from_user(dst, src, count * K1212_FRAME_SIZE) ? -EFAULT : 0;
     1613        return snd_korg1212_copy_from(korg1212, src, pos, count, 0, korg1212->channels * 2);
     1614
     1615}
     1616
     1617static int snd_korg1212_playback_silence(snd_pcm_substream_t *substream,
     1618                           int channel, /* not used (interleaved data) */
     1619                           snd_pcm_uframes_t pos,
     1620                           snd_pcm_uframes_t count)
     1621{
     1622        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
     1623
     1624#if K1212_DEBUG_LEVEL > 0
     1625                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]);
     1626#endif
     1627
     1628        return snd_korg1212_silence(korg1212, pos, count, 0, korg1212->channels * 2);
    14671629}
    14681630
     
    14741636{
    14751637        korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    1476         KorgAudioFrame * src = korg1212->recordDataBufsPtr[0].bufferData + pos;
    1477 
    1478 #if K1212_DEBUG_LEVEL > 0
     1638
     1639#if K1212_DEBUG_LEVEL > 2
    14791640                K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_copy [%s] %ld %ld\n", stateName[korg1212->cardState], pos, count);
    14801641#endif
    14811642
    1482         snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
    1483 
    1484         return copy_to_user(dst, src, count * K1212_FRAME_SIZE) ? -EFAULT : 0;
    1485 }
    1486 
    1487 static int snd_korg1212_playback_silence(snd_pcm_substream_t *substream,
    1488                            int channel, /* not used (interleaved data) */
    1489                            snd_pcm_uframes_t pos,
    1490                            snd_pcm_uframes_t count)
    1491 {
    1492         korg1212_t *korg1212 = _snd_pcm_substream_chip(substream);
    1493         KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos;
    1494 
    1495 #if K1212_DEBUG_LEVEL > 0
    1496                 K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_silence [%s]\n", stateName[korg1212->cardState]);
    1497 #endif
    1498 
    1499         snd_assert(pos + count <= K1212_MAX_SAMPLES, return -EINVAL);
    1500 
    1501         memset(dst, 0, count * K1212_FRAME_SIZE);
    1502 
    1503         return 0;
     1643        return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);
    15041644}
    15051645
     
    15111651        .prepare =      snd_korg1212_prepare,
    15121652        .trigger =      snd_korg1212_trigger,
    1513         .pointer =      snd_korg1212_pointer,
     1653        .pointer =      snd_korg1212_playback_pointer,
    15141654        .copy =         snd_korg1212_playback_copy,
    15151655        .silence =      snd_korg1212_playback_silence,
     
    15231663        .prepare =      snd_korg1212_prepare,
    15241664        .trigger =      snd_korg1212_trigger,
    1525         .pointer =      snd_korg1212_pointer,
     1665        .pointer =      snd_korg1212_capture_pointer,
    15261666        .copy =         snd_korg1212_capture_copy,
    15271667};
     
    15481688        u->value.integer.value[0] = korg1212->volumePhase[i];
    15491689
    1550         if (i >= 8) 
     1690        if (i >= 8)
    15511691                u->value.integer.value[1] = korg1212->volumePhase[i+1];
    15521692
     
    16961836        i = kcontrol->private_value;
    16971837
    1698         if (u->value.enumerated.item[0] != korg1212->sharedBufferPtr->volumeData[i]) {
     1838        if (u->value.enumerated.item[0] != (unsigned) korg1212->sharedBufferPtr->volumeData[i]) {
    16991839                korg1212->sharedBufferPtr->routeData[i] = u->value.enumerated.item[0];
    17001840                change = 1;
     
    17021842
    17031843        if (i >= 8) {
    1704                 if (u->value.enumerated.item[1] != korg1212->sharedBufferPtr->volumeData[i+1]) {
     1844                if (u->value.enumerated.item[1] != (unsigned) korg1212->sharedBufferPtr->volumeData[i+1]) {
    17051845                        korg1212->sharedBufferPtr->routeData[i+1] = u->value.enumerated.item[1];
    17061846                        change = 1;
     
    17131853}
    17141854
    1715 static int snd_korg1212_control_analog_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1855static int snd_korg1212_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
    17161856{
    17171857        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     
    17221862}
    17231863
    1724 static int snd_korg1212_control_analog_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
     1864static int snd_korg1212_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
    17251865{
    17261866        korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
     
    17371877}
    17381878
    1739 static int snd_korg1212_control_analog_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
     1879static int snd_korg1212_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
    17401880{
    17411881        korg1212_t *korg1212 = _snd_kcontrol_chip(kcontrol);
     
    18481988                .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
    18491989                .name =         "ADC Attenuation",
    1850                 .info =         snd_korg1212_control_analog_info,
    1851                 .get =          snd_korg1212_control_analog_get,
    1852                 .put =          snd_korg1212_control_analog_put,
     1990                .info =         snd_korg1212_control_info,
     1991                .get =          snd_korg1212_control_get,
     1992                .put =          snd_korg1212_control_put,
    18531993        }
    18541994};
     
    18682008        snd_iprintf(buffer, " (index #%d)\n", korg1212->card->number + 1);
    18692009        snd_iprintf(buffer, "\nGeneral settings\n");
    1870         snd_iprintf(buffer, "    period size: %d bytes\n", K1212_BLOCK_SIZE);
     2010        snd_iprintf(buffer, "    period size: %d bytes\n", K1212_PERIOD_BYTES);
    18712011        snd_iprintf(buffer, "     clock mode: %s\n", clockSourceName[korg1212->clkSrcRate] );
    18722012        snd_iprintf(buffer, "  left ADC Sens: %d\n", korg1212->leftADCInSens );
     
    18862026}
    18872027
    1888 static void __init snd_korg1212_proc_init(korg1212_t *korg1212)
     2028static void __devinit snd_korg1212_proc_init(korg1212_t *korg1212)
    18892029{
    18902030        snd_info_entry_t *entry;
    18912031
    1892         if ((entry = snd_info_create_card_entry(korg1212->card, "korg1212", korg1212->card->proc_root)) != NULL) {
    1893                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    1894                 entry->private_data = korg1212;
    1895                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    1896                 entry->c.text.read_size = 256;
    1897                 entry->c.text.read = snd_korg1212_proc_read;
    1898                 if (snd_info_register(entry) < 0) {
    1899                         snd_info_free_entry(entry);
    1900                         entry = NULL;
    1901                 }
    1902         }
    1903         korg1212->proc_entry = entry;
    1904 }
    1905 
    1906 static void snd_korg1212_proc_done(korg1212_t * korg1212)
    1907 {
    1908         if (korg1212->proc_entry) {
    1909                 snd_info_unregister(korg1212->proc_entry);
    1910                 korg1212->proc_entry = NULL;
    1911         }
    1912 }
    1913 
    1914 static int __init snd_korg1212_create(korg1212_t *korg1212)
    1915 {
    1916         struct pci_dev *pci = korg1212->pci;
     2032        if (! snd_card_proc_new(korg1212->card, "korg1212", &entry))
     2033                snd_info_set_text_ops(entry, korg1212, snd_korg1212_proc_read);
     2034}
     2035
     2036static int
     2037snd_korg1212_free(korg1212_t *korg1212)
     2038{
     2039        snd_korg1212_TurnOffIdleMonitor(korg1212);
     2040
     2041        if (korg1212->irq >= 0) {
     2042                synchronize_irq(korg1212->irq);               
     2043                snd_korg1212_DisableCardInterrupts(korg1212);
     2044                free_irq(korg1212->irq, (void *)korg1212);
     2045                korg1212->irq = -1;
     2046        }
     2047       
     2048        if (korg1212->iobase != 0) {
     2049                iounmap((void *)korg1212->iobase);
     2050                korg1212->iobase = 0;
     2051        }
     2052       
     2053        if (korg1212->res_iomem != NULL) {
     2054                release_resource(korg1212->res_iomem);
     2055                kfree_nocheck(korg1212->res_iomem);
     2056                korg1212->res_iomem = NULL;
     2057        }
     2058       
     2059        if (korg1212->res_ioport != NULL) {
     2060                release_resource(korg1212->res_ioport);
     2061                kfree_nocheck(korg1212->res_ioport);
     2062                korg1212->res_ioport = NULL;
     2063        }
     2064       
     2065        if (korg1212->res_iomem2 != NULL) {
     2066                release_resource(korg1212->res_iomem2);
     2067                kfree_nocheck(korg1212->res_iomem2);
     2068                korg1212->res_iomem2 = NULL;
     2069        }
     2070
     2071        // ----------------------------------------------------
     2072        // free up memory resources used for the DSP download.
     2073        // ----------------------------------------------------
     2074        if (korg1212->dspMemPtr) {
     2075                snd_free_pci_pages(korg1212->pci, korg1212->dspCodeSize,
     2076                                   korg1212->dspMemPtr, (dma_addr_t)korg1212->dspMemPhy);
     2077                korg1212->dspMemPhy = 0;
     2078                korg1212->dspMemPtr = 0;
     2079                korg1212->dspCodeSize = 0;
     2080        }
     2081
     2082#ifndef K1212_LARGEALLOC
     2083
     2084        // ------------------------------------------------------
     2085        // free up memory resources used for the Play/Rec Buffers
     2086        // ------------------------------------------------------
     2087        if (korg1212->playDataBufsPtr) {
     2088                snd_free_pci_pages(korg1212->pci, korg1212->DataBufsSize,
     2089                                   korg1212->playDataBufsPtr, (dma_addr_t)korg1212->PlayDataPhy);
     2090                korg1212->PlayDataPhy = 0;
     2091                korg1212->playDataBufsPtr = NULL;
     2092        }
     2093
     2094        if (korg1212->recordDataBufsPtr) {
     2095                snd_free_pci_pages(korg1212->pci, korg1212->DataBufsSize,
     2096                                   korg1212->recordDataBufsPtr, (dma_addr_t)korg1212->RecDataPhy);
     2097                korg1212->RecDataPhy = 0;
     2098                korg1212->recordDataBufsPtr = NULL;
     2099        }
     2100
     2101#endif
     2102
     2103        // ----------------------------------------------------
     2104        // free up memory resources used for the Shared Buffers
     2105        // ----------------------------------------------------
     2106        if (korg1212->sharedBufferPtr) {
     2107                snd_free_pci_pages(korg1212->pci, (u32) sizeof(KorgSharedBuffer),
     2108                                   korg1212->sharedBufferPtr, (dma_addr_t)korg1212->sharedBufferPhy);
     2109                korg1212->sharedBufferPhy = 0;
     2110                korg1212->sharedBufferPtr = NULL;
     2111        }
     2112       
     2113        snd_magic_kfree(korg1212);
     2114        return 0;
     2115}
     2116
     2117static int snd_korg1212_dev_free(snd_device_t *device)
     2118{
     2119        korg1212_t *korg1212 = snd_magic_cast(korg1212_t, device->device_data, return -ENXIO);
     2120#if K1212_DEBUG_LEVEL > 0
     2121        K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n");
     2122#endif
     2123        return snd_korg1212_free(korg1212);
     2124}
     2125
     2126static int __devinit snd_korg1212_create(snd_card_t * card, struct pci_dev *pci,
     2127                                         korg1212_t ** rchip)
     2128
     2129{
    19172130        int err;
    1918         int i;
     2131        unsigned int i;
    19192132        unsigned ioport_size, iomem_size, iomem2_size;
    19202133        dma_addr_t phys_addr;
     2134        korg1212_t * korg1212;
     2135
     2136        static snd_device_ops_t ops = {
     2137                .dev_free = snd_korg1212_dev_free,
     2138        };
     2139
     2140        * rchip = NULL;
     2141        if ((err = pci_enable_device(pci)) < 0)
     2142                return err;
     2143
     2144        korg1212 = snd_magic_kcalloc(korg1212_t, 0, GFP_KERNEL);
     2145        if (korg1212 == NULL)
     2146                return -ENOMEM;
     2147
     2148        korg1212->card = card;
     2149        korg1212->pci = pci;
     2150
     2151        init_waitqueue_head(&korg1212->wait);
     2152        spin_lock_init(&korg1212->lock);
    19212153
    19222154        korg1212->irq = -1;
     
    19252157        korg1212->inIRQ = 0;
    19262158        korg1212->running = 0;
     2159        korg1212->opencnt = 0;
     2160        korg1212->playcnt = 0;
     2161        korg1212->setcnt = 0;
    19272162        snd_korg1212_setCardState(korg1212, K1212_STATE_UNINITIALIZED);
    19282163        korg1212->idleMonitorOn = 0;
     
    19332168        for (i=0; i<kAudioChannels; i++)
    19342169                korg1212->volumePhase[i] = 0;
    1935 
    1936         if ((err = pci_enable_device(pci)) < 0)
    1937                 return err;
    19382170
    19392171        korg1212->iomem = pci_resource_start(korg1212->pci, 0);
     
    19592191        korg1212->res_iomem = request_mem_region(korg1212->iomem, iomem_size, "korg1212");
    19602192        if (korg1212->res_iomem == NULL) {
    1961                 snd_printk("unable to grab region 0x%lx-0x%lx\n",
     2193                snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
    19622194                           korg1212->iomem, korg1212->iomem + iomem_size - 1);
    19632195                return -EBUSY;
     
    19662198        korg1212->res_ioport = request_region(korg1212->ioport, ioport_size, "korg1212");
    19672199        if (korg1212->res_ioport == NULL) {
    1968                 snd_printk("unable to grab region 0x%lx-0x%lx\n",
     2200                snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
    19692201                           korg1212->ioport, korg1212->ioport + ioport_size - 1);
    19702202                return -EBUSY;
     
    19732205        korg1212->res_iomem2 = request_mem_region(korg1212->iomem2, iomem2_size, "korg1212");
    19742206        if (korg1212->res_iomem2 == NULL) {
    1975                 snd_printk("unable to grab region 0x%lx-0x%lx\n",
     2207                snd_printk(KERN_ERR "unable to grab region 0x%lx-0x%lx\n",
    19762208                           korg1212->iomem2, korg1212->iomem2 + iomem2_size - 1);
    19772209                return -EBUSY;
     
    19792211
    19802212        if ((korg1212->iobase = (unsigned long) ioremap(korg1212->iomem, iomem_size)) == 0) {
    1981                 snd_printk("unable to remap memory region 0x%lx-0x%lx\n", korg1212->iobase,
     2213                snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", korg1212->iobase,
    19822214                           korg1212->iobase + iomem_size - 1);
    19832215                return -EBUSY;
     
    19892221
    19902222        if (err) {
    1991                 snd_printk("unable to grab IRQ %d\n", pci->irq);
     2223                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
    19922224                return -EBUSY;
    19932225        }
     
    19952227        korg1212->irq = pci->irq;
    19962228
    1997         init_waitqueue_head(&korg1212->wait);
    1998         spin_lock_init(&korg1212->lock);
    19992229        pci_set_master(korg1212->pci);
    20002230
     
    20402270
    20412271        if (korg1212->sharedBufferPtr == NULL) {
    2042                 snd_printk("can not allocate shared buffer memory (%d bytes)\n", sizeof(KorgSharedBuffer));
     2272                snd_printk(KERN_ERR "can not allocate shared buffer memory (%d bytes)\n", sizeof(KorgSharedBuffer));
    20432273                return -ENOMEM;
    20442274        }
     
    20562286
    20572287        if (korg1212->playDataBufsPtr == NULL) {
    2058                 snd_printk("can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
     2288                snd_printk(KERN_ERR "can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
    20592289                return -ENOMEM;
    20602290        }
     
    20692299
    20702300        if (korg1212->recordDataBufsPtr == NULL) {
    2071                 snd_printk("can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
     2301                snd_printk(KERN_ERR "can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
    20722302                return -ENOMEM;
    20732303        }
     
    20972327
    20982328        if (korg1212->dspMemPtr == NULL) {
    2099                 snd_printk("can not allocate dsp code memory (%d bytes)\n", korg1212->dspCodeSize);
     2329                snd_printk(KERN_ERR "can not allocate dsp code memory (%d bytes)\n", korg1212->dspCodeSize);
    21002330                return -ENOMEM;
    21012331        }
     
    21172347        mdelay(CARD_BOOT_DELAY_IN_MS);
    21182348
    2119         if (snd_korg1212_downloadDSPCode(korg1212))
     2349        if (snd_korg1212_downloadDSPCode(korg1212)) 
    21202350                return -EBUSY;
    21212351
     
    21332363               korg1212->AdatTimeCodePhy, LowerWordSwap(korg1212->AdatTimeCodePhy));
    21342364
    2135         if ((err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm16)) < 0)
     2365        if ((err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm)) < 0)
    21362366                return err;
    21372367
    2138         korg1212->pcm16->private_data = korg1212;
    2139         korg1212->pcm16->private_free = snd_korg1212_free_pcm;
    2140         strcpy(korg1212->pcm16->name, "korg1212");
    2141 
    2142         snd_pcm_set_ops(korg1212->pcm16, SNDRV_PCM_STREAM_PLAYBACK, &snd_korg1212_playback_ops);
    2143         snd_pcm_set_ops(korg1212->pcm16, SNDRV_PCM_STREAM_CAPTURE, &snd_korg1212_capture_ops);
    2144 
    2145         korg1212->pcm16->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
     2368        korg1212->pcm->private_data = korg1212;
     2369        korg1212->pcm->private_free = snd_korg1212_free_pcm;
     2370        strcpy(korg1212->pcm->name, "korg1212");
     2371
     2372        snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_korg1212_playback_ops);
     2373       
     2374        snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_korg1212_capture_ops);
     2375
     2376        korg1212->pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
     2377
     2378        //snd_pcm_lib_preallocate_pages_for_all(korg1212->pcm,
     2379        //                      K1212_MAX_BUF_SIZE, K1212_MAX_BUF_SIZE, GFP_KERNEL);
    21462380
    21472381        for (i = 0; i < K1212_CONTROL_ELEMENTS; i++) {
     
    21532387        snd_korg1212_proc_init(korg1212);
    21542388
     2389        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops)) < 0) {
     2390                snd_korg1212_free(korg1212);
     2391                return err;
     2392        }
     2393       
     2394        * rchip = korg1212;
    21552395        return 0;
    21562396
    2157 }
    2158 
    2159 static void
    2160 snd_korg1212_free(void *private_data)
    2161 {
    2162         korg1212_t *korg1212 = (korg1212_t *)private_data;
    2163 
    2164         if (korg1212 == NULL) {
    2165                 return;
    2166         }
    2167 
    2168         snd_korg1212_proc_done(korg1212);
    2169 
    2170         snd_korg1212_TurnOffIdleMonitor(korg1212);
    2171 
    2172         snd_korg1212_DisableCardInterrupts(korg1212);
    2173 
    2174         if (korg1212->irq >= 0) {
    2175                 free_irq(korg1212->irq, (void *)korg1212);
    2176                 korg1212->irq = -1;
    2177         }
    2178         if (korg1212->iobase != 0) {
    2179                 iounmap((void *)korg1212->iobase);
    2180                 korg1212->iobase = 0;
    2181         }
    2182         if (korg1212->res_iomem != NULL) {
    2183                 release_resource(korg1212->res_iomem);
    2184                 kfree_nocheck(korg1212->res_iomem);
    2185                 korg1212->res_iomem = NULL;
    2186         }
    2187         if (korg1212->res_ioport != NULL) {
    2188                 release_resource(korg1212->res_ioport);
    2189                 kfree_nocheck(korg1212->res_ioport);
    2190                 korg1212->res_ioport = NULL;
    2191         }
    2192         if (korg1212->res_iomem2 != NULL) {
    2193                 release_resource(korg1212->res_iomem2);
    2194                 kfree_nocheck(korg1212->res_iomem2);
    2195                 korg1212->res_iomem2 = NULL;
    2196         }
    2197 
    2198         // ----------------------------------------------------
    2199         // free up memory resources used for the DSP download.
    2200         // ----------------------------------------------------
    2201         if (korg1212->dspMemPtr) {
    2202                 snd_free_pci_pages(korg1212->pci, korg1212->dspCodeSize,
    2203                                    korg1212->dspMemPtr, (dma_addr_t)korg1212->dspMemPhy);
    2204                 korg1212->dspMemPhy = 0;
    2205                 korg1212->dspMemPtr = 0;
    2206                 korg1212->dspCodeSize = 0;
    2207         }
    2208 
    2209 #ifndef K1212_LARGEALLOC
    2210 
    2211         // ------------------------------------------------------
    2212         // free up memory resources used for the Play/Rec Buffers
    2213         // ------------------------------------------------------
    2214         if (korg1212->playDataBufsPtr) {
    2215                 snd_free_pci_pages(korg1212->pci, korg1212->DataBufsSize,
    2216                                    korg1212->playDataBufsPtr, (dma_addr_t)korg1212->PlayDataPhy);
    2217                 korg1212->PlayDataPhy = 0;
    2218                 korg1212->playDataBufsPtr = NULL;
    2219         }
    2220 
    2221         if (korg1212->recordDataBufsPtr) {
    2222                 snd_free_pci_pages(korg1212->pci, korg1212->DataBufsSize,
    2223                                    korg1212->recordDataBufsPtr, (dma_addr_t)korg1212->RecDataPhy);
    2224                 korg1212->RecDataPhy = 0;
    2225                 korg1212->recordDataBufsPtr = NULL;
    2226         }
    2227 
    2228 #endif
    2229 
    2230         // ----------------------------------------------------
    2231         // free up memory resources used for the Shared Buffers
    2232         // ----------------------------------------------------
    2233         if (korg1212->sharedBufferPtr) {
    2234                 snd_free_pci_pages(korg1212->pci, (u32) sizeof(KorgSharedBuffer),
    2235                                    korg1212->sharedBufferPtr, (dma_addr_t)korg1212->sharedBufferPhy);
    2236                 korg1212->sharedBufferPhy = 0;
    2237                 korg1212->sharedBufferPtr = NULL;
    2238         }
    22392397}
    22402398
     
    22422400 * Card initialisation
    22432401 */
    2244 
    2245 static void snd_korg1212_card_free(snd_card_t *card)
    2246 {
    2247 #if K1212_DEBUG_LEVEL > 0
    2248         K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing card\n");
    2249 #endif
    2250         snd_korg1212_free(card->private_data);
    2251 }
    22522402
    22532403static int __devinit
     
    22672417                return -ENOENT;
    22682418        }
    2269         if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
    2270                                  sizeof(korg1212_t))) == NULL)
     2419        card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
     2420        if (card == NULL)
    22712421                return -ENOMEM;
    22722422
    2273         card->private_free = snd_korg1212_card_free;
    2274         korg1212 = (korg1212_t *)card->private_data;
    2275         korg1212->card = card;
    2276         korg1212->pci = pci;
    2277 
    2278         if ((err = snd_korg1212_create(korg1212)) < 0) {
     2423        if ((err = snd_korg1212_create(card, pci, &korg1212)) < 0) {
    22792424                snd_card_free(card);
    22802425                return err;
     
    22942439                return err;
    22952440        }
    2296         pci_set_drvdata(pci, card);
     2441        pci_set_drvdata(pci, korg1212);
    22972442        dev++;
    22982443        return 0;
     
    23012446static void __devexit snd_korg1212_remove(struct pci_dev *pci)
    23022447{
    2303         snd_card_free(pci_get_drvdata(pci));
     2448        korg1212_t *korg1212 = pci_get_drvdata(pci);
     2449        snd_card_free(korg1212->card);
    23042450        pci_set_drvdata(pci, NULL);
    23052451}
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme96.c

    r212 r224  
    2525
    2626#include <sound/driver.h>
    27 #include <asm/io.h>
    2827#include <linux/delay.h>
    2928#include <linux/init.h>
     29#include <linux/interrupt.h>
    3030#include <linux/pci.h>
    3131#include <linux/slab.h>
     32
    3233#include <sound/core.h>
    3334#include <sound/info.h>
     
    3839#define SNDRV_GET_ID
    3940#include <sound/initval.h>
     41
     42#include <asm/io.h>
    4043
    4144/* note, two last pcis should be equal, it is not a bug */
     
    255258        snd_pcm_t          *adat_pcm;
    256259        struct pci_dev     *pci;
    257         snd_info_entry_t   *proc_entry;
    258260        snd_kcontrol_t     *spdif_ctl;
    259261} rme96_t;
     
    303305snd_rme96_capture_pointer(snd_pcm_substream_t *substream);
    304306
    305 static void __init
     307static void __devinit
    306308snd_rme96_proc_init(rme96_t *rme96);
    307 
    308 static void
    309 snd_rme96_proc_done(rme96_t *rme96);
    310309
    311310static int
     
    313312                          rme96_t *rme96);
    314313
     314static int
     315snd_rme96_getinputtype(rme96_t *rme96);
     316
    315317static inline unsigned int
    316318snd_rme96_playback_ptr(rme96_t *rme96)
     
    325327        return (readl(rme96->iobase + RME96_IO_GET_REC_POS)
    326328                & RME96_RCR_AUDIO_ADDR_MASK) >> rme96->capture_frlog;
     329}
     330
     331static int
     332snd_rme96_ratecode(int rate)
     333{
     334    switch (rate) {
     335    case 32000: return SNDRV_PCM_RATE_32000;
     336    case 44100: return SNDRV_PCM_RATE_44100;
     337    case 48000: return SNDRV_PCM_RATE_48000;
     338    case 64000: return SNDRV_PCM_RATE_64000;
     339    case 88200: return SNDRV_PCM_RATE_88200;
     340    case 96000: return SNDRV_PCM_RATE_96000;
     341    }
     342    return 0;
    327343}
    328344
     
    667683
    668684        if (!(rme96->wcreg & RME96_WCR_MASTER) &&
     685            snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
    669686            (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
    670687        {
     
    972989                             snd_pcm_hw_params_t *params)
    973990{
    974         unsigned long flags;
     991        unsigned long flags;       
    975992        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    976         int err;
     993        int err, rate, dummy;
    977994
    978995        if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params))) < 0)
    979996                return err;
    980997        spin_lock_irqsave(&rme96->lock, flags);
    981         if ((err = snd_rme96_playback_setrate(rme96, params_rate(params))) < 0) {
     998        if (!(rme96->wcreg & RME96_WCR_MASTER) &&
     999            snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
     1000            (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
     1001        {
     1002                /* slave clock */
     1003                if ((int)params_rate(params) != rate) {
     1004                        spin_unlock_irqrestore(&rme96->lock, flags);
     1005                        return -EIO;                   
     1006                }
     1007        } else if ((err = snd_rme96_playback_setrate(rme96, params_rate(params))) < 0) {
    9821008                spin_unlock_irqrestore(&rme96->lock, flags);
    9831009                return err;
     
    10221048        unsigned long flags;
    10231049        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    1024         int err, isadat;
     1050        snd_pcm_runtime_t *runtime = substream->runtime;
     1051        int err, isadat, rate;
    10251052       
    10261053        if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params))) < 0)
     
    10381065                        return err;
    10391066                }
    1040         } else if (params_rate(params) != snd_rme96_capture_getrate(rme96, &isadat)) {
    1041                 spin_unlock_irqrestore(&rme96->lock, flags);
    1042                 return -EBUSY;
     1067        } else if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
     1068                if ((int)params_rate(params) != rate) {
     1069                        spin_unlock_irqrestore(&rme96->lock, flags);
     1070                        return -EIO;                   
     1071                }
     1072                if ((isadat && runtime->hw.channels_min == 2) ||
     1073                    (!isadat && runtime->hw.channels_min == 8))
     1074                {
     1075                        spin_unlock_irqrestore(&rme96->lock, flags);
     1076                        return -EIO;
     1077                }
    10431078        }
    10441079        snd_rme96_setframelog(rme96, params_channels(params), 0);
     
    11601195{
    11611196        unsigned long flags;
     1197        int rate, dummy;
    11621198        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    11631199        snd_pcm_runtime_t *runtime = substream->runtime;
     
    11661202
    11671203        spin_lock_irqsave(&rme96->lock, flags);
     1204        if (rme96->playback_substream != NULL) {
     1205                spin_unlock_irqrestore(&rme96->lock, flags);
     1206                return -EBUSY;
     1207        }
    11681208        rme96->wcreg &= ~RME96_WCR_ADAT;
    11691209        writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
     
    11731213        spin_unlock_irqrestore(&rme96->lock, flags);
    11741214
    1175         runtime->hw = snd_rme96_playback_spdif_info;   
     1215        runtime->hw = snd_rme96_playback_spdif_info;
     1216        if (!(rme96->wcreg & RME96_WCR_MASTER) &&
     1217            snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
     1218            (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
     1219        {
     1220                /* slave clock */
     1221                runtime->hw.rates = snd_rme96_ratecode(rate);
     1222                runtime->hw.rate_min = rate;
     1223                runtime->hw.rate_max = rate;
     1224        }       
    11761225        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
    11771226        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     
    11881237{
    11891238        unsigned long flags;
    1190         int isadat;
     1239        int isadat, rate;
    11911240        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    11921241        snd_pcm_runtime_t *runtime = substream->runtime;
    11931242
    1194         rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
    1195         if (snd_rme96_capture_getrate(rme96, &isadat) < 0) {
    1196                 /* no input */
    1197                 return -EIO;
    1198         }
    1199         if (isadat) {
    1200                 /* ADAT input */
    1201                 return -EBUSY;
    1202         }
    12031243        snd_pcm_set_sync(substream);
    12041244
    1205         spin_lock_irqsave(&rme96->lock, flags);
     1245        runtime->hw = snd_rme96_capture_spdif_info;
     1246        if (snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
     1247            (rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0)
     1248        {
     1249                if (isadat) {
     1250                        return -EIO;
     1251                }
     1252                runtime->hw.rates = snd_rme96_ratecode(rate);
     1253                runtime->hw.rate_min = rate;
     1254                runtime->hw.rate_max = rate;
     1255        }
     1256       
     1257        spin_lock_irqsave(&rme96->lock, flags);
     1258        if (rme96->capture_substream != NULL) {
     1259                spin_unlock_irqrestore(&rme96->lock, flags);
     1260                return -EBUSY;
     1261        }
    12061262        rme96->capture_substream = substream;
    12071263        rme96->capture_ptr = 0;
    12081264        spin_unlock_irqrestore(&rme96->lock, flags);
    12091265       
    1210         runtime->hw = snd_rme96_capture_spdif_info;
    1211        
    12121266        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
    12131267        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     
    12201274{
    12211275        unsigned long flags;
     1276        int rate, dummy;
    12221277        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    1223         snd_pcm_runtime_t *runtime = substream->runtime;
     1278        snd_pcm_runtime_t *runtime = substream->runtime;       
    12241279       
    12251280        snd_pcm_set_sync(substream);
    12261281
    12271282        spin_lock_irqsave(&rme96->lock, flags);
     1283        if (rme96->playback_substream != NULL) {
     1284                spin_unlock_irqrestore(&rme96->lock, flags);
     1285                return -EBUSY;
     1286        }
    12281287        rme96->wcreg |= RME96_WCR_ADAT;
    12291288        writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
     
    12341293       
    12351294        runtime->hw = snd_rme96_playback_adat_info;
     1295        if (!(rme96->wcreg & RME96_WCR_MASTER) &&
     1296            snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
     1297            (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
     1298        {
     1299                /* slave clock */
     1300                runtime->hw.rates = snd_rme96_ratecode(rate);
     1301                runtime->hw.rate_min = rate;
     1302                runtime->hw.rate_max = rate;
     1303        }       
    12361304        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
    12371305        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     
    12431311{
    12441312        unsigned long flags;
    1245         int isadat;
     1313        int isadat, rate;
    12461314        rme96_t *rme96 = _snd_pcm_substream_chip(substream);
    12471315        snd_pcm_runtime_t *runtime = substream->runtime;
    12481316
    1249         rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
    1250         if (snd_rme96_capture_getrate(rme96, &isadat) < 0) {
    1251                 /* no input */
    1252                 return -EIO;
    1253         }
    1254         if (!isadat) {
    1255                 /* S/PDIF input */
    1256                 return -EBUSY;
    1257         }
    12581317        snd_pcm_set_sync(substream);
    12591318
     1319        runtime->hw = snd_rme96_capture_adat_info;
     1320        if (snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG) {
     1321                /* makes no sense to use analog input. Note that analog
     1322                   expension cards AEB4/8-I are RME96_INPUT_INTERNAL */
     1323                return -EIO;
     1324        }
     1325        if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
     1326                if (!isadat) {
     1327                        return -EIO;
     1328                }
     1329                runtime->hw.rates = snd_rme96_ratecode(rate);
     1330                runtime->hw.rate_min = rate;
     1331                runtime->hw.rate_max = rate;
     1332        }
     1333       
    12601334        spin_lock_irqsave(&rme96->lock, flags);
     1335        if (rme96->capture_substream != NULL) {
     1336                spin_unlock_irqrestore(&rme96->lock, flags);
     1337                return -EBUSY;
     1338        }
    12611339        rme96->capture_substream = substream;
    12621340        rme96->capture_ptr = 0;
    12631341        spin_unlock_irqrestore(&rme96->lock, flags);
    12641342
    1265         runtime->hw = snd_rme96_capture_adat_info;
    12661343        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
    12671344        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
     
    12771354
    12781355        spin_lock_irqsave(&rme96->lock, flags);
     1356        if (RME96_ISPLAYING(rme96)) {
     1357                snd_rme96_playback_stop(rme96);
     1358        }
    12791359        rme96->playback_substream = NULL;
    12801360        rme96->playback_periodsize = 0;
     
    12961376       
    12971377        spin_lock_irqsave(&rme96->lock, flags);
     1378        if (RME96_ISRECORDING(rme96)) {
     1379                snd_rme96_capture_stop(rme96);
     1380        }
    12981381        rme96->capture_substream = NULL;
    12991382        rme96->capture_periodsize = 0;
     
    15561639                rme96->areg &= ~RME96_AR_DAC_EN;
    15571640                writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
    1558                 snd_rme96_proc_done(rme96);
    15591641                free_irq(rme96->irq, (void *)rme96);
    15601642                rme96->irq = -1;
     
    15871669}
    15881670
    1589 static int __init
     1671static int __devinit
    15901672snd_rme96_create(rme96_t *rme96)
    15911673{
     
    17831865        } else if (rme96->wcreg & RME96_WCR_MASTER) {
    17841866                snd_iprintf(buffer, "  clock mode: master\n");
     1867        } else if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
     1868                snd_iprintf(buffer, "  clock mode: slave (master anyway due to analog input setting)\n");
     1869        } else if (snd_rme96_capture_getrate(rme96, &n) < 0) {
     1870                snd_iprintf(buffer, "  clock mode: slave (master anyway due to no valid signal)\n");
    17851871        } else {
    17861872                snd_iprintf(buffer, "  clock mode: slave\n");
     
    18361922}
    18371923
    1838 static void __init
     1924static void __devinit
    18391925snd_rme96_proc_init(rme96_t *rme96)
    18401926{
    18411927        snd_info_entry_t *entry;
    18421928
    1843         if ((entry = snd_info_create_card_entry(rme96->card, "rme96", rme96->card->proc_root)) != NULL) {
    1844                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    1845                 entry->private_data = rme96;
    1846                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    1847                 entry->c.text.read_size = 256;
    1848                 entry->c.text.read = snd_rme96_proc_read;
    1849                 if (snd_info_register(entry) < 0) {
    1850                         snd_info_free_entry(entry);
    1851                         entry = NULL;
    1852                 }
    1853         }
    1854         rme96->proc_entry = entry;
    1855 }
    1856 
    1857 static void
    1858 snd_rme96_proc_done(rme96_t * rme96)
    1859 {
    1860         if (rme96->proc_entry) {
    1861                 snd_info_unregister(rme96->proc_entry);
    1862                 rme96->proc_entry = NULL;
    1863         }
     1929        if (! snd_card_proc_new(rme96->card, "rme96", &entry))
     1930                snd_info_set_text_ops(entry, rme96, snd_rme96_proc_read);
    18641931}
    18651932
     
    19532020        rme96_t *rme96 = _snd_kcontrol_chip(kcontrol);
    19542021        unsigned long flags;
    1955         int items = 3;
     2022        unsigned int items = 3;
    19562023       
    19572024        spin_lock_irqsave(&rme96->lock, flags);
     
    20252092       
    20262093        spin_lock_irqsave(&rme96->lock, flags);
    2027         change = val != snd_rme96_getinputtype(rme96);
     2094        change = (int)val != snd_rme96_getinputtype(rme96);
    20282095        snd_rme96_setinputtype(rme96, val);
    20292096        spin_unlock_irqrestore(&rme96->lock, flags);
     
    20662133        val = ucontrol->value.enumerated.item[0] % 3;
    20672134        spin_lock_irqsave(&rme96->lock, flags);
    2068         change = val != snd_rme96_getclockmode(rme96);
     2135        change = (int)val != snd_rme96_getclockmode(rme96);
    20692136        snd_rme96_setclockmode(rme96, val);
    20702137        spin_unlock_irqrestore(&rme96->lock, flags);
     
    21072174        val = ucontrol->value.enumerated.item[0] % 4;
    21082175        spin_lock_irqsave(&rme96->lock, flags);
    2109         change = val != snd_rme96_getattenuation(rme96);
     2176
     2177        change = (int)val != snd_rme96_getattenuation(rme96);
    21102178        snd_rme96_setattenuation(rme96, val);
    21112179        spin_unlock_irqrestore(&rme96->lock, flags);
     
    21482216        val = ucontrol->value.enumerated.item[0] % 4;
    21492217        spin_lock_irqsave(&rme96->lock, flags);
    2150         change = val != snd_rme96_getmontracks(rme96);
     2218        change = (int)val != snd_rme96_getmontracks(rme96);
    21512219        snd_rme96_setmontracks(rme96, val);
    21522220        spin_unlock_irqrestore(&rme96->lock, flags);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/hammerfall_mem.c

    r215 r224  
    2626    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    2727
    28     hammerfall_mem.c,v 1.5 2002/11/04 09:11:42 perex Exp
     28    hammerfall_mem.c,v 1.8 2003/02/25 13:35:44 perex Exp
    2929
    3030
     
    156156                        rbuf->flags |= HAMMERFALL_BUF_USED;
    157157                        rbuf->pci = pcidev;
    158                         MOD_INC_USE_COUNT;
    159158                        *dmaaddr = rbuf->addr;
    160159                        return rbuf->buf;
     
    173172                rbuf = &hammerfall_buffers[i];
    174173                if (rbuf->buf == addr && rbuf->pci == pcidev) {
    175                         MOD_DEC_USE_COUNT;
    176174                        rbuf->flags &= ~HAMMERFALL_BUF_USED;
    177175                        return;
     
    182180}
    183181
    184 static void __exit hammerfall_free_buffers (void)
     182static void hammerfall_free_buffers (void)
    185183
    186184{
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/hdsp.c

    r215 r224  
    6868MODULE_LICENSE("GPL");
    6969MODULE_CLASSES("{sound}");
    70 MODULE_DEVICES("{{RME,Hammerfall-DSP},");
     70MODULE_DEVICES("{{RME,Hammerfall-DSP}}");
    7171
    7272typedef enum {
     
    455455       
    456456        for (i = 0; i < timeout; i++)
    457                 if ((hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
     457                if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
    458458                        return 0;
    459459
     
    839839                if (!snd_rawmidi_transmit_empty (hmidi->output)) {
    840840                        if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
    841                                 if (n_pending > sizeof (buf))
     841                                if (n_pending > (int)sizeof (buf))
    842842                                        n_pending = sizeof (buf);
    843843                               
     
    873873        if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
    874874                if (hmidi->input) {
    875                         if (n_pending > sizeof (buf)) {
     875                        if (n_pending > (int)sizeof (buf)) {
    876876                                n_pending = sizeof (buf);
    877877                        }
     
    12791279        val = ucontrol->value.integer.value[0] & 1;
    12801280        spin_lock_irqsave(&hdsp->lock, flags);
    1281         change = val != hdsp_spdif_out(hdsp);
     1281        change = (int)val != hdsp_spdif_out(hdsp);
    12821282        hdsp_set_spdif_output(hdsp, val);
    12831283        spin_unlock_irqrestore(&hdsp->lock, flags);
     
    13941394        val = ucontrol->value.enumerated.item[0] % max;
    13951395        spin_lock_irqsave(&hdsp->lock, flags);
    1396         change = val != hdsp_sync_pref(hdsp);
     1396        change = (int)val != hdsp_sync_pref(hdsp);
    13971397        hdsp_set_sync_pref(hdsp, val);
    13981398        spin_unlock_irqrestore(&hdsp->lock, flags);
     
    14981498        val = ucontrol->value.integer.value[0] & 1;
    14991499        spin_lock_irqsave(&hdsp->lock, flags);
    1500         change = val != hdsp_line_out(hdsp);
     1500        change = (int)val != hdsp_line_out(hdsp);
    15011501        hdsp_set_line_output(hdsp, val);
    15021502        spin_unlock_irqrestore(&hdsp->lock, flags);
     
    15671567
    15681568        spin_lock_irqsave(&hdsp->lock, flags);
    1569         if ((change = gain != hdsp_read_gain(hdsp, addr)))
     1569        change = gain != hdsp_read_gain(hdsp, addr);
     1570        if (change)
    15701571                hdsp_write_gain(hdsp, addr, gain);
    15711572        spin_unlock_irqrestore(&hdsp->lock, flags);
     
    16291630
    16301631        spin_lock_irqsave(&hdsp->lock, flags);
    1631         if ((change = gain != hdsp_read_gain(hdsp, addr)))
     1632        change = gain != hdsp_read_gain(hdsp, addr);
     1633        if (change)
    16321634                hdsp_write_gain(hdsp, addr, gain);
    16331635        spin_unlock_irqrestore(&hdsp->lock, flags);
     
    18011803int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
    18021804{
    1803         int idx, err, limit;
     1805        unsigned int idx, limit;
     1806        int err;
    18041807        snd_kcontrol_t *kctl;
    18051808
     
    23002303        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23012304        snd_assert(channel_buf != NULL, return -EIO);
    2302         copy_from_user(channel_buf + pos * 4, src, count * 4);
     2305        if (copy_from_user(channel_buf + pos * 4, src, count * 4))
     2306                return -EFAULT;
    23032307        return count;
    23042308}
     
    23142318        channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
    23152319        snd_assert(channel_buf != NULL, return -EIO);
    2316         copy_to_user(dst, channel_buf + pos * 4, count * 4);
     2320        if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
     2321                return -EFAULT;
    23172322        return count;
    23182323}
     
    23882393                 */
    23892394
    2390                 if (params_rate(params) != hdsp_system_sample_rate(hdsp)) {
     2395                if ((int)params_rate(params) != hdsp_system_sample_rate(hdsp)) {
    23912396                        spin_unlock_irq(&hdsp->lock);
    23922397                        _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
     
    25642569        .channels_min =         10,
    25652570        .channels_max =         HDSP_MAX_CHANNELS,
    2566         .buffer_bytes_max =     1024*1024,
    2567         .period_bytes_min =     1,
    2568         .period_bytes_max =     1024*1024,
     2571        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
     2572        .period_bytes_min =     (64 * 4) *10,
     2573        .period_bytes_max =     (8192 * 4) * HDSP_MAX_CHANNELS,
    25692574        .periods_min =          2,
    25702575        .periods_max =          2,
     
    25892594        .channels_min =         10,
    25902595        .channels_max =         HDSP_MAX_CHANNELS,
    2591         .buffer_bytes_max =     1024*1024,
    2592         .period_bytes_min =     1,
    2593         .period_bytes_max =     1024*1024,
     2596        .buffer_bytes_max =     HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
     2597        .period_bytes_min =     (64 * 4) * 10,
     2598        .period_bytes_max =     (8192 * 4) * HDSP_MAX_CHANNELS,
    25942599        .periods_min =          2,
    25952600        .periods_max =          2,
     
    26242629        if (r->min > 48000) {
    26252630                snd_interval_t t = {
    2626                         min: hdsp->ds_channels,
    2627                         max: hdsp->ds_channels,
    2628                         integer: 1,
     2631                        .min = hdsp->ds_channels,
     2632                        .max = hdsp->ds_channels,
     2633                        .integer = 1,
    26292634                };
    26302635                return snd_interval_refine(c, &t);
    26312636        } else if (r->max < 64000) {
    26322637                snd_interval_t t = {
    2633                         min: hdsp->ss_channels,
    2634                         max: hdsp->ss_channels,
    2635                         integer: 1,
     2638                        .min = hdsp->ss_channels,
     2639                        .max = hdsp->ss_channels,
     2640                        .integer = 1,
    26362641                };
    26372642                return snd_interval_refine(c, &t);
     
    26482653        if (c->min >= hdsp->ss_channels) {
    26492654                snd_interval_t t = {
    2650                         min: 32000,
    2651                         max: 48000,
    2652                         integer: 1,
     2655                        .min = 32000,
     2656                        .max = 48000,
     2657                        .integer = 1,
    26532658                };
    26542659                return snd_interval_refine(r, &t);
    26552660        } else if (c->max <= hdsp->ds_channels) {
    26562661                snd_interval_t t = {
    2657                         min: 64000,
    2658                         max: 96000,
    2659                         integer: 1,
     2662                        .min = 64000,
     2663                        .max = 96000,
     2664                        .integer = 1,
    26602665                };
    26612666                return snd_interval_refine(r, &t);
     
    29672972        switch (rev & 0xff) {
    29682973        case 0xa:
     2974        case 0xb:
     2975        case 0x64:
    29692976                /* hdsp_initialize_firmware() will reset this */
    29702977                hdsp->card_name = "RME Hammerfall DSP";
  • GPL/branches/alsa-resync1/alsa-kernel/pci/rme9652/rme9652.c

    r212 r224  
    2222
    2323#include <sound/driver.h>
    24 #include <asm/io.h>
    2524#include <linux/delay.h>
    2625#include <linux/init.h>
     26#include <linux/interrupt.h>
    2727#include <linux/pci.h>
    2828#include <linux/slab.h>
     29
    2930#include <sound/core.h>
    3031#include <sound/control.h>
     
    3435#define SNDRV_GET_ID
    3536#include <sound/initval.h>
     37
     38#include <asm/current.h>
     39#include <asm/io.h>
    3640
    3741static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
     
    260264        snd_pcm_t *pcm;
    261265        struct pci_dev *pci;
    262         snd_info_entry_t *proc_entry;
    263266        snd_kcontrol_t *spdif_ctl;
    264267
     
    312315
    313316static struct pci_device_id snd_rme9652_ids[] __devinitdata = {
    314         {0x10ee, 0x3fc4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},     /* RME Digi9652 */
    315         {0,}
     317        {
     318                .vendor    = 0x10ee,
     319                .device    = 0x3fc4,
     320                .subvendor = PCI_ANY_ID,
     321                .subdevice = PCI_ANY_ID,
     322        },      /* RME Digi9652 */
     323        { 0, },
    316324};
    317325
     
    367375{
    368376        int status;
    369         int offset, frag;
     377        unsigned int offset, frag;
    370378        snd_pcm_uframes_t period_size = rme9652->period_bytes / 4;
    371379        snd_pcm_sframes_t delta;
     
    382390        delta = rme9652->prev_hw_offset - offset;
    383391        delta &= 0xffff;
    384         if (delta <= rme9652->max_jitter * 4)
     392        if (delta <= (snd_pcm_sframes_t)rme9652->max_jitter * 4)
    385393                offset = rme9652->prev_hw_offset;
    386394        else
     
    10941102        val = ucontrol->value.integer.value[0] & 1;
    10951103        spin_lock_irqsave(&rme9652->lock, flags);
    1096         change = val != rme9652_spdif_out(rme9652);
     1104        change = (int)val != rme9652_spdif_out(rme9652);
    10971105        rme9652_set_spdif_output(rme9652, val);
    10981106        spin_unlock_irqrestore(&rme9652->lock, flags);
     
    11811189        val = ucontrol->value.enumerated.item[0] % 3;
    11821190        spin_lock_irqsave(&rme9652->lock, flags);
    1183         change = val != rme9652_sync_mode(rme9652);
     1191        change = (int)val != rme9652_sync_mode(rme9652);
    11841192        rme9652_set_sync_mode(rme9652, val);
    11851193        spin_unlock_irqrestore(&rme9652->lock, flags);
     
    12781286        val = ucontrol->value.enumerated.item[0] % max;
    12791287        spin_lock_irqsave(&rme9652->lock, flags);
    1280         change = val != rme9652_sync_pref(rme9652);
     1288        change = (int)val != rme9652_sync_pref(rme9652);
    12811289        rme9652_set_sync_pref(rme9652, val);
    12821290        spin_unlock_irqrestore(&rme9652->lock, flags);
     
    15921600int snd_rme9652_create_controls(snd_card_t *card, rme9652_t *rme9652)
    15931601{
    1594         int idx, err;
     1602        unsigned int idx;
     1603        int err;
    15951604        snd_kcontrol_t *kctl;
    15961605
     
    17901799}
    17911800
    1792 static void __init snd_rme9652_proc_init(rme9652_t *rme9652)
     1801static void __devinit snd_rme9652_proc_init(rme9652_t *rme9652)
    17931802{
    17941803        snd_info_entry_t *entry;
    17951804
    1796         if ((entry = snd_info_create_card_entry(rme9652->card, "rme9652", rme9652->card->proc_root)) !=
    1797             NULL) {
    1798                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    1799                 entry->private_data = rme9652;
    1800                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    1801                 entry->c.text.read_size = 256;
    1802                 entry->c.text.read = snd_rme9652_proc_read;
    1803                 if (snd_info_register(entry) < 0) {
    1804                         snd_info_free_entry(entry);
    1805                         entry = NULL;
    1806                 }
    1807         }
    1808         rme9652->proc_entry = entry;
    1809 }
    1810 
    1811 static void snd_rme9652_proc_done(rme9652_t *rme9652)
    1812 {
    1813         if (rme9652->proc_entry) {
    1814                 snd_info_unregister(rme9652->proc_entry);
    1815                 rme9652->proc_entry = NULL;
    1816         }
     1805        if (! snd_card_proc_new(rme9652->card, "rme9652", &entry))
     1806                snd_info_set_text_ops(entry, rme9652, snd_rme9652_proc_read);
    18171807}
    18181808
     
    18461836        if (rme9652->irq >= 0)
    18471837                rme9652_stop(rme9652);
    1848         snd_rme9652_proc_done(rme9652);
    18491838        snd_rme9652_free_buffers(rme9652);
    18501839
     
    18601849}
    18611850
    1862 static int __init snd_rme9652_initialize_memory(rme9652_t *rme9652)
     1851static int __devinit snd_rme9652_initialize_memory(rme9652_t *rme9652)
    18631852{
    18641853        void *pb, *cb;
     
    21052094                 */
    21062095
    2107                 if (params_rate(params) !=
     2096                if ((int)params_rate(params) !=
    21082097                    rme9652_adat_sample_rate(rme9652)) {
    21092098                        spin_unlock_irq(&rme9652->lock);
     
    22762265        .channels_min =         10,
    22772266        .channels_max =         26,
    2278         .buffer_bytes_max =     1024*1024,
    2279         .period_bytes_min =     1,
    2280         .period_bytes_max =     1024*1024,
     2267        .buffer_bytes_max =     RME9652_CHANNEL_BUFFER_BYTES * 26,
     2268        .period_bytes_min =     (64 * 4) * 10,
     2269        .period_bytes_max =     (8192 * 4) * 26,
    22812270        .periods_min =          2,
    22822271        .periods_max =          2,
     
    22992288        .channels_min =         10,
    23002289        .channels_max =         26,
    2301         .buffer_bytes_max =     1024*1024,
    2302         .period_bytes_min =     1,
    2303         .period_bytes_max =     1024*1024,
     2290        .buffer_bytes_max =     RME9652_CHANNEL_BUFFER_BYTES *26,
     2291        .period_bytes_min =     (64 * 4) * 10,
     2292        .period_bytes_max =     (8192 * 4) * 26,
    23042293        .periods_min =          2,
    23052294        .periods_max =          2,
     
    23382327        snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
    23392328        if (r->min > 48000) {
    2340 #ifdef TARGET_OS2
    2341                 snd_interval_t t = {0};
    2342                 t.min = rme9652->ds_channels;
    2343                 t.max = rme9652->ds_channels;
    2344                 t.integer = 1;
    2345 #else
    23462329                snd_interval_t t = {
    2347                         min: rme9652->ds_channels,
    2348                         max: rme9652->ds_channels,
    2349                         integer: 1,
     2330                        .min = rme9652->ds_channels,
     2331                        .max = rme9652->ds_channels,
     2332                        .integer = 1,
    23502333                };
    2351 #endif
    23522334                return snd_interval_refine(c, &t);
    23532335        } else if (r->max < 88200) {
    2354 #ifdef TARGET_OS2
    2355                 snd_interval_t t = {0};
    2356                 t.min = rme9652->ss_channels;
    2357                 t.max = rme9652->ss_channels;
    2358                 t.integer = 1;
    2359 #else
    23602336                snd_interval_t t = {
    2361                         min: rme9652->ss_channels,
    2362                         max: rme9652->ss_channels,
    2363                         integer: 1,
     2337                        .min = rme9652->ss_channels,
     2338                        .max = rme9652->ss_channels,
     2339                        .integer = 1,
    23642340                };
    2365 #endif
    23662341                return snd_interval_refine(c, &t);
    23672342        }
     
    23772352        if (c->min >= rme9652->ss_channels) {
    23782353                snd_interval_t t = {
    2379 #ifdef TARGET_OS2
    2380                         44100,
    2381                         48000,
    2382                         0, 0, 1, 0,
    2383 #else
    2384                         min: 44100,
    2385                         max: 48000,
    2386                         integer: 1,
    2387 #endif
     2354                        .min = 44100,
     2355                        .max = 48000,
     2356                        .integer = 1,
    23882357                };
    23892358                return snd_interval_refine(r, &t);
    23902359        } else if (c->max <= rme9652->ds_channels) {
    23912360                snd_interval_t t = {
    2392 #ifdef TARGET_OS2
    2393                         88200,
    2394                         96000,
    2395                         0, 0, 1, 0,
    2396 #else
    2397                         min: 88200,
    2398                         max: 96000,
    2399                         integer: 1,
    2400 #endif
     2361                        .min = 88200,
     2362                        .max = 96000,
     2363                        .integer = 1,
    24012364                };
    24022365                return snd_interval_refine(r, &t);
     
    25422505};
    25432506
    2544 static int __init snd_rme9652_create_pcm(snd_card_t *card,
     2507static int __devinit snd_rme9652_create_pcm(snd_card_t *card,
    25452508                                         rme9652_t *rme9652)
    25462509{
     
    25662529}
    25672530
    2568 static int __init snd_rme9652_create(snd_card_t *card,
     2531static int __devinit snd_rme9652_create(snd_card_t *card,
    25692532                                     rme9652_t *rme9652,
    25702533                                     int precise_ptr)
     
    27612724
    27622725static struct pci_driver driver = {
    2763         .name ="RME Digi9652 (Hammerfall)",
     2726        .name     = "RME Digi9652 (Hammerfall)",
    27642727        .id_table = snd_rme9652_ids,
    2765         .probe = snd_rme9652_probe,
    2766         .remove = __devexit_p(snd_rme9652_remove),
     2728        .probe    = snd_rme9652_probe,
     2729        .remove  = __devexit_p(snd_rme9652_remove),
    27672730};
    27682731
  • GPL/branches/alsa-resync1/alsa-kernel/pci/sonicvibes.c

    r212 r224  
    2424
    2525#include <sound/driver.h>
    26 #include <asm/io.h>
    2726#include <linux/delay.h>
    2827#include <linux/init.h>
     28#include <linux/interrupt.h>
    2929#include <linux/pci.h>
    3030#include <linux/slab.h>
     31#include <linux/gameport.h>
     32
    3133#include <sound/core.h>
    3234#include <sound/pcm.h>
     
    3739#define SNDRV_GET_ID
    3840#include <sound/initval.h>
    39 #ifndef LINUX_2_2
    40 #include <linux/gameport.h>
    41 #endif
     41
     42#include <asm/io.h>
    4243
    4344MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
     
    252253
    253254        spinlock_t reg_lock;
    254         snd_info_entry_t *proc_entry;
    255255
    256256        unsigned int p_dma_size;
     
    260260        snd_kcontrol_t *master_volume;
    261261
    262 #ifndef LINUX_2_2
     262#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
    263263        struct gameport gameport;
    264264#endif
     
    272272MODULE_DEVICE_TABLE(pci, snd_sonic_ids);
    273273
    274 #ifdef TARGET_OS2
    275274static ratden_t sonicvibes_adc_clock = {
    276         4000 * 65536,
    277         48000UL * 65536,
    278         1,
    279         65536,
     275        .num_min = 4000 * 65536,
     276        .num_max = 48000UL * 65536,
     277        .num_step = 1,
     278        .den = 65536,
    280279};
    281280static snd_pcm_hw_constraint_ratdens_t snd_sonicvibes_hw_constraints_adc_clock = {
    282         1,
    283         &sonicvibes_adc_clock,
     281        .nrats = 1,
     282        .rats = &sonicvibes_adc_clock,
    284283};
    285 #else
    286 static ratden_t sonicvibes_adc_clock = {
    287         num_min: 4000 * 65536,
    288         num_max: 48000UL * 65536,
    289         num_step: 1,
    290         den: 65536,
    291 };
    292 static snd_pcm_hw_constraint_ratdens_t snd_sonicvibes_hw_constraints_adc_clock = {
    293         nrats: 1,
    294         rats: &sonicvibes_adc_clock,
    295 };
    296 #endif
    297284
    298285/*
     
    11371124        snd_card_t *card;
    11381125        snd_kcontrol_t *kctl;
    1139         int idx, err;
     1126        unsigned int idx;
     1127        int err;
    11401128
    11411129        snd_assert(sonic != NULL && sonic->card != NULL, return -EINVAL);
     
    11921180        snd_info_entry_t *entry;
    11931181
    1194         if ((entry = snd_info_create_card_entry(sonic->card, "sonicvibes", sonic->card->proc_root)) != NULL) {
    1195                 entry->content = SNDRV_INFO_CONTENT_TEXT;
    1196                 entry->private_data = sonic;
    1197                 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
    1198                 entry->c.text.read_size = 256;
    1199                 entry->c.text.read = snd_sonicvibes_proc_read;
    1200                 if (snd_info_register(entry) < 0) {
    1201                         snd_info_free_entry(entry);
    1202                         entry = NULL;
    1203                 }
    1204         }
    1205         sonic->proc_entry = entry;
    1206 }
    1207 
    1208 static void snd_sonicvibes_proc_done(sonicvibes_t * sonic)
    1209 {
    1210         if (sonic->proc_entry) {
    1211                 snd_info_unregister(sonic->proc_entry);
    1212                 sonic->proc_entry = NULL;
    1213         }
     1182        if (! snd_card_proc_new(sonic->card, "sonicvibes", &entry))
     1183                snd_info_set_text_ops(entry, sonic, snd_sonicvibes_proc_read);
    12141184}
    12151185
     
    12231193static int snd_sonicvibes_free(sonicvibes_t *sonic)
    12241194{
    1225 #ifndef LINUX_2_2
     1195#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
    12261196        if (sonic->gameport.io)
    12271197                gameport_unregister_port(&sonic->gameport);
    12281198#endif
    1229         snd_sonicvibes_proc_done(sonic);
    12301199        pci_write_config_dword(sonic->pci, 0x40, sonic->dmaa_port);
    12311200        pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port);
     
    14551424        snd_card_t *card = sonic->card;
    14561425        snd_rawmidi_str_t *dir;
    1457         int idx, err;
     1426        unsigned int idx;
     1427        int err;
    14581428
    14591429        mpu->private_data = sonic;
     
    15271497                return err;
    15281498        }
    1529 #ifndef LINUX_2_2
     1499#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
    15301500        sonic->gameport.io = sonic->game_port;
    15311501        gameport_register_port(&sonic->gameport);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/trident/trident_main.c

    r210 r224  
    2929
    3030#include <sound/driver.h>
    31 #include <asm/io.h>
    3231#include <linux/delay.h>
    3332#include <linux/init.h>
     33#include <linux/interrupt.h>
    3434#include <linux/pci.h>
    3535#include <linux/slab.h>
    3636#include <linux/vmalloc.h>
     37#ifndef TARGET_OS2 //TODO: Implement linux/gameport.h
     38#include <linux/gameport.h>
     39#endif /* !TARGET_OS2 */
     40
    3741#include <sound/core.h>
    3842#include <sound/info.h>
     
    4044#include <sound/trident.h>
    4145#include <sound/asoundef.h>
     46
     47#include <asm/io.h>
     48
     49#define chip_t trident_t
    4250
    4351static int snd_trident_pcm_mixer_build(struct snd_trident *trident, struct snd_trident_voice* voice, snd_pcm_substream_t *substream);
     
    10151023    if (voice->memblk)
    10161024        voice->LBA = voice->memblk->offset;
     1025        else
     1026                voice->LBA = runtime->dma_addr;
     1027        outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0));
    10171028
    10181029    // set ESO
     
    24192430static snd_kcontrol_new_t snd_trident_spdif_default __devinitdata =
    24202431{
    2421         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    2422         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
     2432        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     2433        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
    24232434        .info =         snd_trident_spdif_default_info,
    24242435        .get =          snd_trident_spdif_default_get,
     
    39954006EXPORT_SYMBOL(snd_trident_write_voice_regs);
    39964007EXPORT_SYMBOL(snd_trident_clear_voices);
     4008#ifdef CONFIG_PM
     4009EXPORT_SYMBOL(snd_trident_suspend);
     4010EXPORT_SYMBOL(snd_trident_resume);
     4011#endif
    39974012/* trident_memory.c symbols */
    39984013EXPORT_SYMBOL(snd_trident_synth_alloc);
  • GPL/branches/alsa-resync1/alsa-kernel/pci/ymfpci/ymfpci_main.c

    r210 r224  
    2626
    2727#include <sound/driver.h>
    28 #include <asm/io.h>
    2928#include <linux/delay.h>
    3029#include <linux/init.h>
     30#include <linux/interrupt.h>
    3131#include <linux/pci.h>
     32#include <linux/sched.h>
    3233#include <linux/slab.h>
    3334#include <linux/vmalloc.h>
     35
    3436#include <sound/core.h>
    3537#include <sound/control.h>
     
    3840#include <sound/asoundef.h>
    3941#include <sound/mpu401.h>
     42
     43#include <asm/io.h>
     44
    4045#ifdef TARGET_OS2
    4146#include <sound/timer.h>
     
    13161321{
    13171322        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
    1318         .iface =                SNDRV_CTL_ELEM_IFACE_PCM,
    1319         .name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
     1323        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
     1324        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
    13201325        .info =         snd_ymfpci_spdif_mask_info,
    13211326        .get =          snd_ymfpci_spdif_mask_get,
Note: See TracChangeset for help on using the changeset viewer.