Ignore:
Timestamp:
May 2, 2007, 9:13:43 AM (18 years ago)
Author:
Brendan Oakley
Message:

Merged 0.9.0beta6 to 0.9.0beta12. Fixed a few compilation errors.
Left include/sound/driver.h at beta9 until I figure out why it contains
so many modifications to sections that were removed in beta10.
Does not yet build. Needs more fixing.
Added a few new files that were in the copy Paul gave me to work from.

File:
1 edited

Legend:

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

    r32 r92  
    1616 *   You should have received a copy of the GNU General Public License
    1717 *   along with this program; if not, write to the Free Software
    18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    1919 *
    2020 */     
     
    2222/*
    2323  NOTES:
    24   - spdif nonaudio consumer mode does not work (at least with my 
     24  - spdif nonaudio consumer mode does not work (at least with my
    2525    Sony STR-DB830)
    2626*/
    2727
    28 #define SNDRV_MAIN_OBJECT_FILE
    29 
    3028#include <sound/driver.h>
     29#include <asm/io.h>
     30#include <linux/delay.h>
     31#include <linux/interrupt.h>
     32#include <linux/init.h>
     33#include <linux/slab.h>
     34#include <sound/core.h>
    3135#include <sound/control.h>
    3236#include <sound/pcm.h>
    3337#include <sound/ac97_codec.h>
    3438#include <sound/mpu401.h>
     39#include <sound/i2c.h>
     40#include <sound/cs8427.h>
    3541#include <sound/info.h>
    3642#define SNDRV_GET_ID
    3743#include <sound/initval.h>
    3844
     45#include <sound/asoundef.h>
     46
     47#define SND_CS8403
     48#define SND_CS8404
     49#include <sound/cs8403.h>
     50
    3951EXPORT_NO_SYMBOLS;
     52
     53MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
    4054MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
     55MODULE_LICENSE("GPL");
    4156MODULE_CLASSES("{sound}");
    4257MODULE_DEVICES("{{Hoontech SoundTrack DSP 24},"
     
    4964                "{TerraTec,EWS 88MT},"
    5065                "{TerraTec,EWS 88D},"
     66                "{TerraTec,DMX 6Fire},"
    5167                "{ICEnsemble,Generic ICE1712},"
    5268                "{ICEnsemble,Generic Envy24}}");
    53 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
    5469
    5570static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;  /* Index 0-MAX */
    5671static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;   /* ID for this card */
    57 static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;      /* Enable this card */
     72static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;          /* Enable this card */
     73static int snd_omni[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 0};       /* Delta44 & 66 Omni I/O support */
    5874
    5975MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     
    6682MODULE_PARM_DESC(snd_enable, "Enable ICE1712 soundcard.");
    6783MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
     84MODULE_PARM(snd_omni, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
     85MODULE_PARM_DESC(snd_omni, "Enable Midiman M-Audio Delta Omni I/O support.");
     86MODULE_PARM_SYNTAX(snd_omni, SNDRV_ENABLED "," SNDRV_ENABLE_DESC);
    6887
    6988#ifndef PCI_VENDOR_ID_ICE
     
    83102#define ICE1712_SUBDEVICE_EWS88MT       0x3b151511
    84103#define ICE1712_SUBDEVICE_EWS88D        0x3b152b11
     104#define ICE1712_SUBDEVICE_DMX6FIRE      0x3b153811
    85105
    86106/*
     
    256276#define ICE1712_CFG_SPDIF_OUT   0x01    /* S/PDIF output is present */
    257277
    258 /* MidiMan Delta GPIO definitions */
    259 
    260 #define ICE1712_DELTA_DFS       0x01    /* fast/slow sample rate mode */
     278/*
     279 *  MidiMan M-Audio Delta GPIO definitions
     280 */
     281
     282/* MidiMan M-Audio Delta1010 */
     283#define ICE1712_DELTA_DFS 0x01          /* fast/slow sample rate mode */
    261284                                        /* (>48kHz must be 1) */
    262                                         /* all cards */
    263285#define ICE1712_DELTA_SPDIF_IN_STAT 0x02
    264286                                        /* S/PDIF input status */
     
    275297                                        /* all except Delta44 */
    276298                                        /* look to CS8404A datasheet */
     299/* MidiMan M-Audio DeltaDiO */
     300/* 0x01 = DFS */
     301/* 0x02 = SPDIF_IN_STAT */
     302/* 0x04 = SPDIF_OUT_STAT_CLOCK */
     303/* 0x08 = SPDIF_OUT_STAT_DATA */
    277304#define ICE1712_DELTA_SPDIF_INPUT_SELECT 0x10
    278305                                        /* coaxial (0), optical (1) */
    279306                                        /* S/PDIF input select*/
    280                                         /* DeltaDiO only */
     307
     308/* MidiMan M-Audio Delta1010 */
     309/* 0x01 = DFS */
     310/* 0x02 = SPDIF_IN_STAT */
     311/* 0x04 = SPDIF_OUT_STAT_CLOCK */
     312/* 0x08 = SPDIF_OUT_STAT_DATA */
    281313#define ICE1712_DELTA_WORD_CLOCK_SELECT 0x10
    282314                                        /* 1 - clock are taken from S/PDIF input */
    283315                                        /* 0 - clock are taken from Word Clock input */
    284                                         /* Delta1010 only (affected SPMCLKIN pin of Envy24) */
     316                                        /* affected SPMCLKIN pin of Envy24 */
     317#define ICE1712_DELTA_WORD_CLOCK_STATUS 0x20
     318                                        /* 0 = valid word clock signal is present */
     319
     320/* MidiMan M-Audio Delta66 */
     321/* 0x01 = DFS */
     322/* 0x02 = SPDIF_IN_STAT */
     323/* 0x04 = SPDIF_OUT_STAT_CLOCK */
     324/* 0x08 = SPDIF_OUT_STAT_DATA */
    285325#define ICE1712_DELTA_CODEC_SERIAL_DATA 0x10
    286326                                        /* AKM4524 serial data */
    287                                         /* Delta66 and Delta44 */
    288 #define ICE1712_DELTA_WORD_CLOCK_STATUS 0x20
    289                                         /* 0 = valid word clock signal is present */
    290                                         /* Delta1010 only */
    291327#define ICE1712_DELTA_CODEC_SERIAL_CLOCK 0x20
    292328                                        /* AKM4524 serial clock */
    293329                                        /* (writting on rising edge - 0->1 */
    294                                         /* Delta66 and Delta44 */
    295330#define ICE1712_DELTA_CODEC_CHIP_A      0x40
    296331#define ICE1712_DELTA_CODEC_CHIP_B      0x80
    297332                                        /* 1 - select chip A or B */
    298                                         /* Delta66 and Delta44 */
    299 
    300 /* M-Audio Audiophile definitions */
     333
     334/* MidiMan M-Audio Delta44 */
    301335/* 0x01 = DFS */
    302 #define ICE1712_DELTA_AP_CCLK   0x02    /* AudioPhile only */
    303                                         /* SPI clock */
     336/* 0x10 = CODEC_SERIAL_DATA */
     337/* 0x20 = CODEC_SERIAL_CLOCK */
     338/* 0x40 = CODEC_CHIP_A */
     339/* 0x80 = CODEC_CHIP_B */
     340
     341/* MidiMan M-Audio Audiophile definitions */
     342/* 0x01 = DFS */
     343#define ICE1712_DELTA_AP_CCLK   0x02    /* SPI clock */
    304344                                        /* (clocking on rising edge - 0->1) */
    305 #define ICE1712_DELTA_AP_DIN    0x04    /* AudioPhile only - data input */
    306 #define ICE1712_DELTA_AP_DOUT   0x08    /* AudioPhile only - data output */
    307 #define ICE1712_DELTA_AP_CS_DIGITAL 0x10 /* AudioPhile only - CS8427 chip select */
     345#define ICE1712_DELTA_AP_DIN    0x04    /* data input */
     346#define ICE1712_DELTA_AP_DOUT   0x08    /* data output */
     347#define ICE1712_DELTA_AP_CS_DIGITAL 0x10 /* CS8427 chip select */
    308348                                        /* low signal = select */
    309 #define ICE1712_DELTA_AP_CS_CODEC 0x20  /* AudioPhile only - AK4528 chip select */
     349#define ICE1712_DELTA_AP_CS_CODEC 0x20  /* AK4528 chip select */
    310350                                        /* low signal = select */
    311351
     
    353393/* TerraTec EWS 88MT/D configuration definitions */
    354394/* RW, SDA snd SCLK are identical with EWX24/96 */
    355 
    356395#define ICE1712_EWS88_CS8414_RATE       0x07    /* CS8414 sample rate: gpio 0-2 */
    357396#define ICE1712_EWS88_RW                0x08    /* read/write switch for i2c; high = write  */
     
    362401
    363402/* i2c address */
    364 #define ICE1712_EWS88MT_CS8404_ADDR     0x40
    365 #define ICE1712_EWS88MT_INPUT_ADDR      0x46
    366 #define ICE1712_EWS88MT_OUTPUT_ADDR     0x48
     403#define ICE1712_EWS88MT_CS8404_ADDR     (0x40>>1)
     404#define ICE1712_EWS88MT_INPUT_ADDR      (0x46>>1)
     405#define ICE1712_EWS88MT_OUTPUT_ADDR     (0x48>>1)
    367406#define ICE1712_EWS88MT_OUTPUT_SENSE    0x40    /* mask */
    368 #define ICE1712_EWS88D_PCF_ADDR         0x40
     407#define ICE1712_EWS88D_PCF_ADDR         (0x40>>1)
     408
     409/* TerraTec DMX 6Fire configuration definitions */
     410#define ICE1712_6FIRE_AK4524_CS_MASK    0x07    /* AK4524 chip select #1-#3 */
     411#define ICE1712_6FIRE_RW                0x08    /* read/write switch for i2c; high = write  */
     412#define ICE1712_6FIRE_SERIAL_DATA       0x10    /* i2c & ak4524 data */
     413#define ICE1712_6FIRE_SERIAL_CLOCK      0x20    /* i2c & ak4524 clock */
     414#define ICE1712_6FIRE_TX2               0x40    /* MIDI2 */
     415#define ICE1712_6FIRE_RX2               0x80    /* MIDI2 */
     416
     417#define ICE1712_6FIRE_CS8427_ADDR       (0x22>>1) /* ?? */
    369418
    370419/*
     
    381430
    382431typedef struct _snd_ice1712 ice1712_t;
    383 
    384 typedef struct {
    385         void (*write)(ice1712_t *ice, unsigned char reg, unsigned char data);
    386         unsigned char (*read)(ice1712_t *ice, unsigned char reg);
    387         void (*write_bytes)(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data);
    388         void (*read_bytes)(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data);
    389 } ice1712_cs8427_ops_t;
    390432
    391433typedef struct {
     
    453495
    454496        unsigned int pro_volumes[20];
    455         int num_adcs;
    456         int num_dacs;
     497        int ak4528: 1,                  /* AK4524 or AK4528 */
     498            omni: 1;                    /* Delta Omni I/O */
     499        int num_adcs;                   /* AK4524 or AK4528 ADCs */
     500        int num_dacs;                   /* AK4524 or AK4528 DACs */
     501        int num_total_dacs;             /* total DACs */
    457502        unsigned char ak4524_images[4][8];
     503        unsigned char ak4524_ipga_gain[4][2];
    458504        unsigned char hoontech_boxbits[4];
    459505        unsigned int hoontech_config;
    460506        unsigned short hoontech_boxconfig[4];
    461507
     508        snd_i2c_bus_t *i2c;             /* I2C bus */
     509        snd_i2c_device_t *cs8404;       /* CS8404A I2C device */
     510        snd_i2c_device_t *cs8427;       /* CS8427 I2C device */
     511        snd_i2c_device_t *pcf8574[2];   /* PCF8574 Output/Input (EWS88MT) */
     512        snd_i2c_device_t *pcf8575;      /* PCF8575 (EWS88D) */
     513       
    462514        unsigned char cs8403_spdif_bits;
    463515        unsigned char cs8403_spdif_stream_bits;
    464516        snd_kcontrol_t *spdif_stream_ctl;
    465 
    466         unsigned char cs8427_spdif_status[5];
    467         unsigned char cs8427_spdif_stream_status[5];
    468         ice1712_cs8427_ops_t *cs8427_ops;
    469517
    470518        unsigned char gpio_direction, gpio_write_mask;
     
    651699}
    652700
    653 static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 = {
     701static snd_kcontrol_new_t snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
    654702#ifdef TARGET_OS2
    655703        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    670718/*
    671719 */
     720
    672721static void snd_ice1712_delta_cs8403_spdif_write(ice1712_t *ice, unsigned char bits)
    673722{
     
    694743}
    695744
    696 static void snd_ice1712_decode_cs8403_spdif_bits(snd_aes_iec958_t *diga,
    697                                                  unsigned char bits)
    698 {
    699         if (bits & 0x01) {      /* consumer */
    700                 if (!(bits & 0x02))
    701                         diga->status[0] |= IEC958_AES0_NONAUDIO;
    702                 if (!(bits & 0x08))
    703                         diga->status[0] |= IEC958_AES0_CON_NOT_COPYRIGHT;
    704                 switch (bits & 0x10) {
    705                 case 0x10: diga->status[0] |= IEC958_AES0_CON_EMPHASIS_NONE; break;
    706                 case 0x00: diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015; break;
    707                 }
    708                 if (!(bits & 0x80))
    709                         diga->status[1] |= IEC958_AES1_CON_ORIGINAL;
    710                 switch (bits & 0x60) {
    711                 case 0x00: diga->status[1] |= IEC958_AES1_CON_MAGNETIC_ID; break;
    712                 case 0x20: diga->status[1] |= IEC958_AES1_CON_DIGDIGCONV_ID; break;
    713                 case 0x40: diga->status[1] |= IEC958_AES1_CON_LASEROPT_ID; break;
    714                 case 0x60: diga->status[1] |= IEC958_AES1_CON_GENERAL; break;
    715                 }
    716                 switch (bits & 0x06) {
    717                 case 0x00: diga->status[3] |= IEC958_AES3_CON_FS_44100; break;
    718                 case 0x02: diga->status[3] |= IEC958_AES3_CON_FS_48000; break;
    719                 case 0x04: diga->status[3] |= IEC958_AES3_CON_FS_32000; break;
    720                 }
    721         } else {
    722                 diga->status[0] = IEC958_AES0_PROFESSIONAL;
    723                 switch (bits & 0x18) {
    724                 case 0x00: diga->status[0] |= IEC958_AES0_PRO_FS_32000; break;
    725                 case 0x10: diga->status[0] |= IEC958_AES0_PRO_FS_44100; break;
    726                 case 0x08: diga->status[0] |= IEC958_AES0_PRO_FS_48000; break;
    727                 case 0x18: diga->status[0] |= IEC958_AES0_PRO_FS_NOTID; break;
    728                 }
    729                 switch (bits & 0x60) {
    730                 case 0x20: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_NONE; break;
    731                 case 0x40: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015; break;
    732                 case 0x00: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_CCITT; break;
    733                 case 0x60: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_NOTID; break;
    734                 }
    735                 if (bits & 0x80)
    736                         diga->status[1] |= IEC958_AES1_PRO_MODE_STEREOPHONIC;
    737         }
    738 }
    739 
    740 static unsigned char snd_ice1712_encode_cs8403_spdif_bits(snd_aes_iec958_t *diga)
    741 {
    742         unsigned char bits;
    743 
    744         if (!(diga->status[0] & IEC958_AES0_PROFESSIONAL)) {
    745                 bits = 0x01;    /* consumer mode */
    746                 if (diga->status[0] & IEC958_AES0_NONAUDIO)
    747                         bits &= ~0x02;
    748                 else
    749                         bits |= 0x02;
    750                 if (diga->status[0] & IEC958_AES0_CON_NOT_COPYRIGHT)
    751                         bits &= ~0x08;
    752                 else
    753                         bits |= 0x08;
    754                 switch (diga->status[0] & IEC958_AES0_CON_EMPHASIS) {
    755                 default:
    756                 case IEC958_AES0_CON_EMPHASIS_NONE: bits |= 0x10; break;
    757                 case IEC958_AES0_CON_EMPHASIS_5015: bits |= 0x00; break;
    758                 }
    759                 if (diga->status[1] & IEC958_AES1_CON_ORIGINAL)
    760                         bits &= ~0x80;
    761                 else
    762                         bits |= 0x80;
    763                 if ((diga->status[1] & IEC958_AES1_CON_CATEGORY) == IEC958_AES1_CON_GENERAL)
    764                         bits |= 0x60;
    765                 else {
    766                         switch(diga->status[1] & IEC958_AES1_CON_MAGNETIC_MASK) {
    767                         case IEC958_AES1_CON_MAGNETIC_ID:
    768                                 bits |= 0x00; break;
    769                         case IEC958_AES1_CON_DIGDIGCONV_ID:
    770                                 bits |= 0x20; break;
    771                         default:
    772                         case IEC958_AES1_CON_LASEROPT_ID:
    773                                 bits |= 0x40; break;
    774                         }
    775                 }
    776                 switch (diga->status[3] & IEC958_AES3_CON_FS) {
    777                 default:
    778                 case IEC958_AES3_CON_FS_44100: bits |= 0x00; break;
    779                 case IEC958_AES3_CON_FS_48000: bits |= 0x02; break;
    780                 case IEC958_AES3_CON_FS_32000: bits |= 0x04; break;
    781                 }
    782         } else {
    783                 bits = 0x00;    /* professional mode */
    784                 if (diga->status[0] & IEC958_AES0_NONAUDIO)
    785                         bits &= ~0x02;
    786                 else
    787                         bits |= 0x02;
    788                 /* CHECKME: I'm not sure about the bit order in val here */
    789                 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
    790                 case IEC958_AES0_PRO_FS_32000:  bits |= 0x00; break;
    791                 case IEC958_AES0_PRO_FS_44100:  bits |= 0x10; break;    /* 44.1kHz */
    792                 case IEC958_AES0_PRO_FS_48000:  bits |= 0x08; break;    /* 48kHz */
    793                 default:
    794                 case IEC958_AES0_PRO_FS_NOTID: bits |= 0x18; break;
    795                 }
    796                 switch (diga->status[0] & IEC958_AES0_PRO_EMPHASIS) {
    797                 case IEC958_AES0_PRO_EMPHASIS_NONE: bits |= 0x20; break;
    798                 case IEC958_AES0_PRO_EMPHASIS_5015: bits |= 0x40; break;
    799                 case IEC958_AES0_PRO_EMPHASIS_CCITT: bits |= 0x00; break;
    800                 default:
    801                 case IEC958_AES0_PRO_EMPHASIS_NOTID: bits |= 0x60; break;
    802                 }
    803                 switch (diga->status[1] & IEC958_AES1_PRO_MODE) {
    804                 case IEC958_AES1_PRO_MODE_TWO:
    805                 case IEC958_AES1_PRO_MODE_STEREOPHONIC: bits |= 0x00; break;
    806                 default: bits |= 0x80; break;
    807                 }
    808         }
    809         return bits;
    810 }
    811 
    812745
    813746/*
     
    841774
    842775/*
    843  * CS8427 via SPI mode (for Audiophile)
     776 * CS8427 via SPI mode (for Audiophile), emulated I2C
    844777 */
    845778
     
    899832}
    900833
    901 /* write a register */
    902 static void snd_ice1712_ap_cs8427_write(ice1712_t *ice, unsigned char reg, unsigned char data)
    903 {
     834/* sequential write */
     835static int ap_cs8427_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count)
     836{
     837        ice1712_t *ice = snd_magic_cast(ice1712_t, device->bus->private_data, return -EIO);
     838        int res = count;
    904839        unsigned char tmp;
     840
    905841        down(&ice->gpio_mutex);
    906842        tmp = ap_cs8427_codec_select(ice);
    907         ap_cs8427_write_byte(ice, 0x20, tmp); /* address + write mode */
    908         ap_cs8427_write_byte(ice, reg, tmp);
    909         ap_cs8427_write_byte(ice, data, tmp);
     843        ap_cs8427_write_byte(ice, (device->addr << 1) | 0, tmp); /* address + write mode */
     844        while (count-- > 0)
     845                ap_cs8427_write_byte(ice, *bytes++, tmp);
    910846        ap_cs8427_codec_deassert(ice, tmp);
    911847        up(&ice->gpio_mutex);
    912 }
    913 
    914 /* read a register */
    915 static unsigned char snd_ice1712_ap_cs8427_read(ice1712_t *ice, unsigned char reg)
    916 {
    917         unsigned char tmp, data;
     848        return res;
     849}
     850
     851/* sequential read */
     852static int ap_cs8427_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count)
     853{
     854        ice1712_t *ice = snd_magic_cast(ice1712_t, device->bus->private_data, return -EIO);
     855        int res = count;
     856        unsigned char tmp;
    918857
    919858        down(&ice->gpio_mutex);
    920859        tmp = ap_cs8427_codec_select(ice);
    921         ap_cs8427_write_byte(ice, 0x20, tmp); /* address + write mode */
    922         ap_cs8427_write_byte(ice, reg, tmp);
    923         ap_cs8427_codec_deassert(ice, tmp);
    924         udelay(5);
    925         tmp = ap_cs8427_codec_select(ice);
    926         ap_cs8427_write_byte(ice, 0x21, tmp); /* address + read mode */
    927         data = ap_cs8427_read_byte(ice, tmp);
     860        ap_cs8427_write_byte(ice, (device->addr << 1) | 1, tmp); /* address + read mode */
     861        while (count-- > 0)
     862                *bytes++ = ap_cs8427_read_byte(ice, tmp);
    928863        ap_cs8427_codec_deassert(ice, tmp);
    929864        up(&ice->gpio_mutex);
    930         return data;
    931 }
    932 
    933 /* sequential write */
    934 static void snd_ice1712_ap_cs8427_write_bytes(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data)
    935 {
    936 #if 1
    937         unsigned char tmp;
    938         down(&ice->gpio_mutex);
    939         tmp = ap_cs8427_codec_select(ice);
    940         ap_cs8427_write_byte(ice, 0x20, tmp); /* address + write mode */
    941         ap_cs8427_write_byte(ice, reg | 0x80, tmp); /* incremental mode */
    942         while (bytes-- > 0)
    943                 ap_cs8427_write_byte(ice, *data++, tmp);
    944         ap_cs8427_codec_deassert(ice, tmp);
    945         up(&ice->gpio_mutex);
    946 #else
    947         while (bytes-- > 0)
    948                 snd_ice1712_ap_cs8427_write(ice, reg++, *data++);
    949 #endif
    950 }
    951 
    952 /* sequential read */
    953 static void snd_ice1712_ap_cs8427_read_bytes(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data)
    954 {
    955 #if 0 // is this working?  -- ti
    956         unsigned char tmp;
    957        
    958         down(&ice->gpio_mutex);
    959         tmp = ap_cs8427_codec_select(ice);
    960         ap_cs8427_write_byte(ice, 0x20, tmp); /* address + write mode */
    961         ap_cs8427_write_byte(ice, reg | 0x80, tmp); /* incremental mode */
    962         ap_cs8427_codec_deassert(ice, tmp);
    963         udelay(5);
    964         tmp = ap_cs8427_codec_select(ice);
    965         ap_cs8427_write_byte(ice, 0x21, tmp); /* address + read mode */
    966         while (bytes-- > 0)
    967                 *data++ = ap_cs8427_read_byte(ice, tmp);
    968         ap_cs8427_codec_deassert(ice, tmp);
    969         up(&ice->gpio_mutex);
    970 #else
    971         while (bytes-- > 0)
    972                 *data++ = snd_ice1712_ap_cs8427_read(ice, reg++);
    973 #endif
     865        return res;
     866}
     867
     868static int ap_cs8427_probeaddr(snd_i2c_bus_t *bus, unsigned short addr)
     869{
     870        if (addr == 0x10)
     871                return 1;
     872        return -ENOENT;
    974873}
    975874
    976875#ifdef TARGET_OS2
    977876static ice1712_cs8427_ops_t snd_ice1712_ap_cs8427_ops = {
    978         snd_ice1712_ap_cs8427_write,
    979         snd_ice1712_ap_cs8427_read,
    980         snd_ice1712_ap_cs8427_write_bytes,
    981         snd_ice1712_ap_cs8427_read_bytes
     877        ap_cs8427_sendbytes,
     878        ap_cs8427_readbytes,
     879        ap_cs8427_probeaddr,
    982880};
    983881#else
    984 static ice1712_cs8427_ops_t snd_ice1712_ap_cs8427_ops = {
    985         write: snd_ice1712_ap_cs8427_write,
    986         read: snd_ice1712_ap_cs8427_read,
    987         write_bytes: snd_ice1712_ap_cs8427_write_bytes,
    988         read_bytes: snd_ice1712_ap_cs8427_read_bytes,
     882static snd_i2c_ops_t ap_cs8427_i2c_ops = {
     883        sendbytes: ap_cs8427_sendbytes,
     884        readbytes: ap_cs8427_readbytes,
     885        probeaddr: ap_cs8427_probeaddr,
    989886};
    990887#endif
    991 
    992888
    993889/*
     
    996892
    997893/* send SDA and SCL */
    998 static void ewx_i2c_set(ice1712_t *ice, int clk, int data)
    999 {
     894static void ewx_i2c_setlines(snd_i2c_bus_t *bus, int clk, int data)
     895{
     896        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
    1000897        unsigned char tmp = 0;
    1001898        if (clk)
     
    1007904}
    1008905
    1009 /* send one bit */
    1010 static void ewx_i2c_send(ice1712_t *ice, int data)
    1011 {
    1012         ewx_i2c_set(ice, 0, data);
    1013         ewx_i2c_set(ice, 1, data);
    1014         ewx_i2c_set(ice, 0, data);
    1015 }
    1016 
    1017 /* start i2c */
    1018 static void ewx_i2c_start(ice1712_t *ice)
    1019 {
    1020         ewx_i2c_set(ice, 0, 1);
    1021         ewx_i2c_set(ice, 1, 1);
    1022         ewx_i2c_set(ice, 1, 0);
    1023         ewx_i2c_set(ice, 0, 0);
    1024 }
    1025 
    1026 /* stop i2c */
    1027 static void ewx_i2c_stop(ice1712_t *ice)
    1028 {
    1029         ewx_i2c_set(ice, 0, 0);
    1030         ewx_i2c_set(ice, 1, 0);
    1031         ewx_i2c_set(ice, 1, 1);
    1032 }
    1033 
    1034 /* send a byte and get ack */
    1035 static void ewx_i2c_write(ice1712_t *ice, unsigned char val)
    1036 {
    1037         int i;
    1038         for (i = 7; i >= 0; i--)
    1039                 ewx_i2c_send(ice, val & (1 << i));
    1040         ewx_i2c_send(ice, 1); /* ack */
    1041 }
    1042 
    1043 /* prepare for write and send i2c_start */
    1044 static void ewx_i2c_write_prepare(ice1712_t *ice)
    1045 {
    1046         /* set RW high */
    1047         unsigned char mask = ICE1712_EWX2496_RW;
    1048         if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_EWX2496)
    1049                 mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
    1050         snd_ice1712_gpio_write_bits(ice, mask, mask);
    1051         /* set direction both SDA and SCL write */
    1052         ice->gpio_direction |= ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA;
    1053         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
    1054         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA));
    1055                          
    1056         ewx_i2c_start(ice);
    1057 }
    1058 
    1059 /* read a bit from serial data;
    1060    this changes write mask
    1061    SDA direction must be set to low
    1062 */
    1063 static int ewx_i2c_read_bit(ice1712_t *ice)
    1064 {
    1065         int data;
     906static int ewx_i2c_getclock(snd_i2c_bus_t *bus)
     907{
     908        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
     909        return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
     910}
     911
     912static int ewx_i2c_getdata(snd_i2c_bus_t *bus, int ack)
     913{
     914        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return -EIO);
     915        int bit;
    1066916        /* set RW pin to low */
    1067917        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
    1068918        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
    1069         data = (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA) ? 1 : 0;
     919        if (ack)
     920                udelay(5);
     921        bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
    1070922        /* set RW pin to high */
    1071923        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
    1072         return data;
    1073 }
    1074 
    1075 static void ewx_i2c_read_prepare(ice1712_t *ice)
    1076 {
    1077         /* set SCL - write, SDA - read */
    1078         ice->gpio_direction |= ICE1712_EWX2496_SERIAL_CLOCK;
    1079         ice->gpio_direction &= ~ICE1712_EWX2496_SERIAL_DATA;
     924        /* reset write mask */
     925        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
     926        return bit;
     927}
     928
     929static void ewx_i2c_start(snd_i2c_bus_t *bus)
     930{
     931        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
     932        unsigned char mask;
     933
     934        save_gpio_status(ice, (unsigned char *)&bus->private_value);
     935        /* set RW high */
     936        mask = ICE1712_EWX2496_RW;
     937        switch (ice->eeprom.subvendor) {
     938        case ICE1712_SUBDEVICE_EWX2496:
     939                mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
     940                break;
     941        case ICE1712_SUBDEVICE_DMX6FIRE:
     942                mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
     943                break;
     944        }
     945        snd_ice1712_gpio_write_bits(ice, mask, mask);
     946}
     947
     948static void ewx_i2c_stop(snd_i2c_bus_t *bus)
     949{
     950        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
     951        restore_gpio_status(ice, (unsigned char *)&bus->private_value);
     952}
     953
     954static void ewx_i2c_direction(snd_i2c_bus_t *bus, int clock, int data)
     955{
     956        ice1712_t *ice = snd_magic_cast(ice1712_t, bus->private_data, return);
     957        unsigned char mask = 0;
     958
     959        if (clock)
     960                mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
     961        if (data)
     962                mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
     963        ice->gpio_direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
     964        ice->gpio_direction |= mask;
    1080965        snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
    1081         /* set write mask only to SCL */
    1082         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
    1083 }
    1084 
    1085 static void ewx_i2c_read_post(ice1712_t *ice)
    1086 {
    1087         /* reset direction both SDA and SCL to write */
    1088         ice->gpio_direction |= ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA;
    1089         snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
    1090         snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA));
    1091 }
    1092 
    1093 /* read a byte (and ack bit) */
    1094 static unsigned char ewx_i2c_read(ice1712_t *ice)
    1095 {
    1096         int i;
    1097         unsigned char data = 0;
    1098 
    1099         for (i = 7; i >= 0; i--) {
    1100                 ewx_i2c_set(ice, 1, 0);
    1101                 data |= ewx_i2c_read_bit(ice) << i;
    1102                 /* reset write mask */
    1103                 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
    1104                                   ~ICE1712_EWX2496_SERIAL_CLOCK);
    1105                 ewx_i2c_set(ice, 0, 0);
    1106         }
    1107         /* reset write mask */
    1108         ewx_i2c_read_post(ice);
    1109         ewx_i2c_send(ice, 1); /* ack */
    1110         return data;
    1111 }
    1112 
    1113 
    1114 /*
    1115  * CS8427 on EWX 24/96; Address 0x20
    1116  */
    1117 /* write a register */
    1118 static void snd_ice1712_ewx_cs8427_write(ice1712_t *ice, unsigned char reg, unsigned char data)
    1119 {
    1120         unsigned char saved[2];
    1121 
    1122         save_gpio_status(ice, saved);
    1123         ewx_i2c_write_prepare(ice);
    1124         ewx_i2c_write(ice, 0x20);  /* address + write */
    1125         ewx_i2c_write(ice, reg); /* MAP */
    1126         ewx_i2c_write(ice, data);
    1127         ewx_i2c_stop(ice);
    1128         restore_gpio_status(ice, saved);
    1129 }
    1130 
    1131 /* sequential write */
    1132 static void snd_ice1712_ewx_cs8427_write_bytes(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data)
    1133 {
    1134         unsigned char saved[2];
    1135 
    1136         save_gpio_status(ice, saved);
    1137         ewx_i2c_write_prepare(ice);
    1138         ewx_i2c_write(ice, 0x20);  /* address + write */
    1139         ewx_i2c_write(ice, reg | 0x80); /* MAP incremental mode */
    1140         while (bytes-- > 0)
    1141                 ewx_i2c_write(ice, *data++);
    1142         ewx_i2c_stop(ice);
    1143         restore_gpio_status(ice, saved);
    1144 }
    1145 
    1146 /* read a register */
    1147 static unsigned char snd_ice1712_ewx_cs8427_read(ice1712_t *ice, unsigned char reg)
    1148 {
    1149         unsigned char saved[2];
    1150         unsigned char data;
    1151 
    1152         save_gpio_status(ice, saved);
    1153         ewx_i2c_write_prepare(ice);
    1154         ewx_i2c_write(ice, 0x20);  /* address + write */
    1155         ewx_i2c_write(ice, reg); /* MAP */
    1156         /* we set up the address first but without data */
    1157         ewx_i2c_stop(ice);
    1158 
    1159         /* now read */
    1160         ewx_i2c_start(ice);
    1161         ewx_i2c_write(ice, 0x21);  /* address + read */
    1162         ewx_i2c_read_prepare(ice);
    1163         data = ewx_i2c_read(ice);
    1164         ewx_i2c_read_post(ice);
    1165         ewx_i2c_stop(ice);
    1166 
    1167         restore_gpio_status(ice, saved);
    1168         return data;
    1169 }
    1170 
    1171 /* sequential read  */
    1172 static void snd_ice1712_ewx_cs8427_read_bytes(ice1712_t *ice, unsigned char reg, int bytes, unsigned char *data)
    1173 {
    1174 #if 0 // the sequential read seems not working (yet)..
    1175         unsigned char saved[2];
    1176 
    1177         save_gpio_status(ice, saved);
    1178         ewx_i2c_write_prepare(ice);
    1179         ewx_i2c_write(ice, 0x20);  /* address + write */
    1180         ewx_i2c_write(ice, reg | 0x80); /* MAP incremental mode */
    1181         /* we set up the address first but without data */
    1182         ewx_i2c_stop(ice);
    1183 
    1184         /* now read */
    1185         ewx_i2c_start(ice);
    1186         ewx_i2c_write(ice, 0x21);  /* address + read */
    1187         ewx_i2c_read_prepare(ice);
    1188         while (bytes-- > 0)
    1189                 *data++ = ewx_i2c_read(ice);
    1190         ewx_i2c_read_post(ice);
    1191         ewx_i2c_stop(ice);
    1192         restore_gpio_status(ice, saved);
    1193 #else
    1194         while (bytes-- > 0)
    1195                 *data++ = snd_ice1712_ewx_cs8427_read(ice, reg++);
    1196 #endif
     966        snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
    1197967}
    1198968
    1199969#ifdef TARGET_OS2
    1200 static ice1712_cs8427_ops_t snd_ice1712_ewx_cs8427_ops = {
    1201         snd_ice1712_ewx_cs8427_write,
    1202         snd_ice1712_ewx_cs8427_read,
    1203         snd_ice1712_ewx_cs8427_write_bytes,
    1204         snd_ice1712_ewx_cs8427_read_bytes,
     970static snd_i2c_bit_ops_t snd_ice1712_ewx_cs8427_bit_ops = {
     971        ewx_i2c_start,
     972        ewx_i2c_stop,
     973        ewx_i2c_direction,
     974        ewx_i2c_setlines,
     975        ewx_i2c_getclock,
     976        ewx_i2c_getdata,
    1205977};
    1206978#else
    1207 static ice1712_cs8427_ops_t snd_ice1712_ewx_cs8427_ops = {
    1208         write: snd_ice1712_ewx_cs8427_write,
    1209         read: snd_ice1712_ewx_cs8427_read,
    1210         write_bytes: snd_ice1712_ewx_cs8427_write_bytes,
    1211         read_bytes: snd_ice1712_ewx_cs8427_read_bytes,
     979static snd_i2c_bit_ops_t snd_ice1712_ewx_cs8427_bit_ops = {
     980        start: ewx_i2c_start,
     981        stop: ewx_i2c_stop,
     982        direction: ewx_i2c_direction,
     983        setlines: ewx_i2c_setlines,
     984        getclock: ewx_i2c_getclock,
     985        getdata: ewx_i2c_getdata,
    1212986};
    1213987#endif
    1214988
    1215 /*
    1216  * PCF8574 on EWS88MT
    1217  */
    1218 static void snd_ice1712_ews88mt_pcf8574_write(ice1712_t *ice, unsigned char addr, unsigned char data)
    1219 {
    1220         ewx_i2c_write_prepare(ice);
    1221         ewx_i2c_write(ice, addr); /* address + write */
    1222         ewx_i2c_write(ice, data);
    1223         ewx_i2c_stop(ice);
    1224 }
    1225 
    1226 static unsigned char snd_ice1712_ews88mt_pcf8574_read(ice1712_t *ice, unsigned char addr)
    1227 {
    1228         unsigned char data;
    1229         ewx_i2c_write_prepare(ice);
    1230         ewx_i2c_write(ice, addr | 0x01);  /* address + read */
    1231         ewx_i2c_read_prepare(ice);
    1232         data = ewx_i2c_read(ice);
    1233         ewx_i2c_read_post(ice);
    1234         ewx_i2c_stop(ice);
    1235         return data;
    1236 }
    1237 
    1238989/* AK4524 chip select; address 0x48 bit 0-3 */
    1239990static void snd_ice1712_ews88mt_chip_select(ice1712_t *ice, int chip_mask)
     
    1242993
    1243994        snd_assert(chip_mask >= 0 && chip_mask <= 0x0f, return);
    1244         data = snd_ice1712_ews88mt_pcf8574_read(ice, ICE1712_EWS88MT_OUTPUT_ADDR);
     995        snd_i2c_lock(ice->i2c);
     996        snd_runtime_check(snd_i2c_readbytes(ice->pcf8574[1], &data, 1) == 1, snd_i2c_unlock(ice->i2c); return);
    1245997        ndata = (data & 0xf0) | chip_mask;
    1246998        if (ndata != data)
    1247                 snd_ice1712_ews88mt_pcf8574_write(ice, ICE1712_EWS88MT_OUTPUT_ADDR, ndata);
    1248 }
    1249 
    1250 
    1251 /*
    1252  * PCF8575 on EWS88D (16bit)
    1253  */
    1254 static void snd_ice1712_ews88d_pcf8575_write(ice1712_t *ice, unsigned char addr, unsigned short data)
    1255 {
    1256         ewx_i2c_write_prepare(ice);
    1257         ewx_i2c_write(ice, addr); /* address + write */
    1258         ewx_i2c_write(ice, data & 0xff);
    1259         ewx_i2c_write(ice, (data >> 8) & 0xff);
    1260         ewx_i2c_stop(ice);
    1261 }
    1262 
    1263 static unsigned short snd_ice1712_ews88d_pcf8575_read(ice1712_t *ice, unsigned char addr)
    1264 {
    1265         unsigned short data;
    1266         ewx_i2c_write_prepare(ice);
    1267         ewx_i2c_write(ice, addr | 0x01);  /* address + read */
    1268         ewx_i2c_read_prepare(ice);
    1269         data = ewx_i2c_read(ice);
    1270         data |= (unsigned short)ewx_i2c_read(ice) << 8;
    1271         //printk("pcf: read = 0x%x\n", data);
    1272         ewx_i2c_read_post(ice);
    1273         ewx_i2c_stop(ice);
    1274         return data;
     999                snd_runtime_check(snd_i2c_sendbytes(ice->pcf8574[1], &ndata, 1) == 1, snd_i2c_unlock(ice->i2c); return);
     1000        snd_i2c_unlock(ice->i2c);
    12751001}
    12761002
     
    12861012        unsigned int addrdata;
    12871013
    1288         snd_assert(chip >=0 && chip < 4, return);
     1014        snd_assert(chip >= 0 && chip < 4, return);
     1015
    12891016        if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_EWS88MT) {
    12901017                /* assert AK4524 CS */
     
    13271054                                  ~(data_mask | clk_mask |
    13281055                                    codecs_mask | ICE1712_EWS88_RW));
     1056                cif = 1; /* CIF high */
     1057                break;
     1058        case ICE1712_SUBDEVICE_DMX6FIRE:
     1059                data_mask = ICE1712_6FIRE_SERIAL_DATA;
     1060                clk_mask = ICE1712_6FIRE_SERIAL_CLOCK;
     1061                codecs_mask = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
     1062                tmp |= ICE1712_6FIRE_RW; /* set rw bit high */
     1063                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
     1064                                  ice->gpio_direction | data_mask | clk_mask |
     1065                                  codecs_mask | ICE1712_6FIRE_RW);
     1066                snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
     1067                                  ~(data_mask | clk_mask |
     1068                                    codecs_mask | ICE1712_6FIRE_RW));
    13291069                cif = 1; /* CIF high */
    13301070                break;
     
    13601100
    13611101        if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_EWS88MT) {
     1102                restore_gpio_status(ice, saved);
    13621103                //snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f);
    13631104                udelay(1);
     
    13731114                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    13741115                udelay(1);
    1375         }
    1376 
     1116                restore_gpio_status(ice, saved);
     1117        }
     1118
     1119        if ((addr != 0x04 && addr != 0x05) || (data & 0x80) == 0)
    13771120        ice->ak4524_images[chip][addr] = data;
    1378         restore_gpio_status(ice, saved);
    1379 }
    1380 
    1381 
    1382 /*
    1383  * decode/encode channel status bits from CS8404A on EWS88MT&D
    1384  */
    1385 static void snd_ice1712_ews_decode_cs8404_spdif_bits(snd_aes_iec958_t *diga,
    1386                                                      unsigned char bits)
    1387 {
    1388         if (bits & 0x10) {      /* consumer */
    1389                 if (!(bits & 0x20))
    1390                         diga->status[0] |= IEC958_AES0_CON_NOT_COPYRIGHT;
    1391                 if (!(bits & 0x40))
    1392                         diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
    1393                 if (!(bits & 0x80))
    1394                         diga->status[1] |= IEC958_AES1_CON_ORIGINAL;
    1395                 switch (bits & 0x03) {
    1396                 case 0x00: diga->status[1] |= IEC958_AES1_CON_DAT; break;
    1397                 case 0x03: diga->status[1] |= IEC958_AES1_CON_GENERAL; break;
    1398                 }
    1399                 switch (bits & 0x06) {
    1400                 case 0x02: diga->status[3] |= IEC958_AES3_CON_FS_32000; break;
    1401                 case 0x04: diga->status[3] |= IEC958_AES3_CON_FS_48000; break;
    1402                 case 0x06: diga->status[3] |= IEC958_AES3_CON_FS_44100; break;
    1403                 }
    1404         } else {
    1405                 diga->status[0] = IEC958_AES0_PROFESSIONAL;
    1406                 if (!(bits & 0x04))
    1407                         diga->status[0] |= IEC958_AES0_NONAUDIO;
    1408                 switch (bits & 0x60) {
    1409                 case 0x00: diga->status[0] |= IEC958_AES0_PRO_FS_32000; break;
    1410                 case 0x40: diga->status[0] |= IEC958_AES0_PRO_FS_44100; break;
    1411                 case 0x20: diga->status[0] |= IEC958_AES0_PRO_FS_48000; break;
    1412                 case 0x60: diga->status[0] |= IEC958_AES0_PRO_FS_NOTID; break;
    1413                 }
    1414                 switch (bits & 0x03) {
    1415                 case 0x02: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_NONE; break;
    1416                 case 0x01: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015; break;
    1417                 case 0x00: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_CCITT; break;
    1418                 case 0x03: diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_NOTID; break;
    1419                 }
    1420                 if (!(bits & 0x80))
    1421                         diga->status[1] |= IEC958_AES1_PRO_MODE_STEREOPHONIC;
    1422         }
    1423 }
    1424 
    1425 static unsigned char snd_ice1712_ews_encode_cs8404_spdif_bits(snd_aes_iec958_t *diga)
    1426 {
    1427         unsigned char bits;
    1428 
    1429         if (!(diga->status[0] & IEC958_AES0_PROFESSIONAL)) {
    1430                 bits = 0x10;    /* consumer mode */
    1431                 if (!(diga->status[0] & IEC958_AES0_CON_NOT_COPYRIGHT))
    1432                         bits |= 0x20;
    1433                 if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) == IEC958_AES0_CON_EMPHASIS_NONE)
    1434                         bits |= 0x40;
    1435                 if (!(diga->status[1] & IEC958_AES1_CON_ORIGINAL))
    1436                         bits |= 0x80;
    1437                 if ((diga->status[1] & IEC958_AES1_CON_CATEGORY) == IEC958_AES1_CON_GENERAL)
    1438                         bits |= 0x03;
    1439                 switch (diga->status[3] & IEC958_AES3_CON_FS) {
    1440                 default:
    1441                 case IEC958_AES3_CON_FS_44100: bits |= 0x06; break;
    1442                 case IEC958_AES3_CON_FS_48000: bits |= 0x04; break;
    1443                 case IEC958_AES3_CON_FS_32000: bits |= 0x02; break;
    1444                 }
    1445         } else {
    1446                 bits = 0x00;    /* professional mode */
    1447                 if (!(diga->status[0] & IEC958_AES0_NONAUDIO))
    1448                         bits |= 0x04;
    1449                 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
    1450                 case IEC958_AES0_PRO_FS_32000:  bits |= 0x00; break;
    1451                 case IEC958_AES0_PRO_FS_44100:  bits |= 0x40; break;    /* 44.1kHz */
    1452                 case IEC958_AES0_PRO_FS_48000:  bits |= 0x20; break;    /* 48kHz */
    1453                 default:
    1454                 case IEC958_AES0_PRO_FS_NOTID:  bits |= 0x00; break;
    1455                 }
    1456                 switch (diga->status[0] & IEC958_AES0_PRO_EMPHASIS) {
    1457                 case IEC958_AES0_PRO_EMPHASIS_NONE: bits |= 0x02; break;
    1458                 case IEC958_AES0_PRO_EMPHASIS_5015: bits |= 0x01; break;
    1459                 case IEC958_AES0_PRO_EMPHASIS_CCITT: bits |= 0x00; break;
    1460                 default:
    1461                 case IEC958_AES0_PRO_EMPHASIS_NOTID: bits |= 0x03; break;
    1462                 }
    1463                 switch (diga->status[1] & IEC958_AES1_PRO_MODE) {
    1464                 case IEC958_AES1_PRO_MODE_TWO:
    1465                 case IEC958_AES1_PRO_MODE_STEREOPHONIC: bits |= 0x00; break;
    1466                 default: bits |= 0x80; break;
    1467                 }
    1468         }
    1469         return bits;
    1470 }
    1471 
    1472 /* write on i2c address 0x40 */
     1121        else
     1122                ice->ak4524_ipga_gain[chip][addr-4] = data;
     1123}
     1124
     1125static void snd_ice1712_ak4524_reset(ice1712_t *ice, int state)
     1126{
     1127        int chip;
     1128        unsigned char reg;
     1129       
     1130        for (chip = 0; chip < ice->num_dacs/2; chip++) {
     1131                snd_ice1712_ak4524_write(ice, chip, 0x01, state ? 0x00 : 0x03);
     1132                if (state)
     1133                        continue;
     1134                for (reg = 0x04; reg < (ice->ak4528 ? 0x06 : 0x08); reg++)
     1135                        snd_ice1712_ak4524_write(ice, chip, reg, ice->ak4524_images[chip][reg]);
     1136                if (ice->ak4528)
     1137                        continue;
     1138                for (reg = 0x04; reg < 0x06; reg++)
     1139                        snd_ice1712_ak4524_write(ice, chip, reg, ice->ak4524_ipga_gain[chip][reg-4]);
     1140        }
     1141}
     1142
    14731143static void snd_ice1712_ews_cs8404_spdif_write(ice1712_t *ice, unsigned char bits)
    14741144{
    1475         unsigned short val, nval;
    1476 
     1145        unsigned char bytes[2];
     1146
     1147        snd_i2c_lock(ice->i2c);
    14771148        switch (ice->eeprom.subvendor) {
    14781149        case ICE1712_SUBDEVICE_EWS88MT:
    1479                 snd_ice1712_ews88mt_pcf8574_write(ice, ICE1712_EWS88MT_CS8404_ADDR, bits);
     1150                snd_runtime_check(snd_i2c_sendbytes(ice->cs8404, &bits, 1) == 1, snd_i2c_unlock(ice->i2c); return);
    14801151                break;
    14811152        case ICE1712_SUBDEVICE_EWS88D:
    1482                 val = snd_ice1712_ews88d_pcf8575_read(ice, ICE1712_EWS88D_PCF_ADDR);
    1483                 nval = val & 0xff;
    1484                 nval |= bits << 8;
    1485                 if (val != nval)
    1486                         snd_ice1712_ews88d_pcf8575_write(ice, ICE1712_EWS88D_PCF_ADDR, nval);
    1487                 break;
    1488         }
     1153                snd_runtime_check(snd_i2c_readbytes(ice->pcf8575, bytes, 2) == 2, snd_i2c_unlock(ice->i2c); return);
     1154                if (bits != bytes[1]) {
     1155                        bytes[1] = bits;
     1156                        snd_runtime_check(snd_i2c_readbytes(ice->pcf8575, bytes, 2) == 2, snd_i2c_unlock(ice->i2c); return);
     1157                }
     1158                break;
     1159        }
     1160        snd_i2c_unlock(ice->i2c);
    14891161}
    14901162
     
    14961168static int snd_ice1712_cs8427_set_input_clock(ice1712_t *ice, int spdif_clock)
    14971169{
     1170        unsigned char reg[2] = { 0x80 | 4, 0 };   /* CS8427 auto increment | register number 4 + data */
    14981171        unsigned char val, nval;
    1499         val = ice->cs8427_ops->read(ice, 4);
     1172        snd_i2c_lock(ice->i2c);
     1173        if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
     1174                snd_i2c_unlock(ice->i2c);
     1175                return -EREMOTE;
     1176        }
     1177        if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
     1178                snd_i2c_unlock(ice->i2c);
     1179                return -EREMOTE;
     1180        }
    15001181        nval = val & 0xf0;
    15011182        if (spdif_clock)
     
    15041185                nval |= 0x04;
    15051186        if (val != nval) {
    1506                 ice->cs8427_ops->write(ice, 4, nval);
     1187                if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
     1188                        snd_i2c_unlock(ice->i2c);
     1189                        return -EREMOTE;
     1190                }
    15071191                return 1;
    15081192        }
    1509         return 0;
    1510 }
    1511 
    1512 #if 0 // we change clock selection automatically according to the ice1712 clock source
    1513 static int snd_ice1712_cs8427_clock_select_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
    1514 {
    1515         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
    1516         uinfo->count = 1;
    1517         uinfo->value.integer.min = 0;
    1518         uinfo->value.integer.max = 1;
    1519         return 0;
    1520 }
    1521 
    1522 static int snd_ice1712_cs8427_clock_select_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    1523 {
    1524         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1525         int val;
    1526         val = ice->cs8427_ops->read(ice, 4);
    1527         ucontrol->value.integer.value[0] = (val & 0x01) ? 1 : 0;
    1528         return 0;
    1529 }
    1530 
    1531 static int snd_ice1712_cs8427_clock_select_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
    1532 {
    1533         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1534         return snd_ice1712_cs8427_set_input_clock(ice, ucontrol->value.integer.value[0]);
    1535 }
    1536 
    1537 static snd_kcontrol_new_t snd_ice1712_cs8427_clock_select = {
    1538         iface: SNDRV_CTL_ELEM_IFACE_MIXER,
    1539         name: "CS8427 Clock Select",
    1540         info: snd_ice1712_cs8427_clock_select_info,
    1541         get: snd_ice1712_cs8427_clock_select_get,
    1542         put: snd_ice1712_cs8427_clock_select_put,
    1543 };
    1544 #endif
    1545 
    1546 
    1547 /*
    1548  */
    1549 static int snd_ice1712_cs8427_in_status_info(snd_kcontrol_t *kcontrol,
    1550                                              snd_ctl_elem_info_t *uinfo)
    1551 {
    1552         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
    1553         uinfo->count = 1;
    1554         uinfo->value.integer.min = 0;
    1555         uinfo->value.integer.max = 255;
    1556         return 0;
    1557 }
    1558 
    1559 static int snd_ice1712_cs8427_in_status_get(snd_kcontrol_t *kcontrol,
    1560                                             snd_ctl_elem_value_t *ucontrol)
    1561 {
    1562         ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    1563         ucontrol->value.integer.value[0] = ice->cs8427_ops->read(ice, 15);
    1564         return 0;
    1565 }
    1566 
    1567 static snd_kcontrol_new_t snd_ice1712_cs8427_in_status = {
    1568 #ifdef TARGET_OS2
    1569         SNDRV_CTL_ELEM_IFACE_PCM,0,0,
    1570         "IEC958 Input Status",0,
    1571         SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
    1572         snd_ice1712_cs8427_in_status_info,
    1573         snd_ice1712_cs8427_in_status_get,0,0
    1574 #else
    1575         iface: SNDRV_CTL_ELEM_IFACE_PCM,
    1576         info: snd_ice1712_cs8427_in_status_info,
    1577         name: "IEC958 Input Status",
    1578         access: SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
    1579         get: snd_ice1712_cs8427_in_status_get,
    1580 #endif
    1581 };
    1582 
     1193        snd_i2c_unlock(ice->i2c);
     1194        return 0;
     1195}
    15831196
    15841197/*
     
    16241237        case ICE1712_SUBDEVICE_DELTA44:
    16251238        case ICE1712_SUBDEVICE_AUDIOPHILE:
    1626                 /* FIXME: we should put AK452x codecs to reset state
    1627                    when this bit is being changed */
    16281239                spin_unlock_irqrestore(&ice->reg_lock, flags);
     1240                snd_ice1712_ak4524_reset(ice, 1);
    16291241                down(&ice->gpio_mutex);
    16301242                tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
     
    16361248                snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
    16371249                up(&ice->gpio_mutex);
     1250                snd_ice1712_ak4524_reset(ice, 0);
    16381251                return;
    16391252        }
     
    21971810#endif
    21981811
    2199 static void __exit snd_ice1712_pcm_free(snd_pcm_t *pcm)
     1812static void snd_ice1712_pcm_free(snd_pcm_t *pcm)
    22001813{
    22011814        ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
     
    22041817}
    22051818
    2206 static int __init snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
     1819static int __devinit snd_ice1712_pcm(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
    22071820{
    22081821        snd_pcm_t *pcm;
     
    22291842                *rpcm = pcm;
    22301843
    2231         printk("Consumer PCM code does not work well at the moment --jk\n");
    2232 
    2233         return 0;
    2234 }
    2235 
    2236 static void __exit snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
     1844        printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
     1845
     1846        return 0;
     1847}
     1848
     1849static void snd_ice1712_pcm_free_ds(snd_pcm_t *pcm)
    22371850{
    22381851        ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
     
    22411854}
    22421855
    2243 static int __init snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
     1856static int __devinit snd_ice1712_pcm_ds(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
    22441857{
    22451858        snd_pcm_t *pcm;
     
    23841997}
    23851998
    2386 static void snd_ice1712_cs8427_set_status(ice1712_t *ice, snd_pcm_runtime_t *runtime,
    2387                                           unsigned char *status)
    2388 {
    2389         if (status[0] & IEC958_AES0_PROFESSIONAL) {
    2390                 status[0] &= ~IEC958_AES0_PRO_FS;
    2391                 switch (runtime->rate) {
    2392                 case 32000: status[0] |= IEC958_AES0_PRO_FS_32000; break;
    2393                 case 44100: status[0] |= IEC958_AES0_PRO_FS_44100; break;
    2394                 case 48000: status[0] |= IEC958_AES0_PRO_FS_48000; break;
    2395                 default: status[0] |= IEC958_AES0_PRO_FS_NOTID; break;
    2396                 }
    2397         } else {
    2398                 status[3] &= ~IEC958_AES3_CON_FS;
    2399                 switch (runtime->rate) {
    2400                 case 32000: status[3] |= IEC958_AES3_CON_FS_32000; break;
    2401                 case 44100: status[3] |= IEC958_AES3_CON_FS_44100; break;
    2402                 case 48000: status[3] |= IEC958_AES3_CON_FS_48000; break;
    2403                 }
    2404         }
    2405 }
    2406 
    24071999static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
    24082000{
     
    24102002        ice1712_t *ice = snd_pcm_substream_chip(substream);
    24112003        unsigned int tmp;
    2412         unsigned char tmpst[5];
    24132004        int change;
    24142005
     
    24422033        case ICE1712_SUBDEVICE_EWX2496:
    24432034        case ICE1712_SUBDEVICE_AUDIOPHILE:
    2444                 /* setup S/PDIF */
    2445                 memcpy(tmpst, ice->cs8427_spdif_stream_status, 5);
    2446                 snd_ice1712_cs8427_set_status(ice, substream->runtime, tmpst);
    2447                 change = memcmp(tmpst, ice->cs8427_spdif_stream_status, 5) != 0;
    2448                 memcpy(ice->cs8427_spdif_stream_status, tmpst, 5);
    2449                 spin_unlock_irqrestore(&ice->reg_lock, flags);
    2450                 if (change) {
    2451                         snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif_stream_ctl->id);
    2452                         ice->cs8427_ops->write_bytes(ice, 32, 5, tmpst);
    2453                 }
    2454                 return 0;
     2035                snd_cs8427_iec958_pcm(ice->cs8427, substream->runtime->rate);
     2036                break;
    24552037        case ICE1712_SUBDEVICE_EWS88MT:
    24562038        case ICE1712_SUBDEVICE_EWS88D:
     
    26092191
    26102192        ice->cs8403_spdif_stream_bits = ice->cs8403_spdif_bits;
    2611         memcpy(ice->cs8427_spdif_stream_status, ice->cs8427_spdif_status, 5);
    2612         if (ice->spdif_stream_ctl != NULL) {
    2613                 ice->spdif_stream_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    2614                 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE |
    2615                                SNDRV_CTL_EVENT_MASK_INFO, &ice->spdif_stream_ctl->id);
    2616         }
     2193        if (ice->cs8427)
     2194                snd_cs8427_iec958_active(ice->cs8427, 1);
    26172195
    26182196        return 0;
     
    26372215
    26382216        ice->playback_pro_substream = NULL;
    2639 
    2640         if (ice->spdif_stream_ctl != NULL) {
    2641                 ice->spdif_stream_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
    2642                 snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE |
    2643                                SNDRV_CTL_EVENT_MASK_INFO, &ice->spdif_stream_ctl->id);
    2644         }
     2217        if (ice->cs8427)
     2218                snd_cs8427_iec958_active(ice->cs8427, 0);
    26452219
    26462220        return 0;
     
    26552229}
    26562230
    2657 static void __exit snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
     2231static void snd_ice1712_pcm_profi_free(snd_pcm_t *pcm)
    26582232{
    26592233        ice1712_t *ice = snd_magic_cast(ice1712_t, pcm->private_data, return);
     
    27082282#endif
    27092283
    2710 static int __init snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
     2284static int __devinit snd_ice1712_pcm_profi(ice1712_t * ice, int device, snd_pcm_t ** rpcm)
    27112285{
    27122286        snd_pcm_t *pcm;
     
    27332307                *rpcm = pcm;
    27342308       
     2309        if (ice->cs8427) {
     2310                /* assign channels to iec958 */
     2311                err = snd_cs8427_iec958_build(ice->cs8427,
     2312                                              pcm->streams[0].substream,
     2313                                              pcm->streams[1].substream);
     2314                if (err < 0)
     2315                        return err;
     2316        }
     2317
    27352318        if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
    27362319                return err;
     
    28582441        unsigned char nval = ucontrol->value.integer.value[0];
    28592442        int change = ice->ak4524_images[chip][addr] != nval;
     2443        if (change)
     2444                snd_ice1712_ak4524_write(ice, chip, addr, nval);
     2445        return change;
     2446}
     2447
     2448static int snd_ice1712_ak4524_ipga_gain_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     2449{
     2450        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
     2451        uinfo->count = 1;
     2452        uinfo->value.integer.min = 0;
     2453        uinfo->value.integer.max = 36;
     2454        return 0;
     2455}
     2456
     2457static int snd_ice1712_ak4524_ipga_gain_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     2458{
     2459        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     2460        int chip = kcontrol->private_value / 8;
     2461        int addr = kcontrol->private_value % 8;
     2462        ucontrol->value.integer.value[0] = ice->ak4524_ipga_gain[chip][addr-4] & 0x7f;
     2463        return 0;
     2464}
     2465
     2466static int snd_ice1712_ak4524_ipga_gain_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     2467{
     2468        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     2469        int chip = kcontrol->private_value / 8;
     2470        int addr = kcontrol->private_value % 8;
     2471        unsigned char nval = (ucontrol->value.integer.value[0] % 37) | 0x80;
     2472        int change = ice->ak4524_ipga_gain[chip][addr] != nval;
    28602473        if (change)
    28612474                snd_ice1712_ak4524_write(ice, chip, addr, nval);
     
    29602573        }
    29612574       
    2962         return 0;
    2963 }
    2964 
    2965 static void /*__init*/ snd_ice1712_ac97_init(ac97_t *ac97)
     2575        /* initialize volumes */
     2576        for (idx = 0; idx < 20; idx++) {
     2577                ice->pro_volumes[idx] = 0x80008000;     /* mute */
     2578                snd_ice1712_update_volume(ice, idx);
     2579        }
     2580        return 0;
     2581}
     2582
     2583static void snd_ice1712_ac97_init(ac97_t *ac97)
    29662584{
    29672585        // ice1712_t *ice = snd_magic_cast(ice1712_t, ac97->private_data, return);
     
    29712589}
    29722590
    2973 static void __exit snd_ice1712_mixer_free_ac97(ac97_t *ac97)
     2591static void snd_ice1712_mixer_free_ac97(ac97_t *ac97)
    29742592{
    29752593        ice1712_t *ice = snd_magic_cast(ice1712_t, ac97->private_data, return);
     
    29772595}
    29782596
    2979 static int __init snd_ice1712_ac97_mixer(ice1712_t * ice)
     2597static int __devinit snd_ice1712_ac97_mixer(ice1712_t * ice)
    29802598{
    29812599        int err;
     
    29892607                ac97.private_data = ice;
    29902608                ac97.private_free = snd_ice1712_mixer_free_ac97;
    2991                 if ((err = snd_ac97_mixer(ice->card, &ac97, &ice->ac97)) < 0)
     2609                if ((err = snd_ac97_mixer(ice->card, &ac97, &ice->ac97)) < 0) {
     2610                        printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
     2611                        // return err;
     2612                } else {
     2613                if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
    29922614                        return err;
     2615                }
    29932616                return 0;
    29942617        }
     
    30032626                ac97.private_free = snd_ice1712_mixer_free_ac97;
    30042627                if ((err = snd_ac97_mixer(ice->card, &ac97, &ice->ac97)) < 0)
    3005                         return err;
    3006                 if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
    30072628                        return err;
    30082629                return 0;
     
    30472668}
    30482669
    3049 static void __init snd_ice1712_proc_init(ice1712_t * ice)
     2670static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
    30502671{
    30512672        snd_info_entry_t *entry;
     
    30922713}
    30932714
    3094 static snd_kcontrol_new_t snd_ice1712_eeprom = {
     2715static snd_kcontrol_new_t snd_ice1712_eeprom __devinitdata = {
    30952716#ifdef TARGET_OS2
    30962717        SNDRV_CTL_ELEM_IFACE_CARD,0,0,
     
    31262747        case ICE1712_SUBDEVICE_DELTADIO2496:
    31272748        case ICE1712_SUBDEVICE_DELTA66:
    3128                 snd_ice1712_decode_cs8403_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_bits);
    3129                 break;
    3130         case ICE1712_SUBDEVICE_AUDIOPHILE:
    3131         case ICE1712_SUBDEVICE_EWX2496:
    3132                 memcpy(ucontrol->value.iec958.status, ice->cs8427_spdif_status, 5);
     2749                snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_bits);
    31332750                break;
    31342751        case ICE1712_SUBDEVICE_EWS88MT:
    31352752        case ICE1712_SUBDEVICE_EWS88D:
    3136                 snd_ice1712_ews_decode_cs8404_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_bits);
     2753                snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_bits);
    31372754                break;
    31382755        }
     
    31522769        case ICE1712_SUBDEVICE_DELTADIO2496:
    31532770        case ICE1712_SUBDEVICE_DELTA66:
    3154                 val = snd_ice1712_encode_cs8403_spdif_bits(&ucontrol->value.iec958);
     2771                val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
    31552772                spin_lock_irqsave(&ice->reg_lock, flags);
    31562773                change = ice->cs8403_spdif_bits != val;
     
    31632780                }
    31642781                break;
    3165         case ICE1712_SUBDEVICE_AUDIOPHILE:
    3166         case ICE1712_SUBDEVICE_EWX2496:
    3167                 spin_lock_irqsave(&ice->reg_lock, flags);
    3168                 change = memcmp(ucontrol->value.iec958.status, ice->cs8427_spdif_status, 5) != 0;
    3169                 memcpy(ice->cs8427_spdif_status, ucontrol->value.iec958.status, 5);
    3170                 if (change && ice->playback_pro_substream == NULL) {
    3171                         spin_unlock_irqrestore(&ice->reg_lock, flags);
    3172                         ice->cs8427_ops->write_bytes(ice, 32, 5, ice->cs8427_spdif_status);
    3173                 } else
    3174                         spin_unlock_irqrestore(&ice->reg_lock, flags);
    3175                 break;
    31762782        case ICE1712_SUBDEVICE_EWS88MT:
    31772783        case ICE1712_SUBDEVICE_EWS88D:
    3178                 val = snd_ice1712_ews_encode_cs8404_spdif_bits(&ucontrol->value.iec958);
     2784                val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
    31792785                spin_lock_irqsave(&ice->reg_lock, flags);
    31802786                change = ice->cs8403_spdif_bits != val;
     
    31932799}
    31942800
    3195 static snd_kcontrol_new_t snd_ice1712_spdif_default =
     2801static snd_kcontrol_new_t snd_ice1712_spdif_default __devinitdata =
    31962802{
    31972803#ifdef TARGET_OS2
     
    32772883}
    32782884
    3279 static snd_kcontrol_new_t snd_ice1712_spdif_maskc =
     2885static snd_kcontrol_new_t snd_ice1712_spdif_maskc __devinitdata =
    32802886{
    32812887#ifdef TARGET_OS2
     
    32942900};
    32952901
    3296 static snd_kcontrol_new_t snd_ice1712_spdif_maskp =
     2902static snd_kcontrol_new_t snd_ice1712_spdif_maskp __devinitdata =
    32972903{
    32982904#ifdef TARGET_OS2
     
    33272933        case ICE1712_SUBDEVICE_DELTADIO2496:
    33282934        case ICE1712_SUBDEVICE_DELTA66:
    3329                 snd_ice1712_decode_cs8403_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_stream_bits);
    3330                 break;
    3331         case ICE1712_SUBDEVICE_AUDIOPHILE:
    3332         case ICE1712_SUBDEVICE_EWX2496:
    3333                 //ice->cs8427_ops->read_bytes(ice, 32, 5, ucontrol->value.iec958.status);
    3334                 memcpy(ucontrol->value.iec958.status, ice->cs8427_spdif_stream_status, 5);
     2935                snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_stream_bits);
    33352936                break;
    33362937        case ICE1712_SUBDEVICE_EWS88MT:
    33372938        case ICE1712_SUBDEVICE_EWS88D:
    3338                 snd_ice1712_ews_decode_cs8404_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_stream_bits);
     2939                snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->cs8403_spdif_stream_bits);
    33392940                break;
    33402941        }
     
    33542955        case ICE1712_SUBDEVICE_DELTADIO2496:
    33552956        case ICE1712_SUBDEVICE_DELTA66:
    3356                 val = snd_ice1712_encode_cs8403_spdif_bits(&ucontrol->value.iec958);
     2957                val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
    33572958                spin_lock_irqsave(&ice->reg_lock, flags);
    33582959                change = ice->cs8403_spdif_stream_bits != val;
     
    33652966                }
    33662967                break;
    3367         case ICE1712_SUBDEVICE_AUDIOPHILE:
    3368         case ICE1712_SUBDEVICE_EWX2496:
    3369                 spin_lock_irqsave(&ice->reg_lock, flags);
    3370                 change = memcmp(ice->cs8427_spdif_stream_status,
    3371                                 ucontrol->value.iec958.status, 5) != 0;
    3372                 if (change && ice->playback_pro_substream != NULL) {
    3373                         memcpy(ice->cs8427_spdif_stream_status,
    3374                                ucontrol->value.iec958.status, 5);
    3375                         spin_unlock_irqrestore(&ice->reg_lock, flags);
    3376                         ice->cs8427_ops->write_bytes(ice, 32, 5, ucontrol->value.iec958.status);
    3377                 } else
    3378                         spin_unlock_irqrestore(&ice->reg_lock, flags);
    3379                 break;
    33802968        case ICE1712_SUBDEVICE_EWS88MT:
    33812969        case ICE1712_SUBDEVICE_EWS88D:
    3382                 val = snd_ice1712_ews_encode_cs8404_spdif_bits(&ucontrol->value.iec958);
     2970                val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
    33832971                spin_lock_irqsave(&ice->reg_lock, flags);
    33842972                change = ice->cs8403_spdif_stream_bits != val;
     
    33972985}
    33982986
    3399 static snd_kcontrol_new_t snd_ice1712_spdif_stream =
     2987static snd_kcontrol_new_t snd_ice1712_spdif_stream __devinitdata =
    34002988{
    34012989#ifdef TARGET_OS2
     
    34173005
    34183006#ifdef TARGET_OS2
    3419 #define ICE1712_GPIO(xiface, xname, xindex, shift, xaccess) \
     3007#define ICE1712_GPIO(xiface, xname, xindex, mask, invert, xaccess) \
    34203008{ xiface, 0, 0, xname, 0, xaccess, snd_ice1712_gpio_info, \
    34213009  snd_ice1712_gpio_get, snd_ice1712_gpio_put, \
    3422   shift }
     3010        mask | (invert << 24) }
    34233011#else
    3424 #define ICE1712_GPIO(xiface, xname, xindex, shift, xaccess) \
     3012#define ICE1712_GPIO(xiface, xname, xindex, mask, invert, xaccess) \
    34253013{ iface: xiface, name: xname, access: xaccess, info: snd_ice1712_gpio_info, \
    34263014  get: snd_ice1712_gpio_get, put: snd_ice1712_gpio_put, \
    3427   private_value: shift }
     3015  private_value: mask | (invert << 24) }
    34283016#endif
    34293017
     
    34413029        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    34423030        unsigned char mask = kcontrol->private_value & 0xff;
     3031        int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
    34433032        unsigned char saved[2];
    34443033       
    34453034        save_gpio_status(ice, saved);
    3446         ucontrol->value.integer.value[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
     3035        ucontrol->value.integer.value[0] = (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0) ^ invert;
    34473036        restore_gpio_status(ice, saved);
    34483037        return 0;
     
    34533042        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    34543043        unsigned char mask = kcontrol->private_value & 0xff;
     3044        int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
    34553045        unsigned char saved[2];
    34563046        int val, nval;
     
    34583048        if (kcontrol->private_value & (1 << 31))
    34593049                return -EPERM;
    3460         nval = ucontrol->value.integer.value[0] ? mask : 0;
     3050        nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
    34613051        save_gpio_status(ice, saved);
    34623052        val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
     
    34673057}
    34683058
    3469 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_select =
    3470 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 0);
    3471 static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_status =
    3472 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
    3473 static snd_kcontrol_new_t snd_ice1712_deltadio2496_spdif_in_select =
    3474 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0);
    3475 static snd_kcontrol_new_t snd_ice1712_delta_spdif_in_status =
    3476 ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
     3059static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_select __devinitdata =
     3060ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
     3061static snd_kcontrol_new_t snd_ice1712_delta1010_wordclock_status __devinitdata =
     3062ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
     3063static snd_kcontrol_new_t snd_ice1712_deltadio2496_spdif_in_select __devinitdata =
     3064ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
     3065static snd_kcontrol_new_t snd_ice1712_delta_spdif_in_status __devinitdata =
     3066ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_PCM, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
    34773067
    34783068static int snd_ice1712_pro_spdif_master_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     
    35093099        spin_unlock_irqrestore(&ice->reg_lock, flags);
    35103100
    3511         if (ice->cs8427_ops) {
     3101        if (ice->cs8427) {
    35123102                /* change CS8427 clock source too */
    35133103                snd_ice1712_cs8427_set_input_clock(ice, ucontrol->value.integer.value[0]);
     
    35173107}
    35183108
    3519 static snd_kcontrol_new_t snd_ice1712_pro_spdif_master = {
     3109static snd_kcontrol_new_t snd_ice1712_pro_spdif_master __devinitdata = {
    35203110#ifdef TARGET_OS2
    35213111        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    35633153        val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
    35643154        val &= 3;
    3565         cval = inw(ICEMT(ice, ROUTE_CAPTURE));
     3155        cval = inl(ICEMT(ice, ROUTE_CAPTURE));
    35663156        cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
    35673157        if (val == 1 && idx < 2)
     
    35853175        /* update PSDOUT */
    35863176        if (ucontrol->value.enumerated.item[0] >= 11)
    3587                 nval = idx < 2 ? 1 : 0;
     3177                nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
    35883178        else if (ucontrol->value.enumerated.item[0] >= 9)
    3589                 nval = 3;
     3179                nval = 3; /* spdif in */
    35903180        else if (ucontrol->value.enumerated.item[0] >= 1)
    3591                 nval = 2;
     3181                nval = 2; /* analog in */
    35923182        else
    3593                 nval = 0;
     3183                nval = 0; /* pcm */
    35943184        shift = ((idx % 2) * 8) + ((idx / 2) * 2);
    35953185        val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
     
    35993189        if (change)
    36003190                outw(val, ICEMT(ice, ROUTE_PSDOUT03));
    3601         if (nval < 2)
     3191        if (nval < 2) /* dig mixer of pcm */
    36023192                return change;
    36033193
    36043194        /* update CAPTURE */
    3605         val = old_val = inw(ICEMT(ice, ROUTE_CAPTURE));
     3195        val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
    36063196        shift = ((idx / 2) * 8) + ((idx % 2) * 4);
    3607         if (nval == 2) {
     3197        if (nval == 2) { /* analog in */
    36083198                nval = ucontrol->value.enumerated.item[0] - 1;
    36093199                val &= ~(0x07 << shift);
    36103200                val |= nval << shift;
    3611         } else {
     3201        } else { /* spdif in */
    36123202                nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
    36133203                val &= ~(0x08 << shift);
     
    36163206        if (val != old_val) {
    36173207                change = 1;
    3618                 outw(val, ICEMT(ice, ROUTE_CAPTURE));
     3208                outl(val, ICEMT(ice, ROUTE_CAPTURE));
    36193209        }
    36203210        return change;
     
    36763266}
    36773267
    3678 static snd_kcontrol_new_t snd_ice1712_mixer_pro_analog_route = {
     3268static snd_kcontrol_new_t snd_ice1712_mixer_pro_analog_route __devinitdata = {
    36793269#ifdef TARGET_OS2
    36803270        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    36923282};
    36933283
    3694 static snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route = {
     3284static snd_kcontrol_new_t snd_ice1712_mixer_pro_spdif_route __devinitdata = {
    36953285#ifdef TARGET_OS2
    36963286        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    37423332}
    37433333
    3744 static snd_kcontrol_new_t snd_ice1712_mixer_pro_volume_rate = {
     3334static snd_kcontrol_new_t snd_ice1712_mixer_pro_volume_rate __devinitdata = {
    37453335#ifdef TARGET_OS2
    37463336        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    37823372}
    37833373
    3784 static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak = {
     3374static snd_kcontrol_new_t snd_ice1712_mixer_pro_peak __devinitdata = {
    37853375#ifdef TARGET_OS2
    37863376        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    38463436}
    38473437
    3848 static snd_kcontrol_new_t snd_ice1712_ewx_input_sense = {
     3438static snd_kcontrol_new_t snd_ice1712_ewx_input_sense __devinitdata = {
    38493439#ifdef TARGET_OS2
    38503440        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    38643454};
    38653455
    3866 static snd_kcontrol_new_t snd_ice1712_ewx_output_sense = {
     3456static snd_kcontrol_new_t snd_ice1712_ewx_output_sense __devinitdata = {
    38673457#ifdef TARGET_OS2
    38683458        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    38903480{
    38913481        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    3892         unsigned char saved[2];
    38933482        unsigned char data;
    38943483
    3895         save_gpio_status(ice, saved);
    3896         data = snd_ice1712_ews88mt_pcf8574_read(ice, ICE1712_EWS88MT_OUTPUT_ADDR);
    3897         restore_gpio_status(ice, saved);
     3484        snd_i2c_lock(ice->i2c);
     3485        if (snd_i2c_readbytes(ice->pcf8574[1], &data, 1) != 1) {
     3486                snd_i2c_unlock(ice->i2c);
     3487                return -EREMOTE;
     3488        }
     3489        snd_i2c_unlock(ice->i2c);
    38983490        ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
    38993491        return 0;
     
    39043496{
    39053497        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    3906         unsigned char saved[2];
    39073498        unsigned char data, ndata;
    39083499
    3909         save_gpio_status(ice, saved);
    3910         data = snd_ice1712_ews88mt_pcf8574_read(ice, ICE1712_EWS88MT_OUTPUT_ADDR);
     3500        snd_i2c_lock(ice->i2c);
     3501        if (snd_i2c_readbytes(ice->pcf8574[1], &data, 1) != 1) {
     3502                snd_i2c_unlock(ice->i2c);
     3503                return -EREMOTE;
     3504        }
    39113505        ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
    3912         if (ndata != data)
    3913                 snd_ice1712_ews88mt_pcf8574_write(ice, ICE1712_EWS88MT_OUTPUT_ADDR, ndata);
    3914         restore_gpio_status(ice, saved);
     3506        if (ndata != data && snd_i2c_sendbytes(ice->pcf8574[1], &ndata, 1) != 1) {
     3507                snd_i2c_unlock(ice->i2c);
     3508                return -EREMOTE;
     3509        }
     3510        snd_i2c_unlock(ice->i2c);
    39153511        return ndata != data;
    3916 
    39173512}
    39183513
     
    39223517        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    39233518        int channel = kcontrol->id.index;
    3924         unsigned char saved[2];
    39253519        unsigned char data;
    39263520
    39273521        snd_assert(channel >= 0 && channel <= 7, return 0);
    3928         save_gpio_status(ice, saved);
    3929         data = snd_ice1712_ews88mt_pcf8574_read(ice, ICE1712_EWS88MT_INPUT_ADDR);
    3930         restore_gpio_status(ice, saved);
     3522        snd_i2c_lock(ice->i2c);
     3523        if (snd_i2c_readbytes(ice->pcf8574[0], &data, 1) != 1) {
     3524                snd_i2c_unlock(ice->i2c);
     3525                return -EREMOTE;
     3526        }
    39313527        /* reversed; high = +4dBu, low = -10dBV */
    39323528        ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
     
    39393535        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
    39403536        int channel = kcontrol->id.index;
    3941         unsigned char saved[2];
    39423537        unsigned char data, ndata;
    39433538
    39443539        snd_assert(channel >= 0 && channel <= 7, return 0);
    3945         save_gpio_status(ice, saved);
    3946         data = snd_ice1712_ews88mt_pcf8574_read(ice, ICE1712_EWS88MT_INPUT_ADDR);
     3540        snd_i2c_lock(ice->i2c);
     3541        if (snd_i2c_readbytes(ice->pcf8574[0], &data, 1) != 1) {
     3542                snd_i2c_unlock(ice->i2c);
     3543                return -EREMOTE;
     3544        }
    39473545        ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
    3948         if (ndata != data)
    3949                 snd_ice1712_ews88mt_pcf8574_write(ice, ICE1712_EWS88MT_INPUT_ADDR, ndata);
    3950         restore_gpio_status(ice, saved);
     3546        if (ndata != data && snd_i2c_sendbytes(ice->pcf8574[0], &ndata, 1) != 1) {
     3547                snd_i2c_unlock(ice->i2c);
     3548                return -EREMOTE;
     3549        }
     3550        snd_i2c_unlock(ice->i2c);
    39513551        return ndata != data;
    39523552}
    39533553
    3954 static snd_kcontrol_new_t snd_ice1712_ews88mt_input_sense = {
     3554static snd_kcontrol_new_t snd_ice1712_ews88mt_input_sense __devinitdata = {
    39553555#ifdef TARGET_OS2
    39563556        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    39683568};
    39693569
    3970 static snd_kcontrol_new_t snd_ice1712_ews88mt_output_sense = {
     3570static snd_kcontrol_new_t snd_ice1712_ews88mt_output_sense __devinitdata = {
    39713571#ifdef TARGET_OS2
    39723572        SNDRV_CTL_ELEM_IFACE_MIXER,0,0,
     
    40033603        int shift = kcontrol->private_value & 0xff;
    40043604        int invert = (kcontrol->private_value >> 8) & 1;
    4005         unsigned short data;
     3605        unsigned char data[2];
    40063606       
    4007         data = snd_ice1712_ews88d_pcf8575_read(ice, ICE1712_EWS88D_PCF_ADDR);
    4008         //printk("pcf: read 0x%x\n", data);
    4009         data = (data >> shift) & 0x01;
     3607        snd_i2c_lock(ice->i2c);
     3608        if (snd_i2c_readbytes(ice->pcf8575, data, 2) != 2) {
     3609                snd_i2c_unlock(ice->i2c);
     3610                return -EREMOTE;
     3611        }
     3612        snd_i2c_unlock(ice->i2c);
     3613        data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
    40103614        if (invert)
    4011                 data ^= 0x01;
    4012         ucontrol->value.integer.value[0] = data;
     3615                data[0] ^= 0x01;
     3616        ucontrol->value.integer.value[0] = data[0];
    40133617        return 0;
    40143618}
     
    40193623        int shift = kcontrol->private_value & 0xff;
    40203624        int invert = (kcontrol->private_value >> 8) & 1;
    4021         unsigned short data, ndata;
     3625        unsigned char data[2], ndata[2];
    40223626        int change;
    40233627
    4024         data = snd_ice1712_ews88d_pcf8575_read(ice, ICE1712_EWS88D_PCF_ADDR);
    4025         ndata = data & ~(1 << shift);
     3628        snd_i2c_lock(ice->i2c);
     3629        if (snd_i2c_readbytes(ice->pcf8575, data, 2) != 2) {
     3630                snd_i2c_unlock(ice->i2c);
     3631                return -EREMOTE;
     3632        }
     3633        ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
    40263634        if (invert) {
    40273635                if (! ucontrol->value.integer.value[0])
    4028                         ndata |= (1 << shift);
     3636                        ndata[shift >> 3] |= (1 << (shift & 7));
    40293637        } else {
    40303638                if (ucontrol->value.integer.value[0])
    4031                         ndata |= (1 << shift);
    4032         }
    4033         change = (data != ndata);
    4034         if (change) {
    4035                 ndata &= 0xff;
    4036                 ndata |= (unsigned short)ice->cs8403_spdif_stream_bits << 8;
    4037                 snd_ice1712_ews88d_pcf8575_write(ice, ICE1712_EWS88D_PCF_ADDR, ndata);
    4038                 //printk("pcf: write 0x%x\n", ndata);
    4039         }
     3639                        ndata[shift >> 3] |= (1 << (shift & 7));
     3640        }
     3641        change = (data[shift >> 3] != ndata[shift >> 3]);
     3642        if (change && snd_i2c_sendbytes(ice->pcf8575, data, 2) != 2) {
     3643                snd_i2c_unlock(ice->i2c);
     3644                return -EREMOTE;
     3645        }
     3646        snd_i2c_unlock(ice->i2c);
    40403647        return change;
    40413648}
    40423649
    40433650#ifdef TARGET_OS2
    4044 #define EWS88D_CONTROL(xiface, xname, xindex, xshift, xinvert, xaccess) \
     3651#define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
    40453652{ xiface,0,0,\
    40463653  xname, 0,\
     
    40523659}
    40533660#else
    4054 #define EWS88D_CONTROL(xiface, xname, xindex, xshift, xinvert, xaccess) \
     3661#define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
    40553662{ iface: xiface,\
    40563663  name: xname,\
     
    40633670#endif
    40643671
    4065 static snd_kcontrol_new_t snd_ice1712_ews88d_spdif_in_opt =
    4066 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 0, 1, 0); /* inverted */
    4067 static snd_kcontrol_new_t snd_ice1712_ews88d_opt_out_adat =
    4068 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 0, 1, 0, 0);
    4069 static snd_kcontrol_new_t snd_ice1712_ews88d_master_adat =
    4070 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 0, 2, 0, 0);
    4071 static snd_kcontrol_new_t snd_ice1712_ews88d_adat_enable =
    4072 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 0, 3, 0, 0);
    4073 static snd_kcontrol_new_t snd_ice1712_ews88d_adat_through =
    4074 EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 0, 4, 1, 0);
     3672static snd_kcontrol_new_t snd_ice1712_ews88d_controls[] __devinitdata = {
     3673        EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
     3674        EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
     3675        EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
     3676        EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
     3677        EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
     3678};
     3679
     3680
     3681/*
     3682 * DMX 6Fire controls
     3683 */
     3684
     3685#if 0 // XXX not working yet
     3686static int snd_ice1712_6fire_read_pca(ice1712_t *ice)
     3687{
     3688        unsigned char byte;
     3689        snd_i2c_lock(ice->i2c);
     3690        byte = 0; /* read port */
     3691        snd_i2c_sendbytes(ice->pcf8575, &byte, 1);
     3692        if (snd_i2c_readbytes(ice->pcf8575, &byte, 1) != 1) {
     3693                snd_i2c_unlock(ice->i2c);
     3694                return -EREMOTE;
     3695        }
     3696        snd_i2c_unlock(ice->i2c);
     3697        return byte;
     3698}
     3699
     3700static int snd_ice1712_6fire_write_pca(ice1712_t *ice, unsigned char data)
     3701{
     3702        unsigned char bytes[2];
     3703        snd_i2c_lock(ice->i2c);
     3704        bytes[0] = 1; /* write port */
     3705        bytes[1] = data;
     3706        if (snd_i2c_sendbytes(ice->pcf8575, bytes, 2) != 2) {
     3707                snd_i2c_unlock(ice->i2c);
     3708                return -EREMOTE;
     3709        }
     3710        snd_i2c_unlock(ice->i2c);
     3711        return 0;
     3712}
     3713
     3714static int snd_ice1712_6fire_control_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
     3715{
     3716        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
     3717        uinfo->count = 1;
     3718        uinfo->value.integer.min = 0;
     3719        uinfo->value.integer.max = 1;
     3720        return 0;
     3721}
     3722
     3723static int snd_ice1712_6fire_control_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     3724{
     3725        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     3726        int shift = kcontrol->private_value & 0xff;
     3727        int invert = (kcontrol->private_value >> 8) & 1;
     3728        int data;
     3729       
     3730        if ((data = snd_ice1712_6fire_read_pca(ice)) < 0)
     3731                return data;
     3732        data = (data >> shift) & 1;
     3733        if (invert)
     3734                data ^= 1;
     3735        ucontrol->value.integer.value[0] = data;
     3736        return 0;
     3737}
     3738
     3739static int snd_ice1712_6fire_control_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
     3740{
     3741        ice1712_t *ice = snd_kcontrol_chip(kcontrol);
     3742        int shift = kcontrol->private_value & 0xff;
     3743        int invert = (kcontrol->private_value >> 8) & 1;
     3744        int data, ndata;
     3745       
     3746        if ((data = snd_ice1712_6fire_read_pca(ice)) < 0)
     3747                return data;
     3748        ndata = data & ~(1 << shift);
     3749        if (ucontrol->value.integer.value[0])
     3750                ndata |= (1 << shift);
     3751        if (invert)
     3752                ndata ^= (1 << shift);
     3753        if (data != ndata) {
     3754                snd_ice1712_6fire_write_pca(ice, (unsigned char)ndata);
     3755                return 1;
     3756        }
     3757        return 0;
     3758}
     3759
     3760#define DMX6FIRE_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
     3761{ iface: xiface,\
     3762  name: xname,\
     3763  access: xaccess,\
     3764  info: snd_ice1712_6fire_control_info,\
     3765  get: snd_ice1712_6fire_control_get,\
     3766  put: snd_ice1712_6fire_control_put,\
     3767  private_value: xshift | (xinvert << 8),\
     3768}
     3769
     3770static snd_kcontrol_new_t snd_ice1712_6fire_led __devinitdata =
     3771DMX6FIRE_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Breakbox LED", 6, 0, 0);
     3772
     3773#endif // XXX not working yet
    40753774
    40763775
     
    40793778 */
    40803779
    4081 static unsigned char __init snd_ice1712_read_i2c(ice1712_t *ice,
     3780static unsigned char __devinit snd_ice1712_read_i2c(ice1712_t *ice,
    40823781                                                 unsigned char dev,
    40833782                                                 unsigned char addr)
     
    40913790}
    40923791
    4093 static int __init snd_ice1712_read_eeprom(ice1712_t *ice)
     3792static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice)
    40943793{
    40953794        int dev = 0xa0;         /* EEPROM device address */
     
    41373836}
    41383837
    4139 static void __init snd_ice1712_ak4524_init(ice1712_t *ice)
    4140 {
    4141         static unsigned char inits[8] = {
    4142                 0x07, /* 0: all power up */
    4143                 0x03, /* 1: ADC/DAC reset */
    4144                 0x60, /* 2: 24bit I2S */
    4145                 0x19, /* 3: deemphasis off */
    4146                 0x00, /* 4: ADC left muted */
    4147                 0x00, /* 5: ADC right muted */
    4148                 0x00, /* 6: DAC left muted */
    4149                 0x00, /* 7: DAC right muted */
     3838static void __devinit snd_ice1712_ak4524_init(ice1712_t *ice)
     3839{
     3840        static unsigned char inits[] = {
     3841                0x00, 0x07, /* 0: all power up */
     3842                0x01, 0x00, /* 1: ADC/DAC reset */
     3843                0x02, 0x60, /* 2: 24bit I2S */
     3844                0x03, 0x19, /* 3: deemphasis off */
     3845                0x01, 0x03, /* 1: ADC/DAC enable */
     3846                0x04, 0x00, /* 4: ADC left muted */
     3847                0x05, 0x00, /* 5: ADC right muted */
     3848                0x04, 0x80, /* 4: ADC IPGA gain 0dB */
     3849                0x05, 0x80, /* 5: ADC IPGA gain 0dB */
     3850                0x06, 0x00, /* 6: DAC left muted */
     3851                0x07, 0x00, /* 7: DAC right muted */
     3852                0xff, 0xff
    41503853        };
    4151         int chip;
    4152         unsigned char reg;
    4153 
    4154         for (chip = 0; chip < ice->num_dacs/2; chip++) {
    4155                 for (reg = 0; reg < 8; ++reg)
    4156                         snd_ice1712_ak4524_write(ice, chip, reg, inits[reg]);
    4157         }
    4158 }
    4159 
    4160 /* init CS8427 transciever */
    4161 static void __init snd_ice1712_cs8427_init(ice1712_t *ice)
    4162 {
    4163         static unsigned char initvals[] = {
    4164                 /* RMCK to OMCK, no validity, disable mutes, TCBL=output */
    4165                 0x80,
    4166                 /* hold last valid audio sample, RMCK=256*Fs, normal stereo operation */
    4167                 0x00,
    4168                 /* output drivers normal operation, Tx<=serial, Rx=>serial */
    4169                 0x0c,
    4170                 /* Run off, CMCK=256*Fs, output time base = OMCK, input time base =
    4171                    covered input clock, recovered input clock source is Envy24 */
    4172                 0x04,
    4173                 /* Serial audio input port data format = I2S */
    4174                 0x05, /* SIDEL=1, SILRPOL=1 */
    4175                 /* Serial audio output port data format = I2S */
    4176                 0x05,   /* SODEL=1, SOLRPOL=1 */
    4177         };
    4178         unsigned char buf[32];
    4179 
    4180         /* verify CS8427 ID */
    4181         if (ice->cs8427_ops->read(ice, 127) != 0x71) {
    4182                 snd_printk("unable to find CS8427 signature, initialization is not completed\n");
    4183                 return;
    4184         }
    4185         /* turn off run bit while making changes to configuration */
    4186         ice->cs8427_ops->write(ice, 4, 0x00);
    4187         /* send initial values */
    4188         ice->cs8427_ops->write_bytes(ice, 1, 6, initvals);
    4189         /* Turn off CS8427 interrupt stuff that is not used in hardware */
    4190         memset(buf, 0, sizeof(buf));
    4191         /* from address 9 to 15 */
    4192         ice->cs8427_ops->write_bytes(ice, 9, 7, buf);
    4193         /* unmask the input PLL clock, V, confidence, biphase, parity status bits */
    4194         //buf[0] = 0x1f;
    4195         buf[0] = 0;
    4196         /* Registers 32-55 window to CS buffer
    4197            Inhibit D->E transfers from overwriting first 5 bytes of CS data.
    4198            Allow D->E transfers (all) of CS data.
    4199            Allow E->F transfer of CS data.
    4200            One byte mode; both A/B channels get same written CB data.
    4201            A channel info is output to chip's EMPH* pin. */
    4202         buf[1] = 0x10;
    4203         /* Use internal buffer to transmit User (U) data.
    4204            Chip's U pin is an output.
    4205            Transmit all O's for user data. */
    4206         //buf[2] = 0x10;
    4207         buf[2] = 0x00;
    4208         ice->cs8427_ops->write_bytes(ice, 17, 3, buf);
    4209         /* turn on run bit and rock'n'roll */
    4210         ice->cs8427_ops->write(ice, 4, initvals[3] | 0x40);
    4211         /* write default channel status bytes */
    4212         ice->cs8427_ops->write_bytes(ice, 32, 5, ice->cs8427_spdif_status);
    4213 
    4214         /*
    4215          * add controls..
    4216          */
    4217         snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_cs8427_in_status, ice));
    4218 #if 0
    4219         snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_cs8427_clock_select, ice));
    4220 #endif
    4221 }
    4222 
    4223 static void __init snd_ice1712_stdsp24_gpio_write(ice1712_t *ice, unsigned char byte)
     3854        int chip, idx;
     3855        unsigned char *ptr, reg, data;
     3856
     3857        for (chip = idx = 0; chip < ice->num_dacs/2; chip++) {
     3858                ptr = inits;
     3859                while (*ptr != 0xff) {
     3860                        reg = *ptr++;
     3861                        data = *ptr++;
     3862                        if (ice->ak4528) {
     3863                                if (reg > 5)
     3864                                        continue;
     3865                                if (reg >= 4 && (data & 0x80))
     3866                                        continue;
     3867                        }
     3868                        if (reg == 0x03 && ice->ak4528)
     3869                                data = 0x0d;    /* deemphasis off, turn LR highpass filters on */
     3870                        snd_ice1712_ak4524_write(ice, chip, reg, data);
     3871                }
     3872        }
     3873}
     3874
     3875static void __devinit snd_ice1712_stdsp24_gpio_write(ice1712_t *ice, unsigned char byte)
    42243876{
    42253877        byte |= ICE1712_STDSP24_CLOCK_BIT;
     
    42343886}
    42353887
    4236 static void __init snd_ice1712_stdsp24_darear(ice1712_t *ice, int activate)
     3888static void __devinit snd_ice1712_stdsp24_darear(ice1712_t *ice, int activate)
    42373889{
    42383890        down(&ice->gpio_mutex);
     
    42423894}
    42433895
    4244 static void __init snd_ice1712_stdsp24_mute(ice1712_t *ice, int activate)
     3896static void __devinit snd_ice1712_stdsp24_mute(ice1712_t *ice, int activate)
    42453897{
    42463898        down(&ice->gpio_mutex);
     
    42503902}
    42513903
    4252 static void __init snd_ice1712_stdsp24_insel(ice1712_t *ice, int activate)
     3904static void __devinit snd_ice1712_stdsp24_insel(ice1712_t *ice, int activate)
    42533905{
    42543906        down(&ice->gpio_mutex);
     
    42583910}
    42593911
    4260 static void __init snd_ice1712_stdsp24_box_channel(ice1712_t *ice, int box, int chn, int activate)
     3912static void __devinit snd_ice1712_stdsp24_box_channel(ice1712_t *ice, int box, int chn, int activate)
    42613913{
    42623914        down(&ice->gpio_mutex);
     
    43053957}
    43063958
    4307 static void __init snd_ice1712_stdsp24_box_midi(ice1712_t *ice, int box, int master, int slave)
     3959static void __devinit snd_ice1712_stdsp24_box_midi(ice1712_t *ice, int box, int master, int slave)
    43083960{
    43093961        down(&ice->gpio_mutex);
     
    43363988}
    43373989
    4338 static void __init snd_ice1712_stdsp24_init(ice1712_t *ice)
     3990static void __devinit snd_ice1712_stdsp24_init(ice1712_t *ice)
    43393991{
    43403992        int box, chn;
     
    43944046}
    43954047
    4396 static int __init snd_ice1712_chip_init(ice1712_t *ice)
    4397 {
     4048static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
     4049{
     4050        int err, has_i2c = 0;
     4051
    43984052        outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
    43994053        udelay(200);
     
    44264080        }
    44274081
     4082        /* determine I2C, DACs and ADCs */
    44284083        switch (ice->eeprom.subvendor) {
    44294084        case ICE1712_SUBDEVICE_AUDIOPHILE:
     4085                ice->ak4528 = 1;
     4086                /* follow thru */
    44304087        case ICE1712_SUBDEVICE_EWX2496:
    4431                 ice->num_adcs = ice->num_dacs = 2;
     4088                has_i2c = 1;
     4089                ice->num_adcs = ice->num_dacs = ice->num_total_dacs = 2;
    44324090                break; 
    44334091        case ICE1712_SUBDEVICE_DELTA44:
    44344092        case ICE1712_SUBDEVICE_DELTA66:
    4435                 ice->num_adcs = ice->num_dacs = 4;
     4093                ice->num_adcs = ice->num_dacs = ice->num_total_dacs = 4;
     4094                if (ice->omni)
     4095                        ice->num_total_dacs = 8;
    44364096                break;
    44374097        case ICE1712_SUBDEVICE_EWS88MT:
    4438                 ice->num_adcs = ice->num_dacs = 8;
    4439                 break;
    4440         }
    4441 
     4098                has_i2c = 1;
     4099                /* follow thru */
     4100        case ICE1712_SUBDEVICE_DELTA1010:
     4101                ice->num_adcs = ice->num_dacs = ice->num_total_dacs = 8;
     4102                break;
     4103        case ICE1712_SUBDEVICE_EWS88D:
     4104                has_i2c = 1;
     4105                break;
     4106        case ICE1712_SUBDEVICE_DMX6FIRE:
     4107                has_i2c = 1;
     4108                ice->num_adcs = ice->num_dacs = ice->num_total_dacs = 6;
     4109                break;
     4110        }
     4111
     4112        if (has_i2c) {
     4113                if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
     4114                        snd_printk("unable to create I2C bus\n");
     4115                        return err;
     4116                }
     4117                ice->i2c->private_data = ice;
     4118                switch (ice->eeprom.subvendor) {
     4119                case ICE1712_SUBDEVICE_AUDIOPHILE:
     4120                        ice->i2c->ops = &ap_cs8427_i2c_ops;
     4121                        break;
     4122                case ICE1712_SUBDEVICE_EWX2496:
     4123                case ICE1712_SUBDEVICE_EWS88MT:
     4124                case ICE1712_SUBDEVICE_EWS88D:
     4125                case ICE1712_SUBDEVICE_DMX6FIRE:
     4126                        ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
     4127                        break;
     4128                }
     4129                switch (ice->eeprom.subvendor) {
     4130                case ICE1712_SUBDEVICE_AUDIOPHILE:
     4131                case ICE1712_SUBDEVICE_EWX2496:
     4132                        if ((err = snd_cs8427_create(ice->i2c, CS8427_BASE_ADDR, &ice->cs8427)) < 0) {
     4133                                snd_printk("CS8427 initialization failed\n");
     4134                                return err;
     4135                        }
     4136                        break;
     4137                case ICE1712_SUBDEVICE_DMX6FIRE:
     4138#if 0 // XXX not working yet
     4139                        if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", 0x40>>1, &ice->pcf8575)) < 0)
     4140                                return err;
     4141                        if ((err = snd_cs8427_create(ice->i2c, 0x11, &ice->cs8427)) < 0) {
     4142                                snd_printk("CS8427 initialization failed\n");
     4143                                return err;
     4144                        }
     4145#endif // XXX not working yet
     4146                        break;
     4147                case ICE1712_SUBDEVICE_EWS88MT:
     4148                        if ((err = snd_i2c_device_create(ice->i2c, "CS8404", ICE1712_EWS88MT_CS8404_ADDR, &ice->cs8404)) < 0)
     4149                                return err;
     4150                        if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)", ICE1712_EWS88MT_INPUT_ADDR, &ice->pcf8574[0])) < 0)
     4151                                return err;
     4152                        if ((err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)", ICE1712_EWS88MT_OUTPUT_ADDR, &ice->pcf8574[1])) < 0)
     4153                                return err;
     4154                        break;
     4155                case ICE1712_SUBDEVICE_EWS88D:
     4156                        if ((err = snd_i2c_device_create(ice->i2c, "PCF8575", ICE1712_EWS88D_PCF_ADDR, &ice->pcf8575)) < 0)
     4157                                return err;
     4158                        break;
     4159                }
     4160        }
     4161        /* second stage of initialization, analog parts and others */
    44424162        switch (ice->eeprom.subvendor) {
    44434163        case ICE1712_SUBDEVICE_DELTA66:
     
    44464166        case ICE1712_SUBDEVICE_EWX2496:
    44474167        case ICE1712_SUBDEVICE_EWS88MT:
     4168        case ICE1712_SUBDEVICE_DMX6FIRE:
    44484169                snd_ice1712_ak4524_init(ice);
    44494170                break;
     
    44674188                snd_ice1712_delta_cs8403_spdif_write(ice, ice->cs8403_spdif_bits);
    44684189                break;
     4190        }
     4191        switch (ice->eeprom.subvendor) {
    44694192        case ICE1712_SUBDEVICE_EWS88MT:
    44704193        case ICE1712_SUBDEVICE_EWS88D:
     
    44884211        if (err < 0)
    44894212                return err;
    4490         for (idx = 0; idx < ice->num_dacs; idx++) {
     4213        for (idx = 0; idx < ice->num_total_dacs; idx++) {
    44914214                kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
    44924215                if (kctl == NULL)
     
    45704293        case ICE1712_SUBDEVICE_DELTA66:
    45714294        case ICE1712_SUBDEVICE_EWS88MT:
     4295        case ICE1712_SUBDEVICE_DMX6FIRE:
    45724296                for (idx = 0; idx < ice->num_dacs; ++idx) {
    45734297                        snd_kcontrol_t ctl;
     
    45804304                        ctl.get = snd_ice1712_ak4524_volume_get;
    45814305                        ctl.put = snd_ice1712_ak4524_volume_put;
    4582                         ctl.private_value = (idx / 2) * 8 + (idx % 2) + 6; /* reigster 6 & 7 */
     4306                        if (ice->ak4528)
     4307                                ctl.private_value = (idx / 2) * 8 + (idx % 2) + 4; /* register 4 & 5 */
     4308                        else
     4309                                ctl.private_value = (idx / 2) * 8 + (idx % 2) + 6; /* register 6 & 7 */
    45834310                        ctl.private_data = ice;
    45844311                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
    45854312                                return err;
    45864313                }
    4587                 for (idx = 0; idx < ice->num_adcs; ++idx) {
     4314                for (idx = 0; idx < ice->num_adcs && !ice->ak4528; ++idx) {
    45884315                        snd_kcontrol_t ctl;
    45894316                        memset(&ctl, 0, sizeof(ctl));
     
    45954322                        ctl.get = snd_ice1712_ak4524_volume_get;
    45964323                        ctl.put = snd_ice1712_ak4524_volume_put;
    4597                         ctl.private_value = (idx / 2) * 8 + (idx % 2) + 4; /* reigster 4 & 5 */
     4324                        ctl.private_value = (idx / 2) * 8 + (idx % 2) + 4; /* register 4 & 5 */
     4325                        ctl.private_data = ice;
     4326                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
     4327                                return err;
     4328                        memset(&ctl, 0, sizeof(ctl));
     4329                        strcpy(ctl.id.name, "IPGA Analog Capture Volume");
     4330                        ctl.id.index = idx;
     4331                        ctl.id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     4332                        ctl.info = snd_ice1712_ak4524_ipga_gain_info;
     4333                        ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
     4334                        ctl.get = snd_ice1712_ak4524_ipga_gain_get;
     4335                        ctl.put = snd_ice1712_ak4524_ipga_gain_put;
     4336                        ctl.private_value = (idx / 2) * 8 + (idx % 2) + 4; /* register 4 & 5 */
    45984337                        ctl.private_data = ice;
    45994338                        if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
     
    46384377                break;
    46394378        case ICE1712_SUBDEVICE_EWS88D:
    4640                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_spdif_in_opt, ice));
     4379                for (idx = 0; idx < sizeof(snd_ice1712_ews88d_controls)/sizeof(snd_ice1712_ews88d_controls[0]); idx++) {
     4380                        err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
    46414381                if (err < 0)
    46424382                        return err;
    4643                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_opt_out_adat, ice));
     4383                }
     4384                break;
     4385        case ICE1712_SUBDEVICE_DMX6FIRE:
     4386#if 0 // XXX not working yet
     4387                err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_led, ice));
    46444388                if (err < 0)
    46454389                        return err;
    4646                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_master_adat, ice));
    4647                 if (err < 0)
    4648                         return err;
    4649                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_adat_enable, ice));
    4650                 if (err < 0)
    4651                         return err;
    4652                 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_adat_through, ice));
    4653                 if (err < 0)
    4654                         return err;
    4655                 break;
    4656         }
    4657 
    4658         return 0;
    4659 }
    4660 
    4661 static int __exit snd_ice1712_free(ice1712_t *ice)
     4390#endif
     4391                break;
     4392        }
     4393
     4394        return 0;
     4395}
     4396
     4397static int snd_ice1712_free(ice1712_t *ice)
    46624398{
    46634399        if (ice->res_port == NULL)
     
    46724408        if (ice->irq)
    46734409                free_irq(ice->irq, (void *) ice);
    4674         if (ice->res_port)
     4410        if (ice->res_port) {
    46754411                release_resource(ice->res_port);
    4676         if (ice->res_ddma_port)
     4412                kfree_nocheck(ice->res_port);
     4413        }
     4414        if (ice->res_ddma_port) {
    46774415                release_resource(ice->res_ddma_port);
    4678         if (ice->res_dmapath_port)
     4416                kfree_nocheck(ice->res_ddma_port);
     4417        }
     4418        if (ice->res_dmapath_port) {
    46794419                release_resource(ice->res_dmapath_port);
    4680         if (ice->res_profi_port)
     4420                kfree_nocheck(ice->res_dmapath_port);
     4421        }
     4422        if (ice->res_profi_port) {
    46814423                release_resource(ice->res_profi_port);
     4424                kfree_nocheck(ice->res_profi_port);
     4425        }
    46824426        snd_magic_kfree(ice);
    46834427        return 0;
    46844428}
    46854429
    4686 static int __exit snd_ice1712_dev_free(snd_device_t *device)
     4430static int snd_ice1712_dev_free(snd_device_t *device)
    46874431{
    46884432        ice1712_t *ice = snd_magic_cast(ice1712_t, device->device_data, return -ENXIO);
     
    46904434}
    46914435
    4692 static int __init snd_ice1712_create(snd_card_t * card,
     4436static int __devinit snd_ice1712_create(snd_card_t * card,
    46934437                                     struct pci_dev *pci,
     4438                                     int omni,
    46944439                                     ice1712_t ** r_ice1712)
    46954440{
     
    47054450        };
    47064451#endif
     4452
    47074453        *r_ice1712 = NULL;
    47084454
     
    47204466        if (ice == NULL)
    47214467                return -ENOMEM;
     4468        ice->omni = omni ? 1 : 0;
    47224469        spin_lock_init(&ice->reg_lock);
    47234470        init_MUTEX(&ice->gpio_mutex);
     
    47264473                                         0x10 | /* no emphasis */
    47274474                                         0x20); /* PCM encoder/decoder */
    4728         ice->cs8427_spdif_status[0] = (SNDRV_PCM_DEFAULT_CON_SPDIF >> 0) & 0xff;
    4729         ice->cs8427_spdif_status[1] = (SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff;
    4730         ice->cs8427_spdif_status[2] = (SNDRV_PCM_DEFAULT_CON_SPDIF >> 16) & 0xff;
    4731         ice->cs8427_spdif_status[3] = (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff;
    4732         memcpy(ice->cs8427_spdif_stream_status, ice->cs8427_spdif_status, 5);
    47334475        ice->card = card;
    47344476        ice->pci = pci;
     
    47954537}
    47964538
    4797 static int __init snd_ice1712_probe(struct pci_dev *pci,
     4539static int __devinit snd_ice1712_probe(struct pci_dev *pci,
    47984540                                    const struct pci_device_id *id)
    47994541{
     
    48034545        int pcm_dev = 0, err;
    48044546
    4805         for ( ; dev < SNDRV_CARDS; dev++) {
     4547        if (dev >= SNDRV_CARDS)
     4548                return -ENODEV;
    48064549                if (!snd_enable[dev]) {
    48074550                        dev++;
    48084551                        return -ENOENT;
    48094552                }
    4810                 break;
    4811         }
    4812         if (dev >= SNDRV_CARDS)
    4813                 return -ENODEV;
    48144553
    48154554        card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
     
    48174556                return -ENOMEM;
    48184557
    4819         if ((err = snd_ice1712_create(card, pci, &ice)) < 0) {
     4558        if ((err = snd_ice1712_create(card, pci, snd_omni[dev], &ice)) < 0) {
    48204559                snd_card_free(card);
    48214560                return err;
     
    48804619                strcpy(card->shortname, "TerraTec EWS 88D");
    48814620                break;
     4621        case ICE1712_SUBDEVICE_DMX6FIRE:
     4622                strcpy(card->shortname, "TerraTec DMX 6Fire");
     4623                break;
    48824624        }
    48834625
     
    49074649                return err;
    49084650        }
    4909         PCI_SET_DRIVER_DATA(pci, card);
     4651        pci_set_drvdata(pci, card);
    49104652        dev++;
    49114653        return 0;
    49124654}
    49134655
    4914 static void __exit snd_ice1712_remove(struct pci_dev *pci)
    4915 {
    4916         snd_card_free(PCI_GET_DRIVER_DATA(pci));
    4917         PCI_SET_DRIVER_DATA(pci, NULL);
     4656static void __devexit snd_ice1712_remove(struct pci_dev *pci)
     4657{
     4658        snd_card_free(pci_get_drvdata(pci));
     4659        pci_set_drvdata(pci, NULL);
    49184660}
    49194661
     
    49304672        id_table: snd_ice1712_ids,
    49314673        probe: snd_ice1712_probe,
    4932         remove: snd_ice1712_remove,
     4674        remove: __devexit_p(snd_ice1712_remove),
    49334675};
    49344676#endif
     
    49404682        if ((err = pci_module_init(&driver)) < 0) {
    49414683#ifdef MODULE
    4942                 snd_printk("ICE1712 soundcard not found or device busy\n");
     4684                printk(KERN_ERR "ICE1712 soundcard not found or device busy\n");
    49434685#endif
    49444686                return err;
     
    49574699#ifndef MODULE
    49584700
    4959 /* format is: snd-card-ice1712=snd_enable,snd_index,snd_id */
     4701/* format is: snd-ice1712=snd_enable,snd_index,snd_id */
    49604702
    49614703static int __init alsa_card_ice1712_setup(char *str)
     
    49724714}
    49734715
    4974 __setup("snd-card-ice1712=", alsa_card_ice1712_setup);
     4716__setup("snd-ice1712=", alsa_card_ice1712_setup);
    49754717
    49764718#endif /* ifndef MODULE */
Note: See TracChangeset for help on using the changeset viewer.