Changeset 604


Ignore:
Timestamp:
Jan 8, 2018, 2:07:36 AM (8 years ago)
Author:
David Azarewicz
Message:

Incorporated changes from Andy.
Added limited MSI support.

Location:
GPL/trunk
Files:
11 edited

Legend:

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

    r598 r604  
    433433
    434434        /* Do jiffies check only in xrun_debug mode */
    435 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
     435//#ifdef CONFIG_SND_PCM_XRUN_DEBUG
    436436        if (!xrun_debug(substream, XRUN_DEBUG_JIFFIESCHECK))
    437437                goto no_jiffies_check;
    438 #endif
     438//#endif
    439439        /* Skip the jiffies check for hardwares with BATCH flag.
    440440         * Such hardware usually just increases the position at each IRQ,
  • GPL/trunk/alsa-kernel/pci/hda/hda_intel.c

    r598 r604  
    2525 *  CONTACTS:
    2626 *
    27  *  Matt Jared          matt.jared@intel.com
    28  *  Andy Kopp           andy.kopp@intel.com
    29  *  Dan Kogan           dan.d.kogan@intel.com
     27 *  Matt Jared    matt.jared@intel.com
     28 *  Andy Kopp   andy.kopp@intel.com
     29 *  Dan Kogan   dan.d.kogan@intel.com
    3030 *
    3131 *  CHANGES:
    3232 *
    33  *  2004.12.01  Major rewrite by tiwai, merged the work of pshou
     33 *  2004.12.01  Major rewrite by tiwai, merged the work of pshou
    3434 *
    3535 */
     
    7272#ifdef CONFIG_SND_HDA_INPUT_BEEP
    7373static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] =
    74                                         CONFIG_SND_HDA_INPUT_BEEP_MODE};
     74          CONFIG_SND_HDA_INPUT_BEEP_MODE};
    7575#endif
    7676
     
    8585module_param_array(position_fix, int, NULL, 0444);
    8686MODULE_PARM_DESC(position_fix, "DMA pointer read method."
    87                 "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO).");
     87    "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO).");
    8888module_param_array(bdl_pos_adj, int, NULL, 0644);
    8989MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
     
    9494module_param(single_cmd, bool, 0444);
    9595MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
    96                 "(for debugging only).");
     96    "(for debugging only).");
    9797module_param(enable_msi, int, 0444);
    9898MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)");
     
    104104module_param_array(beep_mode, int, NULL, 0444);
    105105MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode "
    106                             "(0=off, 1=on, 2=mute switch on/off) (default=1).");
     106          "(0=off, 1=on, 2=mute switch on/off) (default=1).");
    107107#endif
    108108
     
    111111module_param(power_save, int, 0644);
    112112MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
    113                 "(in second, 0 = disable).");
     113    "(in second, 0 = disable).");
    114114
    115115/* reset the HD-audio controller in power save mode.
     
    124124MODULE_LICENSE("GPL");
    125125MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
    126                         "{Intel, ICH6M},"
    127                         "{Intel, ICH7},"
    128                         "{Intel, ESB2},"
    129                         "{Intel, ICH8},"
    130                         "{Intel, ICH9},"
    131                         "{Intel, ICH10},"
    132                         "{Intel, PCH},"
    133                         "{Intel, CPT},"
    134                         "{Intel, PBG},"
    135                         "{Intel, SCH},"
    136                         "{ATI, SB450},"
    137                         "{ATI, SB600},"
    138                         "{ATI, RS600},"
    139                         "{ATI, RS690},"
    140                         "{ATI, RS780},"
    141                         "{ATI, R600},"
    142                         "{ATI, RV630},"
    143                         "{ATI, RV610},"
    144                         "{ATI, RV670},"
    145                         "{ATI, RV635},"
    146                         "{ATI, RV620},"
    147                         "{ATI, RV770},"
    148                         "{VIA, VT8251},"
    149                         "{VIA, VT8237A},"
    150                         "{SiS, SIS966},"
    151                         "{ULI, M5461}}");
     126      "{Intel, ICH6M},"
     127      "{Intel, ICH7},"
     128      "{Intel, ESB2},"
     129      "{Intel, ICH8},"
     130      "{Intel, ICH9},"
     131      "{Intel, ICH10},"
     132      "{Intel, PCH},"
     133      "{Intel, CPT},"
     134      "{Intel, PBG},"
     135      "{Intel, SCH},"
     136      "{ATI, SB450},"
     137      "{ATI, SB600},"
     138      "{ATI, RS600},"
     139      "{ATI, RS690},"
     140      "{ATI, RS780},"
     141      "{ATI, R600},"
     142      "{ATI, RV630},"
     143      "{ATI, RV610},"
     144      "{ATI, RV670},"
     145      "{ATI, RV635},"
     146      "{ATI, RV620},"
     147      "{ATI, RV770},"
     148      "{VIA, VT8251},"
     149      "{VIA, VT8237A},"
     150      "{SiS, SIS966},"
     151      "{ULI, M5461}}");
    152152MODULE_DESCRIPTION("Intel HDA driver");
    153153
    154154#ifdef CONFIG_SND_VERBOSE_PRINTK
    155 #define SFX     /* nop */
     155#define SFX /* nop */
    156156#else
    157 #define SFX     "hda-intel: "
     157#define SFX "hda-intel: "
    158158#endif
    159159
     
    161161 * registers
    162162 */
    163 #define ICH6_REG_GCAP                   0x00
    164 #define   ICH6_GCAP_64OK        (1 << 0)   /* 64bit address support */
    165 #define   ICH6_GCAP_NSDO        (3 << 1)   /* # of serial data out signals */
    166 #define   ICH6_GCAP_BSS         (31 << 3)  /* # of bidirectional streams */
    167 #define   ICH6_GCAP_ISS         (15 << 8)  /* # of input streams */
    168 #define   ICH6_GCAP_OSS         (15 << 12) /* # of output streams */
    169 #define ICH6_REG_VMIN                   0x02
    170 #define ICH6_REG_VMAJ                   0x03
    171 #define ICH6_REG_OUTPAY                 0x04
    172 #define ICH6_REG_INPAY                  0x06
    173 #define ICH6_REG_GCTL                   0x08
    174 #define   ICH6_GCTL_RESET       (1 << 0)   /* controller reset */
    175 #define   ICH6_GCTL_FCNTRL      (1 << 1)   /* flush control */
    176 #define   ICH6_GCTL_UNSOL       (1 << 8)   /* accept unsol. response enable */
    177 #define ICH6_REG_WAKEEN                 0x0c
    178 #define ICH6_REG_STATESTS               0x0e
    179 #define ICH6_REG_GSTS                   0x10
    180 #define   ICH6_GSTS_FSTS        (1 << 1)   /* flush status */
    181 #define ICH6_REG_INTCTL                 0x20
    182 #define ICH6_REG_INTSTS                 0x24
    183 #define ICH6_REG_WALLCLK                0x30    /* 24Mhz source */
    184 #define ICH6_REG_SYNC                   0x34   
    185 #define ICH6_REG_CORBLBASE              0x40
    186 #define ICH6_REG_CORBUBASE              0x44
    187 #define ICH6_REG_CORBWP                 0x48
    188 #define ICH6_REG_CORBRP                 0x4a
    189 #define   ICH6_CORBRP_RST       (1 << 15)  /* read pointer reset */
    190 #define ICH6_REG_CORBCTL                0x4c
    191 #define   ICH6_CORBCTL_RUN      (1 << 1)   /* enable DMA */
    192 #define   ICH6_CORBCTL_CMEIE    (1 << 0)   /* enable memory error irq */
    193 #define ICH6_REG_CORBSTS                0x4d
    194 #define   ICH6_CORBSTS_CMEI     (1 << 0)   /* memory error indication */
    195 #define ICH6_REG_CORBSIZE               0x4e
    196 
    197 #define ICH6_REG_RIRBLBASE              0x50
    198 #define ICH6_REG_RIRBUBASE              0x54
    199 #define ICH6_REG_RIRBWP                 0x58
    200 #define   ICH6_RIRBWP_RST       (1 << 15)  /* write pointer reset */
    201 #define ICH6_REG_RINTCNT                0x5a
    202 #define ICH6_REG_RIRBCTL                0x5c
    203 #define   ICH6_RBCTL_IRQ_EN     (1 << 0)   /* enable IRQ */
    204 #define   ICH6_RBCTL_DMA_EN     (1 << 1)   /* enable DMA */
    205 #define   ICH6_RBCTL_OVERRUN_EN (1 << 2)   /* enable overrun irq */
    206 #define ICH6_REG_RIRBSTS                0x5d
    207 #define   ICH6_RBSTS_IRQ        (1 << 0)   /* response irq */
    208 #define   ICH6_RBSTS_OVERRUN    (1 << 2)   /* overrun irq */
    209 #define ICH6_REG_RIRBSIZE               0x5e
    210 
    211 #define ICH6_REG_IC                     0x60
    212 #define ICH6_REG_IR                     0x64
    213 #define ICH6_REG_IRS                    0x68
    214 #define   ICH6_IRS_VALID        (1<<1)
    215 #define   ICH6_IRS_BUSY         (1<<0)
    216 
    217 #define ICH6_REG_DPLBASE                0x70
    218 #define ICH6_REG_DPUBASE                0x74
    219 #define   ICH6_DPLBASE_ENABLE   0x1     /* Enable position buffer */
     163#define ICH6_REG_GCAP     0x00
     164#define   ICH6_GCAP_64OK  (1 << 0)   /* 64bit address support */
     165#define   ICH6_GCAP_NSDO  (3 << 1)   /* # of serial data out signals */
     166#define   ICH6_GCAP_BSS   (31 << 3)  /* # of bidirectional streams */
     167#define   ICH6_GCAP_ISS   (15 << 8)  /* # of input streams */
     168#define   ICH6_GCAP_OSS   (15 << 12) /* # of output streams */
     169#define ICH6_REG_VMIN     0x02
     170#define ICH6_REG_VMAJ     0x03
     171#define ICH6_REG_OUTPAY     0x04
     172#define ICH6_REG_INPAY      0x06
     173#define ICH6_REG_GCTL     0x08
     174#define   ICH6_GCTL_RESET (1 << 0)   /* controller reset */
     175#define   ICH6_GCTL_FCNTRL  (1 << 1)   /* flush control */
     176#define   ICH6_GCTL_UNSOL (1 << 8)   /* accept unsol. response enable */
     177#define ICH6_REG_WAKEEN     0x0c
     178#define ICH6_REG_STATESTS   0x0e
     179#define ICH6_REG_GSTS     0x10
     180#define   ICH6_GSTS_FSTS  (1 << 1)   /* flush status */
     181#define ICH6_REG_INTCTL     0x20
     182#define ICH6_REG_INTSTS     0x24
     183#define ICH6_REG_WALLCLK    0x30  /* 24Mhz source */
     184#define ICH6_REG_SYNC     0x34
     185#define ICH6_REG_CORBLBASE    0x40
     186#define ICH6_REG_CORBUBASE    0x44
     187#define ICH6_REG_CORBWP     0x48
     188#define ICH6_REG_CORBRP     0x4a
     189#define   ICH6_CORBRP_RST (1 << 15)  /* read pointer reset */
     190#define ICH6_REG_CORBCTL    0x4c
     191#define   ICH6_CORBCTL_RUN  (1 << 1)   /* enable DMA */
     192#define   ICH6_CORBCTL_CMEIE  (1 << 0)   /* enable memory error irq */
     193#define ICH6_REG_CORBSTS    0x4d
     194#define   ICH6_CORBSTS_CMEI (1 << 0)   /* memory error indication */
     195#define ICH6_REG_CORBSIZE   0x4e
     196
     197#define ICH6_REG_RIRBLBASE    0x50
     198#define ICH6_REG_RIRBUBASE    0x54
     199#define ICH6_REG_RIRBWP     0x58
     200#define   ICH6_RIRBWP_RST (1 << 15)  /* write pointer reset */
     201#define ICH6_REG_RINTCNT    0x5a
     202#define ICH6_REG_RIRBCTL    0x5c
     203#define   ICH6_RBCTL_IRQ_EN (1 << 0)   /* enable IRQ */
     204#define   ICH6_RBCTL_DMA_EN (1 << 1)   /* enable DMA */
     205#define   ICH6_RBCTL_OVERRUN_EN (1 << 2)   /* enable overrun irq */
     206#define ICH6_REG_RIRBSTS    0x5d
     207#define   ICH6_RBSTS_IRQ  (1 << 0)   /* response irq */
     208#define   ICH6_RBSTS_OVERRUN  (1 << 2)   /* overrun irq */
     209#define ICH6_REG_RIRBSIZE   0x5e
     210
     211#define ICH6_REG_IC     0x60
     212#define ICH6_REG_IR     0x64
     213#define ICH6_REG_IRS      0x68
     214#define   ICH6_IRS_VALID  (1<<1)
     215#define   ICH6_IRS_BUSY   (1<<0)
     216
     217#define ICH6_REG_DPLBASE    0x70
     218#define ICH6_REG_DPUBASE    0x74
     219#define   ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
    220220
    221221/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
     
    223223
    224224/* stream register offsets from stream base */
    225 #define ICH6_REG_SD_CTL                 0x00
    226 #define ICH6_REG_SD_STS                 0x03
    227 #define ICH6_REG_SD_LPIB                0x04
    228 #define ICH6_REG_SD_CBL                 0x08
    229 #define ICH6_REG_SD_LVI                 0x0c
    230 #define ICH6_REG_SD_FIFOW               0x0e
    231 #define ICH6_REG_SD_FIFOSIZE            0x10
    232 #define ICH6_REG_SD_FORMAT              0x12
    233 #define ICH6_REG_SD_BDLPL               0x18
    234 #define ICH6_REG_SD_BDLPU               0x1c
     225#define ICH6_REG_SD_CTL     0x00
     226#define ICH6_REG_SD_STS     0x03
     227#define ICH6_REG_SD_LPIB    0x04
     228#define ICH6_REG_SD_CBL     0x08
     229#define ICH6_REG_SD_LVI     0x0c
     230#define ICH6_REG_SD_FIFOW   0x0e
     231#define ICH6_REG_SD_FIFOSIZE    0x10
     232#define ICH6_REG_SD_FORMAT    0x12
     233#define ICH6_REG_SD_BDLPL   0x18
     234#define ICH6_REG_SD_BDLPU   0x1c
    235235
    236236/* PCI space */
    237 #define ICH6_PCIREG_TCSEL       0x44
     237#define ICH6_PCIREG_TCSEL 0x44
    238238
    239239/*
     
    243243/* max number of SDs */
    244244/* ICH, ATI and VIA have 4 playback and 4 capture */
    245 #define ICH6_NUM_CAPTURE        4
    246 #define ICH6_NUM_PLAYBACK       4
     245#define ICH6_NUM_CAPTURE  4
     246#define ICH6_NUM_PLAYBACK 4
    247247
    248248/* ULI has 6 playback and 5 capture */
    249 #define ULI_NUM_CAPTURE         5
    250 #define ULI_NUM_PLAYBACK        6
     249#define ULI_NUM_CAPTURE   5
     250#define ULI_NUM_PLAYBACK  6
    251251
    252252/* ATI HDMI has 1 playback and 0 capture */
    253 #define ATIHDMI_NUM_CAPTURE     0
    254 #define ATIHDMI_NUM_PLAYBACK    1
     253#define ATIHDMI_NUM_CAPTURE 0
     254#define ATIHDMI_NUM_PLAYBACK  1
    255255
    256256/* TERA has 4 playback and 3 capture */
    257 #define TERA_NUM_CAPTURE        3
    258 #define TERA_NUM_PLAYBACK       4
     257#define TERA_NUM_CAPTURE  3
     258#define TERA_NUM_PLAYBACK 4
    259259
    260260/* this number is statically defined for simplicity */
    261 #define MAX_AZX_DEV             16
     261#define MAX_AZX_DEV   16
    262262
    263263/* max number of fragments - we may use more if allocating more pages for BDL */
    264 #define BDL_SIZE                4096
    265 #define AZX_MAX_BDL_ENTRIES     (BDL_SIZE / 16)
    266 #define AZX_MAX_FRAG            32
     264#define BDL_SIZE    4096
     265#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
     266#define AZX_MAX_FRAG    32
    267267/* max buffer size - no h/w limit, you can increase as you like */
    268 #define AZX_MAX_BUF_SIZE        (1024*1024*1024)
     268#define AZX_MAX_BUF_SIZE  (1024*1024*1024)
    269269
    270270/* RIRB int mask: overrun[2], response[0] */
    271 #define RIRB_INT_RESPONSE       0x01
    272 #define RIRB_INT_OVERRUN        0x04
    273 #define RIRB_INT_MASK           0x05
     271#define RIRB_INT_RESPONSE 0x01
     272#define RIRB_INT_OVERRUN  0x04
     273#define RIRB_INT_MASK   0x05
    274274
    275275/* STATESTS int mask: S3,SD2,SD1,SD0 */
    276 #define AZX_MAX_CODECS          8
    277 #define AZX_DEFAULT_CODECS      4
    278 #define STATESTS_INT_MASK       ((1 << AZX_MAX_CODECS) - 1)
     276#define AZX_MAX_CODECS    8
     277#define AZX_DEFAULT_CODECS  4
     278#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
    279279
    280280/* SD_CTL bits */
    281 #define SD_CTL_STREAM_RESET     0x01    /* stream reset bit */
    282 #define SD_CTL_DMA_START        0x02    /* stream DMA start bit */
    283 #define SD_CTL_STRIPE           (3 << 16)       /* stripe control */
    284 #define SD_CTL_TRAFFIC_PRIO     (1 << 18)       /* traffic priority */
    285 #define SD_CTL_DIR              (1 << 19)       /* bi-directional stream */
    286 #define SD_CTL_STREAM_TAG_MASK  (0xf << 20)
    287 #define SD_CTL_STREAM_TAG_SHIFT 20
     281#define SD_CTL_STREAM_RESET 0x01  /* stream reset bit */
     282#define SD_CTL_DMA_START  0x02  /* stream DMA start bit */
     283#define SD_CTL_STRIPE   (3 << 16) /* stripe control */
     284#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
     285#define SD_CTL_DIR    (1 << 19) /* bi-directional stream */
     286#define SD_CTL_STREAM_TAG_MASK  (0xf << 20)
     287#define SD_CTL_STREAM_TAG_SHIFT 20
    288288
    289289/* SD_CTL and SD_STS */
    290 #define SD_INT_DESC_ERR         0x10    /* descriptor error interrupt */
    291 #define SD_INT_FIFO_ERR         0x08    /* FIFO error interrupt */
    292 #define SD_INT_COMPLETE         0x04    /* completion interrupt */
    293 #define SD_INT_MASK             (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
    294                                 SD_INT_COMPLETE)
     290#define SD_INT_DESC_ERR   0x10  /* descriptor error interrupt */
     291#define SD_INT_FIFO_ERR   0x08  /* FIFO error interrupt */
     292#define SD_INT_COMPLETE   0x04  /* completion interrupt */
     293#define SD_INT_MASK   (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
     294        SD_INT_COMPLETE)
    295295
    296296/* SD_STS */
    297 #define SD_STS_FIFO_READY       0x20    /* FIFO ready */
     297#define SD_STS_FIFO_READY 0x20  /* FIFO ready */
    298298
    299299/* INTCTL and INTSTS */
    300 #define ICH6_INT_ALL_STREAM     0xff       /* all stream interrupts */
    301 #define ICH6_INT_CTRL_EN        0x40000000 /* controller interrupt enable bit */
    302 #define ICH6_INT_GLOBAL_EN      0x80000000 /* global interrupt enable bit */
     300#define ICH6_INT_ALL_STREAM 0xff     /* all stream interrupts */
     301#define ICH6_INT_CTRL_EN  0x40000000 /* controller interrupt enable bit */
     302#define ICH6_INT_GLOBAL_EN  0x80000000 /* global interrupt enable bit */
    303303
    304304/* below are so far hardcoded - should read registers in future */
    305 #define ICH6_MAX_CORB_ENTRIES   256
    306 #define ICH6_MAX_RIRB_ENTRIES   256
     305#define ICH6_MAX_CORB_ENTRIES 256
     306#define ICH6_MAX_RIRB_ENTRIES 256
    307307
    308308/* position fix mode */
    309309enum {
    310         POS_FIX_AUTO,
    311         POS_FIX_LPIB,
    312         POS_FIX_POSBUF,
    313         POS_FIX_VIACOMBO,
     310  POS_FIX_AUTO,
     311  POS_FIX_LPIB,
     312  POS_FIX_POSBUF,
     313  POS_FIX_VIACOMBO,
    314314};
    315315
     
    330330
    331331/* Define IN stream 0 FIFO size offset in VIA controller */
    332 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
     332#define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
    333333/* Define VIA HD Audio Device ID*/
    334 #define VIA_HDAC_DEVICE_ID              0x3288
     334#define VIA_HDAC_DEVICE_ID    0x3288
    335335
    336336/* HD Audio class code */
    337 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO   0x0403
     337#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
    338338
    339339/*
     
    341341
    342342struct azx_dev {
    343         struct snd_dma_buffer bdl; /* BDL buffer */
     343  struct snd_dma_buffer bdl; /* BDL buffer */
    344344#ifdef TARGET_OS2
    345         volatile u32 *posbuf;           /* position buffer pointer */
     345  volatile u32 *posbuf;   /* position buffer pointer */
    346346#else
    347         u32 *posbuf;            /* position buffer pointer */
     347  u32 *posbuf;    /* position buffer pointer */
    348348#endif
    349349
    350         unsigned int bufsize;   /* size of the play buffer in bytes */
    351         unsigned int period_bytes; /* size of the period in bytes */
    352         unsigned int frags;     /* number for period in the play buffer */
    353         unsigned int fifo_size; /* FIFO size */
    354         unsigned long start_wallclk;    /* start + minimum wallclk */
    355         unsigned long period_wallclk;   /* wallclk for period */
     350  unsigned int bufsize; /* size of the play buffer in bytes */
     351  unsigned int period_bytes; /* size of the period in bytes */
     352  unsigned int frags; /* number for period in the play buffer */
     353  unsigned int fifo_size; /* FIFO size */
     354  unsigned long start_wallclk;  /* start + minimum wallclk */
     355  unsigned long period_wallclk; /* wallclk for period */
    356356
    357357#ifdef TARGET_OS2
    358         volatile void __iomem *sd_addr;         /* stream descriptor pointer */
     358  volatile void __iomem *sd_addr;   /* stream descriptor pointer */
    359359#else
    360         void __iomem *sd_addr;  /* stream descriptor pointer */
     360  void __iomem *sd_addr;  /* stream descriptor pointer */
    361361#endif
    362362
    363         u32 sd_int_sta_mask;    /* stream int status mask */
    364 
    365         /* pcm support */
    366         struct snd_pcm_substream *substream;    /* assigned substream,
    367                                                 * set in PCM open
    368                                                 */
    369         unsigned int format_val;        /* format value to be set in the
    370                                         * controller and the codec
    371                                         */
    372         unsigned char stream_tag;       /* assigned stream */
    373         unsigned char index;            /* stream index */
    374         int device;                     /* last device number assigned to */
    375 
    376         unsigned int opened :1;
    377         unsigned int running :1;
    378         unsigned int irq_pending :1;
    379         /*
    380         * For VIA:
    381         *  A flag to ensure DMA position is 0
    382         *  when link position is not greater than FIFO size
    383         */
    384         unsigned int insufficient :1;
     363  u32 sd_int_sta_mask;  /* stream int status mask */
     364
     365  /* pcm support */
     366  struct snd_pcm_substream *substream;  /* assigned substream,
     367            * set in PCM open
     368            */
     369  unsigned int format_val;  /* format value to be set in the
     370          * controller and the codec
     371          */
     372  unsigned char stream_tag; /* assigned stream */
     373  unsigned char index;    /* stream index */
     374  int device;     /* last device number assigned to */
     375
     376  unsigned int opened :1;
     377  unsigned int running :1;
     378  unsigned int irq_pending :1;
     379  /*
     380  * For VIA:
     381  *  A flag to ensure DMA position is 0
     382  *  when link position is not greater than FIFO size
     383  */
     384  unsigned int insufficient :1;
    385385};
    386386
     
    388388struct azx_rb {
    389389#ifdef TARGET_OS2
    390         volatile u32 *buf;              /* CORB/RIRB buffer */
     390  volatile u32 *buf;    /* CORB/RIRB buffer */
    391391#else
    392         u32 *buf;               /* CORB/RIRB buffer */
     392  u32 *buf;   /* CORB/RIRB buffer */
    393393#endif
    394                                 /* Each CORB entry is 4byte, RIRB is 8byte
    395                                 */
    396         dma_addr_t addr;        /* physical address of CORB/RIRB buffer */
    397         /* for RIRB */
    398         unsigned short rp, wp;  /* read/write pointers */
    399         int cmds[AZX_MAX_CODECS];       /* number of pending requests */
    400         u32 res[AZX_MAX_CODECS];        /* last read value */
     394        /* Each CORB entry is 4byte, RIRB is 8byte
     395        */
     396  dma_addr_t addr;  /* physical address of CORB/RIRB buffer */
     397  /* for RIRB */
     398  unsigned short rp, wp;  /* read/write pointers */
     399  int cmds[AZX_MAX_CODECS]; /* number of pending requests */
     400  u32 res[AZX_MAX_CODECS];  /* last read value */
    401401};
    402402
    403403struct azx {
    404         struct snd_card *card;
    405         struct pci_dev *pci;
    406         int dev_index;
    407 
    408         /* chip type specific */
    409         int driver_type;
    410         int playback_streams;
    411         int playback_index_offset;
    412         int capture_streams;
    413         int capture_index_offset;
    414         int num_streams;
    415 
    416         /* pci resources */
    417         unsigned long addr;
     404  struct snd_card *card;
     405  struct pci_dev *pci;
     406  int dev_index;
     407
     408  /* chip type specific */
     409  int driver_type;
     410  int playback_streams;
     411  int playback_index_offset;
     412  int capture_streams;
     413  int capture_index_offset;
     414  int num_streams;
     415
     416  /* pci resources */
     417  unsigned long addr;
    418418#ifdef TARGET_OS2
    419         volatile void __iomem *remap_addr;
     419  volatile void __iomem *remap_addr;
    420420#else /* !TARGET_OS2 */
    421         void __iomem *remap_addr;
     421  void __iomem *remap_addr;
    422422#endif /* !TARGET_OS2 */
    423         int irq;
    424 
    425         /* locks */
    426         spinlock_t reg_lock;
    427         struct mutex open_mutex;
    428 
    429         /* streams (x num_streams) */
    430         struct azx_dev *azx_dev;
    431 
    432         /* PCM */
    433         struct snd_pcm *pcm[HDA_MAX_PCMS];
    434 
    435         /* HD codec */
    436         unsigned short codec_mask;
    437         int  codec_probe_mask; /* copied from probe_mask option */
    438         struct hda_bus *bus;
    439         unsigned int beep_mode;
    440 
    441         /* CORB/RIRB */
    442         struct azx_rb corb;
    443         struct azx_rb rirb;
    444 
    445         /* CORB/RIRB and position buffers */
    446         struct snd_dma_buffer rb;
    447         struct snd_dma_buffer posbuf;
    448 
    449         /* flags */
    450         int position_fix[2]; /* for both playback/capture streams */
    451         int poll_count;
    452         unsigned int running :1;
    453         unsigned int initialized :1;
    454         unsigned int single_cmd :1;
    455         unsigned int polling_mode :1;
    456         unsigned int msi :1;
    457         unsigned int irq_pending_warned :1;
    458         unsigned int probing :1; /* codec probing phase */
    459 
    460         /* for debugging */
    461         unsigned int last_cmd[AZX_MAX_CODECS];
    462 
    463         /* for pending irqs */
    464         struct work_struct irq_pending_work;
    465 
    466         /* reboot notifier (for mysterious hangup problem at power-down) */
    467         struct notifier_block reboot_notifier;
     423  int irq;
     424
     425  /* locks */
     426  spinlock_t reg_lock;
     427  struct mutex open_mutex;
     428
     429  /* streams (x num_streams) */
     430  struct azx_dev *azx_dev;
     431
     432  /* PCM */
     433  struct snd_pcm *pcm[HDA_MAX_PCMS];
     434
     435  /* HD codec */
     436  unsigned short codec_mask;
     437  int  codec_probe_mask; /* copied from probe_mask option */
     438  struct hda_bus *bus;
     439  unsigned int beep_mode;
     440
     441  /* CORB/RIRB */
     442  struct azx_rb corb;
     443  struct azx_rb rirb;
     444
     445  /* CORB/RIRB and position buffers */
     446  struct snd_dma_buffer rb;
     447  struct snd_dma_buffer posbuf;
     448
     449  /* flags */
     450  int position_fix[2]; /* for both playback/capture streams */
     451  int poll_count;
     452  unsigned int running :1;
     453  unsigned int initialized :1;
     454  unsigned int single_cmd :1;
     455  unsigned int polling_mode :1;
     456  unsigned int msi :1;
     457  unsigned int irq_pending_warned :1;
     458  unsigned int probing :1; /* codec probing phase */
     459
     460  /* for debugging */
     461  unsigned int last_cmd[AZX_MAX_CODECS];
     462
     463  /* for pending irqs */
     464  struct work_struct irq_pending_work;
     465
     466  /* reboot notifier (for mysterious hangup problem at power-down) */
     467  struct notifier_block reboot_notifier;
    468468};
    469469
    470470/* driver types */
    471471enum {
    472         AZX_DRIVER_ICH,
    473         AZX_DRIVER_PCH,
    474         AZX_DRIVER_SCH,
    475         AZX_DRIVER_ATI,
    476         AZX_DRIVER_ATIHDMI,
    477         AZX_DRIVER_VIA,
    478         AZX_DRIVER_SIS,
    479         AZX_DRIVER_ULI,
    480         AZX_DRIVER_NVIDIA,
    481         AZX_DRIVER_TERA,
    482         AZX_DRIVER_CTX,
    483         AZX_DRIVER_GENERIC,
    484         AZX_NUM_DRIVERS, /* keep this as last entry */
     472  AZX_DRIVER_ICH,
     473  AZX_DRIVER_PCH,
     474  AZX_DRIVER_SCH,
     475  AZX_DRIVER_HDMI,
     476  AZX_DRIVER_ATI,
     477  AZX_DRIVER_ATIHDMI,
     478  AZX_DRIVER_VIA,
     479  AZX_DRIVER_SIS,
     480  AZX_DRIVER_ULI,
     481  AZX_DRIVER_NVIDIA,
     482  AZX_DRIVER_TERA,
     483  AZX_DRIVER_CTX,
     484  AZX_DRIVER_GENERIC,
     485  AZX_NUM_DRIVERS, /* keep this as last entry */
    485486};
    486487
    487488static char *driver_short_names[] __devinitdata = {
    488         [AZX_DRIVER_ICH] = "HDA Intel",
    489         [AZX_DRIVER_PCH] = "HDA Intel PCH",
    490         [AZX_DRIVER_SCH] = "HDA Intel MID",
    491         [AZX_DRIVER_ATI] = "HDA ATI SB",
    492         [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
    493         [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
    494         [AZX_DRIVER_SIS] = "HDA SIS966",
    495         [AZX_DRIVER_ULI] = "HDA ULI M5461",
    496         [AZX_DRIVER_NVIDIA] = "HDA NVidia",
    497         [AZX_DRIVER_TERA] = "HDA Teradici",
    498         [AZX_DRIVER_CTX] = "HDA Creative",
    499         [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
     489  [AZX_DRIVER_ICH] = "HDA Intel",
     490  [AZX_DRIVER_PCH] = "HDA Intel PCH",
     491  [AZX_DRIVER_SCH] = "HDA Intel MID",
     492  [AZX_DRIVER_HDMI] = "HDA Intel HDMI",
     493  [AZX_DRIVER_ATI] = "HDA ATI SB",
     494  [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI",
     495  [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
     496  [AZX_DRIVER_SIS] = "HDA SIS966",
     497  [AZX_DRIVER_ULI] = "HDA ULI M5461",
     498  [AZX_DRIVER_NVIDIA] = "HDA NVidia",
     499  [AZX_DRIVER_TERA] = "HDA Teradici",
     500  [AZX_DRIVER_CTX] = "HDA Creative",
     501  [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
    500502};
    501503
     
    504506 */
    505507#define azx_writel(chip,reg,value) \
    506         writel(value, (chip)->remap_addr + ICH6_REG_##reg)
     508  writel(value, (chip)->remap_addr + ICH6_REG_##reg)
    507509#define azx_readl(chip,reg) \
    508         readl((chip)->remap_addr + ICH6_REG_##reg)
     510  readl((chip)->remap_addr + ICH6_REG_##reg)
    509511#define azx_writew(chip,reg,value) \
    510         writew(value, (chip)->remap_addr + ICH6_REG_##reg)
     512  writew(value, (chip)->remap_addr + ICH6_REG_##reg)
    511513#define azx_readw(chip,reg) \
    512         readw((chip)->remap_addr + ICH6_REG_##reg)
     514  readw((chip)->remap_addr + ICH6_REG_##reg)
    513515#define azx_writeb(chip,reg,value) \
    514         writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
     516  writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
    515517#define azx_readb(chip,reg) \
    516         readb((chip)->remap_addr + ICH6_REG_##reg)
     518  readb((chip)->remap_addr + ICH6_REG_##reg)
    517519
    518520#define azx_sd_writel(dev,reg,value) \
    519         writel(value, (dev)->sd_addr + ICH6_REG_##reg)
     521  writel(value, (dev)->sd_addr + ICH6_REG_##reg)
    520522#define azx_sd_readl(dev,reg) \
    521         readl((dev)->sd_addr + ICH6_REG_##reg)
     523  readl((dev)->sd_addr + ICH6_REG_##reg)
    522524#define azx_sd_writew(dev,reg,value) \
    523         writew(value, (dev)->sd_addr + ICH6_REG_##reg)
     525  writew(value, (dev)->sd_addr + ICH6_REG_##reg)
    524526#define azx_sd_readw(dev,reg) \
    525         readw((dev)->sd_addr + ICH6_REG_##reg)
     527  readw((dev)->sd_addr + ICH6_REG_##reg)
    526528#define azx_sd_writeb(dev,reg,value) \
    527         writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
     529  writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
    528530#define azx_sd_readb(dev,reg) \
    529         readb((dev)->sd_addr + ICH6_REG_##reg)
     531  readb((dev)->sd_addr + ICH6_REG_##reg)
    530532
    531533/* for pcm support */
     
    543545static int azx_alloc_cmd_io(struct azx *chip)
    544546{
    545         int err;
    546 
    547         /* single page (at least 4096 bytes) must suffice for both ringbuffes */
    548         err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
    549                                   snd_dma_pci_data(chip->pci),
    550                                   PAGE_SIZE, &chip->rb);
    551         if (err < 0) {
    552                 snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
    553                 return err;
    554         }
    555         return 0;
     547  int err;
     548
     549  /* single page (at least 4096 bytes) must suffice for both ringbuffes */
     550  err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
     551          snd_dma_pci_data(chip->pci),
     552          PAGE_SIZE, &chip->rb);
     553  if (err < 0) {
     554    snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
     555    return err;
     556  }
     557  return 0;
    556558}
    557559
    558560static void azx_init_cmd_io(struct azx *chip)
    559561{
    560         spin_lock_irq(&chip->reg_lock);
    561         /* CORB set up */
    562         chip->corb.addr = chip->rb.addr;
    563         chip->corb.buf = (u32 *)chip->rb.area;
    564         azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
    565         azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
    566 
    567         /* set the corb size to 256 entries (ULI requires explicitly) */
    568         azx_writeb(chip, CORBSIZE, 0x02);
    569         /* set the corb write pointer to 0 */
    570         azx_writew(chip, CORBWP, 0);
    571         /* reset the corb hw read pointer */
    572         azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
    573         /* enable corb dma */
    574         azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
    575 
    576         /* RIRB set up */
    577         chip->rirb.addr = chip->rb.addr + 2048;
    578         chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
    579         chip->rirb.wp = chip->rirb.rp = 0;
    580         memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
    581         azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
    582         azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
    583 
    584         /* set the rirb size to 256 entries (ULI requires explicitly) */
    585         azx_writeb(chip, RIRBSIZE, 0x02);
    586         /* reset the rirb hw write pointer */
    587         azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
    588         /* set N=1, get RIRB response interrupt for new entry */
    589         if (chip->driver_type == AZX_DRIVER_CTX)
    590                 azx_writew(chip, RINTCNT, 0xc0);
    591         else
    592                 azx_writew(chip, RINTCNT, 1);
    593         /* enable rirb dma and response irq */
    594         azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
    595         spin_unlock_irq(&chip->reg_lock);
     562  spin_lock_irq(&chip->reg_lock);
     563  /* CORB set up */
     564  chip->corb.addr = chip->rb.addr;
     565  chip->corb.buf = (u32 *)chip->rb.area;
     566  azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
     567  azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
     568
     569  /* set the corb size to 256 entries (ULI requires explicitly) */
     570  azx_writeb(chip, CORBSIZE, 0x02);
     571  /* set the corb write pointer to 0 */
     572  azx_writew(chip, CORBWP, 0);
     573  /* reset the corb hw read pointer */
     574  azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
     575  /* enable corb dma */
     576  azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
     577
     578  /* RIRB set up */
     579  chip->rirb.addr = chip->rb.addr + 2048;
     580  chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
     581  chip->rirb.wp = chip->rirb.rp = 0;
     582  memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
     583  azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
     584  azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
     585
     586  /* set the rirb size to 256 entries (ULI requires explicitly) */
     587  azx_writeb(chip, RIRBSIZE, 0x02);
     588  /* reset the rirb hw write pointer */
     589  azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
     590  /* set N=1, get RIRB response interrupt for new entry */
     591  if (chip->driver_type == AZX_DRIVER_CTX)
     592    azx_writew(chip, RINTCNT, 0xc0);
     593  else
     594    azx_writew(chip, RINTCNT, 1);
     595  /* enable rirb dma and response irq */
     596  azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
     597  spin_unlock_irq(&chip->reg_lock);
    596598}
    597599
    598600static void azx_free_cmd_io(struct azx *chip)
    599601{
    600         spin_lock_irq(&chip->reg_lock);
    601         /* disable ringbuffer DMAs */
    602         azx_writeb(chip, RIRBCTL, 0);
    603         azx_writeb(chip, CORBCTL, 0);
    604         spin_unlock_irq(&chip->reg_lock);
     602  spin_lock_irq(&chip->reg_lock);
     603  /* disable ringbuffer DMAs */
     604  azx_writeb(chip, RIRBCTL, 0);
     605  azx_writeb(chip, CORBCTL, 0);
     606  spin_unlock_irq(&chip->reg_lock);
    605607}
    606608
    607609static unsigned int azx_command_addr(u32 cmd)
    608610{
    609         unsigned int addr = cmd >> 28;
    610 
    611         if (addr >= AZX_MAX_CODECS) {
    612                 snd_BUG();
    613                 addr = 0;
    614         }
    615 
    616         return addr;
     611  unsigned int addr = cmd >> 28;
     612
     613  if (addr >= AZX_MAX_CODECS) {
     614    snd_BUG();
     615    addr = 0;
     616  }
     617
     618  return addr;
    617619}
    618620
    619621static unsigned int azx_response_addr(u32 res)
    620622{
    621         unsigned int addr = res & 0xf;
    622 
    623         if (addr >= AZX_MAX_CODECS) {
    624                 snd_BUG();
    625                 addr = 0;
    626         }
    627 
    628         return addr;
     623  unsigned int addr = res & 0xf;
     624
     625  if (addr >= AZX_MAX_CODECS) {
     626    snd_BUG();
     627    addr = 0;
     628  }
     629
     630  return addr;
    629631}
    630632
     
    632634static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
    633635{
    634         struct azx *chip = bus->private_data;
    635         unsigned int addr = azx_command_addr(val);
    636         unsigned int wp;
    637 
    638         spin_lock_irq(&chip->reg_lock);
    639 
    640         /* add command to corb */
    641         wp = azx_readb(chip, CORBWP);
    642         wp++;
    643         wp %= ICH6_MAX_CORB_ENTRIES;
    644 
    645         chip->rirb.cmds[addr]++;
    646         chip->corb.buf[wp] = cpu_to_le32(val);
    647         azx_writel(chip, CORBWP, wp);
    648 
    649         spin_unlock_irq(&chip->reg_lock);
    650 
    651         return 0;
    652 }
    653 
    654 #define ICH6_RIRB_EX_UNSOL_EV   (1<<4)
     636  struct azx *chip = bus->private_data;
     637  unsigned int addr = azx_command_addr(val);
     638  unsigned int wp;
     639
     640  spin_lock_irq(&chip->reg_lock);
     641
     642  /* add command to corb */
     643  wp = azx_readb(chip, CORBWP);
     644  wp++;
     645  wp %= ICH6_MAX_CORB_ENTRIES;
     646
     647  chip->rirb.cmds[addr]++;
     648  chip->corb.buf[wp] = cpu_to_le32(val);
     649  azx_writel(chip, CORBWP, wp);
     650
     651  spin_unlock_irq(&chip->reg_lock);
     652
     653  return 0;
     654}
     655
     656#define ICH6_RIRB_EX_UNSOL_EV (1<<4)
    655657
    656658/* retrieve RIRB entry - called from interrupt handler */
    657659static void azx_update_rirb(struct azx *chip)
    658660{
    659         unsigned int rp, wp;
    660         unsigned int addr;
    661         u32 res, res_ex;
    662 
    663         wp = azx_readb(chip, RIRBWP);
    664         if (wp == chip->rirb.wp)
    665                 return;
    666         chip->rirb.wp = wp;
    667 
    668         while (chip->rirb.rp != wp) {
    669                 chip->rirb.rp++;
    670                 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
    671 
    672                 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
    673                 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
    674                 res = le32_to_cpu(chip->rirb.buf[rp]);
    675                 addr = azx_response_addr(res_ex);
    676                 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
    677                         snd_hda_queue_unsol_event(chip->bus, res, res_ex);
    678                 else if (chip->rirb.cmds[addr]) {
    679                         chip->rirb.res[addr] = res;
    680                         smp_wmb();
    681                         chip->rirb.cmds[addr]--;
    682                 } else
    683                         snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "
    684                                    "last cmd=%#08x\n",
    685                                    res, res_ex,
    686                                    chip->last_cmd[addr]);
    687         }
     661  unsigned int rp, wp;
     662  unsigned int addr;
     663  u32 res, res_ex;
     664
     665  wp = azx_readb(chip, RIRBWP);
     666  if (wp == chip->rirb.wp)
     667    return;
     668  chip->rirb.wp = wp;
     669
     670  while (chip->rirb.rp != wp) {
     671    chip->rirb.rp++;
     672    chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
     673
     674    rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
     675    res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
     676    res = le32_to_cpu(chip->rirb.buf[rp]);
     677    addr = azx_response_addr(res_ex);
     678    if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
     679      snd_hda_queue_unsol_event(chip->bus, res, res_ex);
     680    else if (chip->rirb.cmds[addr]) {
     681      chip->rirb.res[addr] = res;
     682      smp_wmb();
     683      chip->rirb.cmds[addr]--;
     684    } else
     685      snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "
     686           "last cmd=%#08x\n",
     687           res, res_ex,
     688           chip->last_cmd[addr]);
     689  }
    688690}
    689691
    690692/* receive a response */
    691693static unsigned int azx_rirb_get_response(struct hda_bus *bus,
    692                                           unsigned int addr)
    693 {
    694         struct azx *chip = bus->private_data;
    695         unsigned long timeout;
     694            unsigned int addr)
     695{
     696  struct azx *chip = bus->private_data;
     697  unsigned long timeout;
    696698#ifdef TARGET_OS2
    697         int count = 0;
     699  int count = 0;
    698700#endif
    699         int do_poll = 0;
     701  int do_poll = 0;
    700702
    701703 again:
    702         timeout = jiffies + msecs_to_jiffies(1000);
    703         for ( ; ; ) {
    704                 if (chip->polling_mode || do_poll) {
    705                         spin_lock_irq(&chip->reg_lock);
    706                         azx_update_rirb(chip);
    707                         spin_unlock_irq(&chip->reg_lock);
    708                 }
    709                 if (!chip->rirb.cmds[addr]) {
    710                         smp_rmb();
    711                         bus->rirb_error = 0;
    712 
    713                         if (!do_poll)
    714                                 chip->poll_count = 0;
    715                         return chip->rirb.res[addr]; /* the last value */
    716                 }
    717                 if (time_after(jiffies, timeout))
    718                         break;
     704  timeout = jiffies + msecs_to_jiffies(1000);
     705  for ( ; ; ) {
     706    if (chip->polling_mode || do_poll) {
     707      spin_lock_irq(&chip->reg_lock);
     708      azx_update_rirb(chip);
     709      spin_unlock_irq(&chip->reg_lock);
     710    }
     711    if (!chip->rirb.cmds[addr]) {
     712      smp_rmb();
     713      bus->rirb_error = 0;
     714
     715      if (!do_poll)
     716        chip->poll_count = 0;
     717      return chip->rirb.res[addr]; /* the last value */
     718    }
     719    if (time_after(jiffies, timeout))
     720      break;
    719721#ifdef TARGET_OS2
    720                 if (count >= 5000) /* Hack on OS/2 to stop infinite loop as jiffies sometimes don't increment */
    721                         break;
     722    if (count >= 5000) /* Hack on OS/2 to stop infinite loop as jiffies sometimes don't increment */
     723      break;
    722724#endif
    723                 if (bus->needs_damn_long_delay)
    724                         msleep(2); /* temporary workaround */
    725                 else {
    726                         udelay(10);
    727                         cond_resched();
    728                 }
     725    if (bus->needs_damn_long_delay)
     726      msleep(2); /* temporary workaround */
     727    else {
     728      udelay(10);
     729      cond_resched();
     730    }
    729731#ifdef TARGET_OS2
    730         count++;
     732  count++;
    731733#endif
    732         }
    733 
    734         if (!chip->polling_mode && chip->poll_count < 2) {
    735                 snd_printdd(SFX "azx_get_response timeout, "
    736                            "polling the codec once: last cmd=0x%08x\n",
    737                            chip->last_cmd[addr]);
    738                 do_poll = 1;
    739                 chip->poll_count++;
    740                 goto again;
    741         }
    742 
    743 
    744         if (!chip->polling_mode) {
    745                 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
    746                            "switching to polling mode: last cmd=0x%08x\n",
    747                            chip->last_cmd[addr]);
    748                 chip->polling_mode = 1;
    749                 goto again;
    750         }
     734  }
     735
     736  if (!chip->polling_mode && chip->poll_count < 2) {
     737    snd_printdd(SFX "azx_get_response timeout, "
     738         "polling the codec once: last cmd=0x%08x\n",
     739         chip->last_cmd[addr]);
     740    do_poll = 1;
     741    chip->poll_count++;
     742    goto again;
     743  }
     744
     745
     746  if (!chip->polling_mode) {
     747    snd_printk(KERN_WARNING SFX "azx_get_response timeout, "
     748         "switching to polling mode: last cmd=0x%08x\n",
     749         chip->last_cmd[addr]);
     750    chip->polling_mode = 1;
     751    goto again;
     752  }
    751753#ifdef TARGET_OS2
    752         if (count >= 5000) {
    753                 snd_printk(KERN_WARNING "hda_intel: count >= 5000, aborting loop in azx_rirb_get_response\n");
    754         }
     754  if (count >= 5000) {
     755    snd_printk(KERN_WARNING "hda_intel: count >= 5000, aborting loop in azx_rirb_get_response\n");
     756  }
    755757#endif
    756         if (chip->msi) {
    757                 snd_printk(KERN_WARNING SFX "No response from codec, "
    758                            "disabling MSI: last cmd=0x%08x\n",
    759                            chip->last_cmd[addr]);
    760                 free_irq(chip->irq, chip);
    761                 chip->irq = -1;
    762                 pci_disable_msi(chip->pci);
    763                 chip->msi = 0;
    764                 if (azx_acquire_irq(chip, 1) < 0) {
    765                         bus->rirb_error = 1;
    766                         return -1;
    767                 }
    768                 goto again;
    769         }
    770 
    771         if (chip->probing) {
    772                 /* If this critical timeout happens during the codec probing
    773                 * phase, this is likely an access to a non-existing codec
    774                 * slot.  Better to return an error and reset the system.
    775                 */
    776                 return -1;
    777         }
    778 
    779         /* a fatal communication error; need either to reset or to fallback
    780         * to the single_cmd mode
    781         */
    782         bus->rirb_error = 1;
    783         if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
    784                 bus->response_reset = 1;
    785                 return -1; /* give a chance to retry */
    786         }
    787 
    788         snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
    789                    "switching to single_cmd mode: last cmd=0x%08x\n",
    790                    chip->last_cmd[addr]);
    791         chip->single_cmd = 1;
    792         bus->response_reset = 0;
    793         /* release CORB/RIRB */
    794         azx_free_cmd_io(chip);
    795         /* disable unsolicited responses */
    796         azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
    797         return -1;
     758  if (chip->msi) {
     759    snd_printk(KERN_WARNING SFX "No response from codec, "
     760         "disabling MSI: last cmd=0x%08x\n",
     761         chip->last_cmd[addr]);
     762    free_irq(chip->irq, chip);
     763    chip->irq = -1;
     764    pci_disable_msi(chip->pci);
     765    chip->msi = 0;
     766    if (azx_acquire_irq(chip, 1) < 0) {
     767      bus->rirb_error = 1;
     768      return -1;
     769    }
     770    goto again;
     771  }
     772
     773  if (chip->probing) {
     774    /* If this critical timeout happens during the codec probing
     775    * phase, this is likely an access to a non-existing codec
     776    * slot.  Better to return an error and reset the system.
     777    */
     778    return -1;
     779  }
     780
     781  /* a fatal communication error; need either to reset or to fallback
     782  * to the single_cmd mode
     783  */
     784  bus->rirb_error = 1;
     785  if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
     786    bus->response_reset = 1;
     787    return -1; /* give a chance to retry */
     788  }
     789
     790  snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
     791       "switching to single_cmd mode: last cmd=0x%08x\n",
     792       chip->last_cmd[addr]);
     793  chip->single_cmd = 1;
     794  bus->response_reset = 0;
     795  /* release CORB/RIRB */
     796  azx_free_cmd_io(chip);
     797  /* disable unsolicited responses */
     798  azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
     799  return -1;
    798800}
    799801
     
    811813static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
    812814{
    813         int timeout = 50;
    814 
    815         while (timeout--) {
    816                 /* check IRV busy bit */
    817                 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
    818                         /* reuse rirb.res as the response return value */
    819                         chip->rirb.res[addr] = azx_readl(chip, IR);
    820                         return 0;
    821                 }
    822                 udelay(1);
    823         }
    824         if (printk_ratelimit())
    825                 snd_printd(SFX "get_response timeout: IRS=0x%x\n",
    826                            azx_readw(chip, IRS));
    827         chip->rirb.res[addr] = -1;
    828         return -EIO;
     815  int timeout = 50;
     816
     817  while (timeout--) {
     818    /* check IRV busy bit */
     819    if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
     820      /* reuse rirb.res as the response return value */
     821      chip->rirb.res[addr] = azx_readl(chip, IR);
     822      return 0;
     823    }
     824    udelay(1);
     825  }
     826  if (printk_ratelimit())
     827    snd_printd(SFX "get_response timeout: IRS=0x%x\n",
     828         azx_readw(chip, IRS));
     829  chip->rirb.res[addr] = -1;
     830  return -EIO;
    829831}
    830832
     
    832834static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
    833835{
    834         struct azx *chip = bus->private_data;
    835         unsigned int addr = azx_command_addr(val);
    836         int timeout = 50;
    837 
    838         bus->rirb_error = 0;
    839         while (timeout--) {
    840                 /* check ICB busy bit */
    841                 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
    842                         /* Clear IRV valid bit */
    843                         azx_writew(chip, IRS, azx_readw(chip, IRS) |
    844                                    ICH6_IRS_VALID);
    845                         azx_writel(chip, IC, val);
    846                         azx_writew(chip, IRS, azx_readw(chip, IRS) |
    847                                    ICH6_IRS_BUSY);
    848                         return azx_single_wait_for_response(chip, addr);
    849                 }
    850                 udelay(1);
    851         }
    852         if (printk_ratelimit())
    853                 snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",
    854                            azx_readw(chip, IRS), val);
    855         return -EIO;
     836  struct azx *chip = bus->private_data;
     837  unsigned int addr = azx_command_addr(val);
     838  int timeout = 50;
     839
     840  bus->rirb_error = 0;
     841  while (timeout--) {
     842    /* check ICB busy bit */
     843    if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
     844      /* Clear IRV valid bit */
     845      azx_writew(chip, IRS, azx_readw(chip, IRS) |
     846           ICH6_IRS_VALID);
     847      azx_writel(chip, IC, val);
     848      azx_writew(chip, IRS, azx_readw(chip, IRS) |
     849           ICH6_IRS_BUSY);
     850      return azx_single_wait_for_response(chip, addr);
     851    }
     852    udelay(1);
     853  }
     854  if (printk_ratelimit())
     855    snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",
     856         azx_readw(chip, IRS), val);
     857  return -EIO;
    856858}
    857859
    858860/* receive a response */
    859861static unsigned int azx_single_get_response(struct hda_bus *bus,
    860                                             unsigned int addr)
    861 {
    862         struct azx *chip = bus->private_data;
    863         return chip->rirb.res[addr];
     862              unsigned int addr)
     863{
     864  struct azx *chip = bus->private_data;
     865  return chip->rirb.res[addr];
    864866}
    865867
     
    874876static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
    875877{
    876         struct azx *chip = bus->private_data;
    877 
    878         chip->last_cmd[azx_command_addr(val)] = val;
    879         if (chip->single_cmd)
    880                 return azx_single_send_cmd(bus, val);
    881         else
    882                 return azx_corb_send_cmd(bus, val);
     878  struct azx *chip = bus->private_data;
     879
     880  chip->last_cmd[azx_command_addr(val)] = val;
     881  if (chip->single_cmd)
     882    return azx_single_send_cmd(bus, val);
     883  else
     884    return azx_corb_send_cmd(bus, val);
    883885}
    884886
    885887/* get a response */
    886888static unsigned int azx_get_response(struct hda_bus *bus,
    887                                      unsigned int addr)
    888 {
    889         struct azx *chip = bus->private_data;
    890         if (chip->single_cmd)
    891                 return azx_single_get_response(bus, addr);
    892         else
    893                 return azx_rirb_get_response(bus, addr);
     889             unsigned int addr)
     890{
     891  struct azx *chip = bus->private_data;
     892  if (chip->single_cmd)
     893    return azx_single_get_response(bus, addr);
     894  else
     895    return azx_rirb_get_response(bus, addr);
    894896}
    895897
     
    901903static int azx_reset(struct azx *chip, int full_reset)
    902904{
    903         int count;
    904 
    905         if (!full_reset)
    906                 goto __skip;
    907 
    908         /* clear STATESTS */
    909         azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
    910 
    911         /* reset controller */
    912         azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
    913 
    914         count = 50;
    915         while (azx_readb(chip, GCTL) && --count)
    916                 msleep(1);
    917 
    918         /* delay for >= 100us for codec PLL to settle per spec
    919         * Rev 0.9 section 5.5.1
    920         */
    921         msleep(1);
    922 
    923         /* Bring controller out of reset */
    924         azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
    925 
    926         count = 50;
    927         while (!azx_readb(chip, GCTL) && --count)
    928                 msleep(1);
    929 
    930         /* Brent Chartrand said to wait >= 540us for codecs to initialize */
    931         msleep(1);
     905  int count;
     906
     907  if (!full_reset)
     908    goto __skip;
     909
     910  /* clear STATESTS */
     911  azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
     912
     913  /* reset controller */
     914  azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
     915
     916  count = 50;
     917  while (azx_readb(chip, GCTL) && --count)
     918    msleep(1);
     919
     920  /* delay for >= 100us for codec PLL to settle per spec
     921  * Rev 0.9 section 5.5.1
     922  */
     923  msleep(1);
     924
     925  /* Bring controller out of reset */
     926  azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
     927
     928  count = 50;
     929  while (!azx_readb(chip, GCTL) && --count)
     930    msleep(1);
     931
     932  /* Brent Chartrand said to wait >= 540us for codecs to initialize */
     933  msleep(1);
    932934
    933935      __skip:
    934         /* check to see if controller is ready */
    935         if (!azx_readb(chip, GCTL)) {
    936                 snd_printd(SFX "azx_reset: controller not ready!\n");
    937                 return -EBUSY;
    938         }
    939 
    940         /* Accept unsolicited responses */
    941         if (!chip->single_cmd)
    942                 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
    943                            ICH6_GCTL_UNSOL);
    944 
    945         /* detect codecs */
    946         if (!chip->codec_mask) {
    947                 chip->codec_mask = azx_readw(chip, STATESTS);
    948                 snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask);
    949         }
    950 
    951         return 0;
     936  /* check to see if controller is ready */
     937  if (!azx_readb(chip, GCTL)) {
     938    snd_printd(SFX "azx_reset: controller not ready!\n");
     939    return -EBUSY;
     940  }
     941
     942  /* Accept unsolicited responses */
     943  if (!chip->single_cmd)
     944    azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
     945         ICH6_GCTL_UNSOL);
     946
     947  /* detect codecs */
     948  if (!chip->codec_mask) {
     949    chip->codec_mask = azx_readw(chip, STATESTS);
     950    snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask);
     951  }
     952
     953  return 0;
    952954}
    953955
     
    960962static void azx_int_enable(struct azx *chip)
    961963{
    962         /* enable controller CIE and GIE */
    963         azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
    964                    ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
     964  /* enable controller CIE and GIE */
     965  azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
     966       ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
    965967}
    966968
     
    968970static void azx_int_disable(struct azx *chip)
    969971{
    970         int i;
    971 
    972         /* disable interrupts in stream descriptor */
    973         for (i = 0; i < chip->num_streams; i++) {
    974                 struct azx_dev *azx_dev = &chip->azx_dev[i];
    975                 azx_sd_writeb(azx_dev, SD_CTL,
    976                               azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
    977         }
    978 
    979         /* disable SIE for all streams */
    980         azx_writeb(chip, INTCTL, 0);
    981 
    982         /* disable controller CIE and GIE */
    983         azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
    984                    ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
     972  int i;
     973
     974  /* disable interrupts in stream descriptor */
     975  for (i = 0; i < chip->num_streams; i++) {
     976    struct azx_dev *azx_dev = &chip->azx_dev[i];
     977    azx_sd_writeb(azx_dev, SD_CTL,
     978            azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
     979  }
     980
     981  /* disable SIE for all streams */
     982  azx_writeb(chip, INTCTL, 0);
     983
     984  /* disable controller CIE and GIE */
     985  azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
     986       ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
    985987}
    986988
     
    988990static void azx_int_clear(struct azx *chip)
    989991{
    990         int i;
    991 
    992         /* clear stream status */
    993         for (i = 0; i < chip->num_streams; i++) {
    994                 struct azx_dev *azx_dev = &chip->azx_dev[i];
    995                 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
    996         }
    997 
    998         /* clear STATESTS */
    999         azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
    1000 
    1001         /* clear rirb status */
    1002         azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
    1003 
    1004         /* clear int status */
    1005         azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
     992  int i;
     993
     994  /* clear stream status */
     995  for (i = 0; i < chip->num_streams; i++) {
     996    struct azx_dev *azx_dev = &chip->azx_dev[i];
     997    azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
     998  }
     999
     1000  /* clear STATESTS */
     1001  azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
     1002
     1003  /* clear rirb status */
     1004  azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
     1005
     1006  /* clear int status */
     1007  azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
    10061008}
    10071009
     
    10091011static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
    10101012{
    1011         /*
    1012         * Before stream start, initialize parameter
    1013         */
    1014         azx_dev->insufficient = 1;
    1015 
    1016         /* enable SIE */
    1017         azx_writel(chip, INTCTL,
    1018                    azx_readl(chip, INTCTL) | (1 << azx_dev->index));
    1019         /* set DMA start and interrupt mask */
    1020         azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
    1021                       SD_CTL_DMA_START | SD_INT_MASK);
     1013  /*
     1014  * Before stream start, initialize parameter
     1015  */
     1016  azx_dev->insufficient = 1;
     1017
     1018  /* enable SIE */
     1019  azx_writel(chip, INTCTL,
     1020       azx_readl(chip, INTCTL) | (1 << azx_dev->index));
     1021  /* set DMA start and interrupt mask */
     1022  azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
     1023          SD_CTL_DMA_START | SD_INT_MASK);
    10221024}
    10231025
     
    10251027static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
    10261028{
    1027         azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
    1028                       ~(SD_CTL_DMA_START | SD_INT_MASK));
    1029         azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
     1029  azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
     1030          ~(SD_CTL_DMA_START | SD_INT_MASK));
     1031  azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
    10301032}
    10311033
     
    10331035static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
    10341036{
    1035         azx_stream_clear(chip, azx_dev);
    1036         /* disable SIE */
    1037         azx_writel(chip, INTCTL,
    1038                    azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
     1037  azx_stream_clear(chip, azx_dev);
     1038  /* disable SIE */
     1039  azx_writel(chip, INTCTL,
     1040       azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
    10391041}
    10401042
     
    10451047static void azx_init_chip(struct azx *chip, int full_reset)
    10461048{
    1047         if (chip->initialized)
    1048                 return;
    1049 
    1050         /* reset controller */
    1051         azx_reset(chip, full_reset);
    1052 
    1053         /* initialize interrupts */
    1054         azx_int_clear(chip);
    1055         azx_int_enable(chip);
    1056 
    1057         /* initialize the codec command I/O */
    1058         if (!chip->single_cmd)
    1059                 azx_init_cmd_io(chip);
    1060 
    1061         /* program the position buffer */
    1062         azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
    1063         azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
    1064 
    1065         chip->initialized = 1;
     1049  if (chip->initialized)
     1050    return;
     1051
     1052  /* reset controller */
     1053  azx_reset(chip, full_reset);
     1054
     1055  /* initialize interrupts */
     1056  azx_int_clear(chip);
     1057  azx_int_enable(chip);
     1058
     1059  /* initialize the codec command I/O */
     1060  if (!chip->single_cmd)
     1061    azx_init_cmd_io(chip);
     1062
     1063  /* program the position buffer */
     1064  azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
     1065  azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
     1066
     1067  chip->initialized = 1;
    10661068}
    10671069
     
    10711073/* update bits in a PCI register byte */
    10721074static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
    1073                             unsigned char mask, unsigned char val)
    1074 {
    1075         unsigned char data;
    1076 
    1077         pci_read_config_byte(pci, reg, &data);
    1078         data &= ~mask;
    1079         data |= (val & mask);
    1080         pci_write_config_byte(pci, reg, data);
     1075          unsigned char mask, unsigned char val)
     1076{
     1077  unsigned char data;
     1078
     1079  pci_read_config_byte(pci, reg, &data);
     1080  data &= ~mask;
     1081  data |= (val & mask);
     1082  pci_write_config_byte(pci, reg, data);
    10811083}
    10821084
    10831085static void azx_init_pci(struct azx *chip)
    10841086{
    1085         unsigned short snoop;
    1086 
    1087         /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
    1088         * TCSEL == Traffic Class Select Register, which sets PCI express QOS
    1089         * Ensuring these bits are 0 clears playback static on some HD Audio
    1090         * codecs
    1091         */
    1092         update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
    1093 
    1094         switch (chip->driver_type) {
    1095         case AZX_DRIVER_ATI:
    1096                 /* For ATI SB450 azalia HD audio, we need to enable snoop */
    1097                 update_pci_byte(chip->pci,
    1098                                 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
    1099                                 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
    1100                 break;
    1101         case AZX_DRIVER_NVIDIA:
    1102                 /* For NVIDIA HDA, enable snoop */
    1103                 update_pci_byte(chip->pci,
    1104                                 NVIDIA_HDA_TRANSREG_ADDR,
    1105                                 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
    1106                 update_pci_byte(chip->pci,
    1107                                 NVIDIA_HDA_ISTRM_COH,
    1108                                 0x01, NVIDIA_HDA_ENABLE_COHBIT);
    1109                 update_pci_byte(chip->pci,
    1110                                 NVIDIA_HDA_OSTRM_COH,
    1111                                 0x01, NVIDIA_HDA_ENABLE_COHBIT);
    1112                 break;
    1113         case AZX_DRIVER_SCH:
    1114         case AZX_DRIVER_PCH:
    1115                 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
    1116                 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
    1117                         pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
    1118                                 snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
    1119                         pci_read_config_word(chip->pci,
    1120                                 INTEL_SCH_HDA_DEVC, &snoop);
    1121                         snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
    1122                                 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
    1123                                 ? "Failed" : "OK");
    1124                 }
    1125                 break;
     1087  unsigned short snoop;
     1088
     1089  /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
     1090  * TCSEL == Traffic Class Select Register, which sets PCI express QOS
     1091  * Ensuring these bits are 0 clears playback static on some HD Audio
     1092  * codecs
     1093  */
     1094  update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
     1095
     1096  switch (chip->driver_type) {
     1097  case AZX_DRIVER_ATI:
     1098    /* For ATI SB450 azalia HD audio, we need to enable snoop */
     1099    update_pci_byte(chip->pci,
     1100        ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
     1101        0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);
     1102    break;
     1103  case AZX_DRIVER_NVIDIA:
     1104    /* For NVIDIA HDA, enable snoop */
     1105    update_pci_byte(chip->pci,
     1106        NVIDIA_HDA_TRANSREG_ADDR,
     1107        0x0f, NVIDIA_HDA_ENABLE_COHBITS);
     1108    update_pci_byte(chip->pci,
     1109        NVIDIA_HDA_ISTRM_COH,
     1110        0x01, NVIDIA_HDA_ENABLE_COHBIT);
     1111    update_pci_byte(chip->pci,
     1112        NVIDIA_HDA_OSTRM_COH,
     1113        0x01, NVIDIA_HDA_ENABLE_COHBIT);
     1114    break;
     1115  case AZX_DRIVER_SCH:
     1116  case AZX_DRIVER_PCH:
     1117    pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
     1118    if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {
     1119      pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,
     1120        snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));
     1121      pci_read_config_word(chip->pci,
     1122        INTEL_SCH_HDA_DEVC, &snoop);
     1123      snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
     1124        (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
     1125        ? "Failed" : "OK");
     1126    }
     1127    break;
    11261128
    11271129        }
     
    11361138static irqreturn_t azx_interrupt(int irq, void *dev_id)
    11371139{
    1138         struct azx *chip = dev_id;
    1139         struct azx_dev *azx_dev;
    1140         u32 status;
    1141         u8 sd_status;
    1142         int i, ok;
    1143 
    1144         spin_lock(&chip->reg_lock);
    1145 
    1146         status = azx_readl(chip, INTSTS);
    1147         if (status == 0) {
    1148                 spin_unlock(&chip->reg_lock);
    1149                 return IRQ_NONE;
    1150         }
    1151        
    1152         for (i = 0; i < chip->num_streams; i++) {
    1153                 azx_dev = &chip->azx_dev[i];
    1154                 if (status & azx_dev->sd_int_sta_mask) {
    1155                         sd_status = azx_sd_readb(azx_dev, SD_STS);
    1156                         azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
    1157                         if (!azx_dev->substream || !azx_dev->running ||
    1158                             !(sd_status & SD_INT_COMPLETE))
    1159                                 continue;
    1160                         /* check whether this IRQ is really acceptable */
    1161                         ok = azx_position_ok(chip, azx_dev);
    1162                         if (ok == 1) {
    1163                                 azx_dev->irq_pending = 0;
    1164                                 spin_unlock(&chip->reg_lock);
    1165                                 snd_pcm_period_elapsed(azx_dev->substream);
    1166                                 spin_lock(&chip->reg_lock);
    1167                         } else if (ok == 0 && chip->bus && chip->bus->workq) {
    1168                                 /* bogus IRQ, process it later */
    1169                                 azx_dev->irq_pending = 1;
    1170                                 queue_work(chip->bus->workq,
    1171                                            &chip->irq_pending_work);
    1172                         }
    1173                 }
    1174         }
    1175 
    1176         /* clear rirb int */
    1177         status = azx_readb(chip, RIRBSTS);
    1178         if (status & RIRB_INT_MASK) {
    1179                 if (status & RIRB_INT_RESPONSE) {
    1180                         if (chip->driver_type == AZX_DRIVER_CTX)
    1181                                 udelay(80);
    1182                         azx_update_rirb(chip);
    1183                 }
    1184                 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
    1185         }
     1140  struct azx *chip = dev_id;
     1141  struct azx_dev *azx_dev;
     1142  u32 status;
     1143  u8 sd_status;
     1144  int i, ok;
     1145
     1146  spin_lock(&chip->reg_lock);
     1147
     1148  status = azx_readl(chip, INTSTS);
     1149  if (status == 0) {
     1150    spin_unlock(&chip->reg_lock);
     1151    return IRQ_NONE;
     1152  }
     1153
     1154  for (i = 0; i < chip->num_streams; i++) {
     1155    azx_dev = &chip->azx_dev[i];
     1156    if (status & azx_dev->sd_int_sta_mask) {
     1157      sd_status = azx_sd_readb(azx_dev, SD_STS);
     1158      azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
     1159      if (!azx_dev->substream || !azx_dev->running ||
     1160          !(sd_status & SD_INT_COMPLETE))
     1161        continue;
     1162      /* check whether this IRQ is really acceptable */
     1163      ok = azx_position_ok(chip, azx_dev);
     1164      if (ok == 1) {
     1165        azx_dev->irq_pending = 0;
     1166        spin_unlock(&chip->reg_lock);
     1167        snd_pcm_period_elapsed(azx_dev->substream);
     1168        spin_lock(&chip->reg_lock);
     1169      } else if (ok == 0 && chip->bus && chip->bus->workq) {
     1170        /* bogus IRQ, process it later */
     1171        azx_dev->irq_pending = 1;
     1172        queue_work(chip->bus->workq,
     1173             &chip->irq_pending_work);
     1174      }
     1175    }
     1176  }
     1177
     1178  /* clear rirb int */
     1179  status = azx_readb(chip, RIRBSTS);
     1180  if (status & RIRB_INT_MASK) {
     1181    if (status & RIRB_INT_RESPONSE) {
     1182      if (chip->driver_type == AZX_DRIVER_CTX)
     1183        udelay(80);
     1184      azx_update_rirb(chip);
     1185    }
     1186    azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
     1187  }
    11861188
    11871189#if 0
    1188         /* clear state status int */
    1189         if (azx_readb(chip, STATESTS) & 0x04)
    1190                 azx_writeb(chip, STATESTS, 0x04);
     1190  /* clear state status int */
     1191  if (azx_readb(chip, STATESTS) & 0x04)
     1192    azx_writeb(chip, STATESTS, 0x04);
    11911193#endif
    1192         spin_unlock(&chip->reg_lock);
     1194  spin_unlock(&chip->reg_lock);
    11931195
    11941196#ifdef TARGET_OS2
     
    11981200#endif
    11991201
    1200         return IRQ_HANDLED;
     1202  return IRQ_HANDLED;
    12011203}
    12021204
     
    12061208 */
    12071209static int setup_bdle(struct snd_pcm_substream *substream,
    1208                       struct azx_dev *azx_dev, u32 **bdlp,
    1209                       int ofs, int size, int with_ioc)
    1210 {
    1211         u32 *bdl = *bdlp;
    1212 
    1213         while (size > 0) {
    1214                 dma_addr_t addr;
    1215                 int chunk;
    1216 
    1217                 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
    1218                         return -EINVAL;
    1219 
    1220                 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
    1221                 /* program the address field of the BDL entry */
    1222                 bdl[0] = cpu_to_le32((u32)addr);
    1223                 bdl[1] = cpu_to_le32(upper_32_bits(addr));
    1224                 /* program the size field of the BDL entry */
    1225                 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
    1226                 bdl[2] = cpu_to_le32(chunk);
    1227                 /* program the IOC to enable interrupt
    1228                 * only when the whole fragment is processed
    1229                 */
    1230                 size -= chunk;
    1231                 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
    1232                 bdl += 4;
    1233                 azx_dev->frags++;
    1234                 ofs += chunk;
    1235         }
    1236         *bdlp = bdl;
    1237         return ofs;
     1210          struct azx_dev *azx_dev, u32 **bdlp,
     1211          int ofs, int size, int with_ioc)
     1212{
     1213  u32 *bdl = *bdlp;
     1214
     1215  while (size > 0) {
     1216    dma_addr_t addr;
     1217    int chunk;
     1218
     1219    if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
     1220      return -EINVAL;
     1221
     1222    addr = snd_pcm_sgbuf_get_addr(substream, ofs);
     1223    /* program the address field of the BDL entry */
     1224    bdl[0] = cpu_to_le32((u32)addr);
     1225    bdl[1] = cpu_to_le32(upper_32_bits(addr));
     1226    /* program the size field of the BDL entry */
     1227    chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
     1228    bdl[2] = cpu_to_le32(chunk);
     1229    /* program the IOC to enable interrupt
     1230    * only when the whole fragment is processed
     1231    */
     1232    size -= chunk;
     1233    bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
     1234    bdl += 4;
     1235    azx_dev->frags++;
     1236    ofs += chunk;
     1237  }
     1238  *bdlp = bdl;
     1239  return ofs;
    12381240}
    12391241
     
    12421244 */
    12431245static int azx_setup_periods(struct azx *chip,
    1244                              struct snd_pcm_substream *substream,
    1245                              struct azx_dev *azx_dev)
    1246 {
    1247         u32 *bdl;
    1248         int i, ofs, periods, period_bytes;
    1249         int pos_adj;
    1250 
    1251         /* reset BDL address */
    1252         azx_sd_writel(azx_dev, SD_BDLPL, 0);
    1253         azx_sd_writel(azx_dev, SD_BDLPU, 0);
    1254 
    1255         period_bytes = azx_dev->period_bytes;
    1256         periods = azx_dev->bufsize / period_bytes;
    1257 
    1258         /* program the initial BDL entries */
    1259         bdl = (u32 *)azx_dev->bdl.area;
    1260         ofs = 0;
    1261         azx_dev->frags = 0;
    1262         pos_adj = bdl_pos_adj[chip->dev_index];
    1263         if (pos_adj > 0) {
    1264                 struct snd_pcm_runtime *runtime = substream->runtime;
    1265                 int pos_align = pos_adj;
    1266                 pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
    1267                 if (!pos_adj)
    1268                         pos_adj = pos_align;
    1269                 else
    1270                         pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
    1271                                 pos_align;
    1272                 pos_adj = frames_to_bytes(runtime, pos_adj);
    1273                 if (pos_adj >= period_bytes) {
    1274                         snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",
    1275                                    bdl_pos_adj[chip->dev_index]);
    1276                         pos_adj = 0;
    1277                 } else {
    1278                         ofs = setup_bdle(substream, azx_dev,
    1279                                         &bdl, ofs, pos_adj,
    1280                                         !substream->runtime->no_period_wakeup);
    1281                         if (ofs < 0)
    1282                                 goto error;
    1283                 }
    1284         } else
    1285                 pos_adj = 0;
    1286         for (i = 0; i < periods; i++) {
    1287                 if (i == periods - 1 && pos_adj)
    1288                         ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
    1289                                         period_bytes - pos_adj, 0);
    1290                 else
    1291                         ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
    1292                                         period_bytes,
    1293                                         !substream->runtime->no_period_wakeup);
    1294                 if (ofs < 0)
    1295                         goto error;
    1296         }
    1297         return 0;
     1246           struct snd_pcm_substream *substream,
     1247           struct azx_dev *azx_dev)
     1248{
     1249  u32 *bdl;
     1250  int i, ofs, periods, period_bytes;
     1251  int pos_adj;
     1252
     1253  /* reset BDL address */
     1254  azx_sd_writel(azx_dev, SD_BDLPL, 0);
     1255  azx_sd_writel(azx_dev, SD_BDLPU, 0);
     1256
     1257  period_bytes = azx_dev->period_bytes;
     1258  periods = azx_dev->bufsize / period_bytes;
     1259
     1260  /* program the initial BDL entries */
     1261  bdl = (u32 *)azx_dev->bdl.area;
     1262  ofs = 0;
     1263  azx_dev->frags = 0;
     1264  pos_adj = bdl_pos_adj[chip->dev_index];
     1265  if (pos_adj > 0) {
     1266    struct snd_pcm_runtime *runtime = substream->runtime;
     1267    int pos_align = pos_adj;
     1268    pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
     1269    if (!pos_adj)
     1270      pos_adj = pos_align;
     1271    else
     1272      pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
     1273        pos_align;
     1274    pos_adj = frames_to_bytes(runtime, pos_adj);
     1275    if (pos_adj >= period_bytes) {
     1276      snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",
     1277           bdl_pos_adj[chip->dev_index]);
     1278      pos_adj = 0;
     1279    } else {
     1280      ofs = setup_bdle(substream, azx_dev,
     1281          &bdl, ofs, pos_adj,
     1282          !substream->runtime->no_period_wakeup);
     1283      if (ofs < 0)
     1284        goto error;
     1285    }
     1286  } else
     1287    pos_adj = 0;
     1288  for (i = 0; i < periods; i++) {
     1289    if (i == periods - 1 && pos_adj)
     1290      ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
     1291          period_bytes - pos_adj, 0);
     1292    else
     1293      ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
     1294          period_bytes,
     1295          !substream->runtime->no_period_wakeup);
     1296    if (ofs < 0)
     1297      goto error;
     1298  }
     1299  return 0;
    12981300
    12991301 error:
    1300         snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
    1301                    azx_dev->bufsize, period_bytes);
    1302         return -EINVAL;
     1302  snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
     1303       azx_dev->bufsize, period_bytes);
     1304  return -EINVAL;
    13031305}
    13041306
     
    13061308static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
    13071309{
    1308         unsigned char val;
    1309         int timeout;
    1310 
    1311         azx_stream_clear(chip, azx_dev);
    1312 
    1313         azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
    1314                       SD_CTL_STREAM_RESET);
    1315         udelay(3);
    1316         timeout = 300;
    1317         while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
    1318                --timeout)
    1319                 ;
    1320         val &= ~SD_CTL_STREAM_RESET;
    1321         azx_sd_writeb(azx_dev, SD_CTL, val);
    1322         udelay(3);
    1323 
    1324         timeout = 300;
    1325         /* waiting for hardware to report that the stream is out of reset */
    1326         while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
    1327                --timeout)
    1328                 ;
    1329 
    1330         /* reset first position - may not be synced with hw at this time */
    1331         *azx_dev->posbuf = 0;
     1310  unsigned char val;
     1311  int timeout;
     1312
     1313  azx_stream_clear(chip, azx_dev);
     1314
     1315  azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
     1316          SD_CTL_STREAM_RESET);
     1317  udelay(3);
     1318  timeout = 300;
     1319  while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
     1320         --timeout)
     1321    ;
     1322  val &= ~SD_CTL_STREAM_RESET;
     1323  azx_sd_writeb(azx_dev, SD_CTL, val);
     1324  udelay(3);
     1325
     1326  timeout = 300;
     1327  /* waiting for hardware to report that the stream is out of reset */
     1328  while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
     1329         --timeout)
     1330    ;
     1331
     1332  /* reset first position - may not be synced with hw at this time */
     1333  *azx_dev->posbuf = 0;
    13321334}
    13331335
     
    13371339static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
    13381340{
    1339         /* make sure the run bit is zero for SD */
    1340         azx_stream_clear(chip, azx_dev);
    1341         /* program the stream_tag */
    1342         azx_sd_writel(azx_dev, SD_CTL,
    1343                       (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
    1344                       (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
    1345 
    1346         /* program the length of samples in cyclic buffer */
    1347         azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
    1348 
    1349         /* program the stream format */
    1350         /* this value needs to be the same as the one programmed */
    1351         azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
    1352 
    1353         /* program the stream LVI (last valid index) of the BDL */
    1354         azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
    1355 
    1356         /* program the BDL address */
    1357         /* lower BDL address */
    1358         azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
    1359         /* upper BDL address */
    1360         azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
    1361 
    1362         /* enable the position buffer */
    1363         if (chip->position_fix[0] != POS_FIX_LPIB ||
    1364             chip->position_fix[1] != POS_FIX_LPIB) {
    1365                 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
    1366                         azx_writel(chip, DPLBASE,
    1367                                 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
    1368         }
    1369 
    1370         /* set the interrupt enable bits in the descriptor control register */
    1371         azx_sd_writel(azx_dev, SD_CTL,
    1372                       azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
    1373 
    1374         return 0;
     1341  /* make sure the run bit is zero for SD */
     1342  azx_stream_clear(chip, azx_dev);
     1343  /* program the stream_tag */
     1344  azx_sd_writel(azx_dev, SD_CTL,
     1345          (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
     1346          (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));
     1347
     1348  /* program the length of samples in cyclic buffer */
     1349  azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
     1350
     1351  /* program the stream format */
     1352  /* this value needs to be the same as the one programmed */
     1353  azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
     1354
     1355  /* program the stream LVI (last valid index) of the BDL */
     1356  azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
     1357
     1358  /* program the BDL address */
     1359  /* lower BDL address */
     1360  azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
     1361  /* upper BDL address */
     1362  azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
     1363
     1364  /* enable the position buffer */
     1365  if (chip->position_fix[0] != POS_FIX_LPIB ||
     1366      chip->position_fix[1] != POS_FIX_LPIB) {
     1367    if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
     1368      azx_writel(chip, DPLBASE,
     1369        (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
     1370  }
     1371
     1372  /* set the interrupt enable bits in the descriptor control register */
     1373  azx_sd_writel(azx_dev, SD_CTL,
     1374          azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
     1375
     1376  return 0;
    13751377}
    13761378
     
    13801382static int probe_codec(struct azx *chip, int addr)
    13811383{
    1382         unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
    1383                 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
    1384         unsigned int res;
    1385 
    1386         mutex_lock(&chip->bus->cmd_mutex);
    1387         chip->probing = 1;
    1388         azx_send_cmd(chip->bus, cmd);
    1389         res = azx_get_response(chip->bus, addr);
    1390         chip->probing = 0;
    1391         mutex_unlock(&chip->bus->cmd_mutex);
    1392         if (res == -1)
    1393                 return -EIO;
    1394         snd_printdd(SFX "codec #%d probed OK\n", addr);
    1395         return 0;
     1384  unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
     1385    (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
     1386  unsigned int res;
     1387
     1388  mutex_lock(&chip->bus->cmd_mutex);
     1389  chip->probing = 1;
     1390  azx_send_cmd(chip->bus, cmd);
     1391  res = azx_get_response(chip->bus, addr);
     1392  chip->probing = 0;
     1393  mutex_unlock(&chip->bus->cmd_mutex);
     1394  if (res == -1)
     1395    return -EIO;
     1396  snd_printdd(SFX "codec #%d probed OK\n", addr);
     1397  return 0;
    13961398}
    13971399
    13981400static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
    1399                                 struct hda_pcm *cpcm);
     1401        struct hda_pcm *cpcm);
    14001402static void azx_stop_chip(struct azx *chip);
    14011403
    14021404static void azx_bus_reset(struct hda_bus *bus)
    14031405{
    1404         struct azx *chip = bus->private_data;
    1405 
    1406         bus->in_reset = 1;
    1407         azx_stop_chip(chip);
    1408         azx_init_chip(chip, 1);
     1406  struct azx *chip = bus->private_data;
     1407
     1408  bus->in_reset = 1;
     1409  azx_stop_chip(chip);
     1410  azx_init_chip(chip, 1);
    14091411#ifdef CONFIG_PM
    1410         if (chip->initialized) {
    1411                 int i;
    1412 
    1413                 for (i = 0; i < HDA_MAX_PCMS; i++)
    1414                         snd_pcm_suspend_all(chip->pcm[i]);
    1415                 snd_hda_suspend(chip->bus);
    1416                 snd_hda_resume(chip->bus);
    1417         }
     1412  if (chip->initialized) {
     1413    int i;
     1414
     1415    for (i = 0; i < HDA_MAX_PCMS; i++)
     1416      snd_pcm_suspend_all(chip->pcm[i]);
     1417    snd_hda_suspend(chip->bus);
     1418    snd_hda_resume(chip->bus);
     1419  }
    14181420#endif
    1419         bus->in_reset = 0;
     1421  bus->in_reset = 0;
    14201422}
    14211423
     
    14261428/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
    14271429static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
    1428         [AZX_DRIVER_NVIDIA] = 8,
    1429         [AZX_DRIVER_TERA] = 1,
     1430  [AZX_DRIVER_NVIDIA] = 8,
     1431  [AZX_DRIVER_TERA] = 1,
    14301432};
    14311433
    14321434static int __devinit azx_codec_create(struct azx *chip, const char *model)
    14331435{
    1434         struct hda_bus_template bus_temp;
    1435         int c, codecs, err;
    1436         int max_slots;
    1437 
    1438         memset(&bus_temp, 0, sizeof(bus_temp));
    1439         bus_temp.private_data = chip;
    1440         bus_temp.modelname = model;
    1441         bus_temp.pci = chip->pci;
    1442         bus_temp.ops.command = azx_send_cmd;
    1443         bus_temp.ops.get_response = azx_get_response;
    1444         bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
    1445         bus_temp.ops.bus_reset = azx_bus_reset;
     1436  struct hda_bus_template bus_temp;
     1437  int c, codecs, err;
     1438  int max_slots;
     1439
     1440  memset(&bus_temp, 0, sizeof(bus_temp));
     1441  bus_temp.private_data = chip;
     1442  bus_temp.modelname = model;
     1443  bus_temp.pci = chip->pci;
     1444  bus_temp.ops.command = azx_send_cmd;
     1445  bus_temp.ops.get_response = azx_get_response;
     1446  bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
     1447  bus_temp.ops.bus_reset = azx_bus_reset;
    14461448#ifdef CONFIG_SND_HDA_POWER_SAVE
    1447         bus_temp.power_save = &power_save;
    1448         bus_temp.ops.pm_notify = azx_power_notify;
     1449  bus_temp.power_save = &power_save;
     1450  bus_temp.ops.pm_notify = azx_power_notify;
    14491451#endif
    14501452
    1451         err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
    1452         if (err < 0)
    1453                 return err;
    1454 
    1455         if (chip->driver_type == AZX_DRIVER_NVIDIA)
    1456                 chip->bus->needs_damn_long_delay = 1;
    1457 
    1458         codecs = 0;
    1459         max_slots = azx_max_codecs[chip->driver_type];
    1460         if (!max_slots)
    1461                 max_slots = AZX_DEFAULT_CODECS;
    1462 
    1463         /* First try to probe all given codec slots */
    1464         for (c = 0; c < max_slots; c++) {
    1465                 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
    1466                         if (probe_codec(chip, c) < 0) {
    1467                                 /* Some BIOSen give you wrong codec addresses
    1468                                 * that don't exist
    1469                                 */
    1470                                 snd_printk(KERN_WARNING SFX
    1471                                            "Codec #%d probe error; "
    1472                                            "disabling it...\n", c);
    1473                                 chip->codec_mask &= ~(1 << c);
    1474                                 /* More badly, accessing to a non-existing
    1475                                 * codec often screws up the controller chip,
    1476                                 * and disturbs the further communications.
    1477                                 * Thus if an error occurs during probing,
    1478                                 * better to reset the controller chip to
    1479                                 * get back to the sanity state.
    1480                                 */
    1481                                 azx_stop_chip(chip);
    1482                                 azx_init_chip(chip, 1);
    1483                         }
    1484                 }
    1485         }
    1486 
    1487         /* Then create codec instances */
    1488         for (c = 0; c < max_slots; c++) {
    1489                 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
    1490                         struct hda_codec *codec;
    1491                         err = snd_hda_codec_new(chip->bus, c, &codec);
    1492                         if (err < 0)
    1493                                 continue;
    1494                         codec->beep_mode = chip->beep_mode;
    1495                         codecs++;
    1496                 }
    1497         }
    1498         if (!codecs) {
    1499                 snd_printk(KERN_ERR SFX "no codecs initialized\n");
    1500                 return -ENXIO;
    1501         }
    1502         return 0;
     1453  err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
     1454  if (err < 0)
     1455    return err;
     1456
     1457  if (chip->driver_type == AZX_DRIVER_NVIDIA)
     1458    chip->bus->needs_damn_long_delay = 1;
     1459
     1460  codecs = 0;
     1461  max_slots = azx_max_codecs[chip->driver_type];
     1462  if (!max_slots)
     1463    max_slots = AZX_DEFAULT_CODECS;
     1464
     1465  /* First try to probe all given codec slots */
     1466  for (c = 0; c < max_slots; c++) {
     1467    if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
     1468      if (probe_codec(chip, c) < 0) {
     1469        /* Some BIOSen give you wrong codec addresses
     1470        * that don't exist
     1471        */
     1472        snd_printk(KERN_WARNING SFX
     1473             "Codec #%d probe error; "
     1474             "disabling it...\n", c);
     1475        chip->codec_mask &= ~(1 << c);
     1476        /* More badly, accessing to a non-existing
     1477        * codec often screws up the controller chip,
     1478        * and disturbs the further communications.
     1479        * Thus if an error occurs during probing,
     1480        * better to reset the controller chip to
     1481        * get back to the sanity state.
     1482        */
     1483        azx_stop_chip(chip);
     1484        azx_init_chip(chip, 1);
     1485      }
     1486    }
     1487  }
     1488
     1489  /* Then create codec instances */
     1490  for (c = 0; c < max_slots; c++) {
     1491    if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
     1492      struct hda_codec *codec;
     1493      err = snd_hda_codec_new(chip->bus, c, &codec);
     1494      if (err < 0)
     1495        continue;
     1496      codec->beep_mode = chip->beep_mode;
     1497      codecs++;
     1498    }
     1499  }
     1500  if (!codecs) {
     1501    snd_printk(KERN_ERR SFX "no codecs initialized\n");
     1502    return -ENXIO;
     1503  }
     1504  return 0;
    15031505}
    15041506
     
    15061508static int __devinit azx_codec_configure(struct azx *chip)
    15071509{
    1508         struct hda_codec *codec;
    1509         list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {
    1510                 snd_hda_codec_configure(codec);
    1511         }
    1512         return 0;
     1510  struct hda_codec *codec;
     1511  list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {
     1512    snd_hda_codec_configure(codec);
     1513  }
     1514  return 0;
    15131515}
    15141516
     
    15221524azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
    15231525{
    1524         int dev, i, nums;
    1525         struct azx_dev *res = NULL;
    1526 
    1527         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    1528                 dev = chip->playback_index_offset;
    1529                 nums = chip->playback_streams;
    1530         } else {
    1531                 dev = chip->capture_index_offset;
    1532                 nums = chip->capture_streams;
    1533         }
    1534         for (i = 0; i < nums; i++, dev++)
    1535                 if (!chip->azx_dev[dev].opened) {
    1536                         res = &chip->azx_dev[dev];
    1537                         if (res->device == substream->pcm->device)
    1538                                 break;
    1539                 }
    1540         if (res) {
    1541                 res->opened = 1;
    1542                 res->device = substream->pcm->device;
    1543         }
    1544         return res;
     1526  int dev, i, nums;
     1527  struct azx_dev *res = NULL;
     1528
     1529  if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
     1530    dev = chip->playback_index_offset;
     1531    nums = chip->playback_streams;
     1532  } else {
     1533    dev = chip->capture_index_offset;
     1534    nums = chip->capture_streams;
     1535  }
     1536  for (i = 0; i < nums; i++, dev++)
     1537    if (!chip->azx_dev[dev].opened) {
     1538      res = &chip->azx_dev[dev];
     1539      if (res->device == substream->pcm->device)
     1540        break;
     1541    }
     1542  if (res) {
     1543    res->opened = 1;
     1544    res->device = substream->pcm->device;
     1545  }
     1546  return res;
    15451547}
    15461548
     
    15481550static inline void azx_release_device(struct azx_dev *azx_dev)
    15491551{
    1550         azx_dev->opened = 0;
     1552  azx_dev->opened = 0;
    15511553}
    15521554
    15531555static struct snd_pcm_hardware azx_pcm_hw = {
    1554         .info =                 (SNDRV_PCM_INFO_MMAP |
    1555                                 SNDRV_PCM_INFO_INTERLEAVED |
    1556                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    1557                                 SNDRV_PCM_INFO_MMAP_VALID |
    1558                                 /* No full-resume yet implemented */
    1559                                 /* SNDRV_PCM_INFO_RESUME |*/
    1560                                 SNDRV_PCM_INFO_PAUSE |
    1561                                 SNDRV_PCM_INFO_SYNC_START |
    1562                                 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
    1563         .formats =              SNDRV_PCM_FMTBIT_S16_LE,
    1564         .rates =                SNDRV_PCM_RATE_48000,
    1565         .rate_min =             48000,
    1566         .rate_max =             48000,
    1567         .channels_min =         2,
    1568         .channels_max =         2,
    1569         .buffer_bytes_max =     AZX_MAX_BUF_SIZE,
    1570         .period_bytes_min =     128,
    1571         .period_bytes_max =     AZX_MAX_BUF_SIZE / 2,
    1572         .periods_min =          2,
    1573         .periods_max =          AZX_MAX_FRAG,
    1574         .fifo_size =            0,
     1556  .info =     (SNDRV_PCM_INFO_MMAP |
     1557        SNDRV_PCM_INFO_INTERLEAVED |
     1558        SNDRV_PCM_INFO_BLOCK_TRANSFER |
     1559        SNDRV_PCM_INFO_MMAP_VALID |
     1560        /* No full-resume yet implemented */
     1561        /* SNDRV_PCM_INFO_RESUME |*/
     1562        SNDRV_PCM_INFO_PAUSE |
     1563        SNDRV_PCM_INFO_SYNC_START |
     1564        SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
     1565  .formats =    SNDRV_PCM_FMTBIT_S16_LE,
     1566  .rates =    SNDRV_PCM_RATE_48000,
     1567  .rate_min =   48000,
     1568  .rate_max =   48000,
     1569  .channels_min =   2,
     1570  .channels_max =   2,
     1571  .buffer_bytes_max = AZX_MAX_BUF_SIZE,
     1572  .period_bytes_min = 128,
     1573  .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
     1574  .periods_min =    2,
     1575  .periods_max =    AZX_MAX_FRAG,
     1576  .fifo_size =    0,
    15751577};
    15761578
    15771579struct azx_pcm {
    1578         struct azx *chip;
    1579         struct hda_codec *codec;
    1580         struct hda_pcm_stream *hinfo[2];
     1580  struct azx *chip;
     1581  struct hda_codec *codec;
     1582  struct hda_pcm_stream *hinfo[2];
    15811583};
    15821584
    15831585static int azx_pcm_open(struct snd_pcm_substream *substream)
    15841586{
    1585         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1586         struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
    1587         struct azx *chip = apcm->chip;
    1588         struct azx_dev *azx_dev;
    1589         struct snd_pcm_runtime *runtime = substream->runtime;
    1590         unsigned long flags;
    1591         int err;
    1592 
    1593         mutex_lock(&chip->open_mutex);
    1594         azx_dev = azx_assign_device(chip, substream);
    1595         if (azx_dev == NULL) {
    1596                 mutex_unlock(&chip->open_mutex);
    1597                 return -EBUSY;
    1598         }
    1599         runtime->hw = azx_pcm_hw;
    1600         runtime->hw.channels_min = hinfo->channels_min;
    1601         runtime->hw.channels_max = hinfo->channels_max;
    1602         runtime->hw.formats = hinfo->formats;
    1603         runtime->hw.rates = hinfo->rates;
    1604         snd_pcm_limit_hw_rates(runtime);
    1605         snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
    1606         snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
    1607                                    128);
    1608         snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
    1609                                    128);
    1610         snd_hda_power_up(apcm->codec);
    1611         err = hinfo->ops.open(hinfo, apcm->codec, substream);
    1612         if (err < 0) {
    1613                 azx_release_device(azx_dev);
    1614                 snd_hda_power_down(apcm->codec);
    1615                 mutex_unlock(&chip->open_mutex);
    1616                 return err;
    1617         }
    1618         snd_pcm_limit_hw_rates(runtime);
    1619         /* sanity check */
    1620         if (snd_BUG_ON(!runtime->hw.channels_min) ||
    1621             snd_BUG_ON(!runtime->hw.channels_max) ||
    1622             snd_BUG_ON(!runtime->hw.formats) ||
    1623             snd_BUG_ON(!runtime->hw.rates)) {
    1624                 azx_release_device(azx_dev);
    1625                 hinfo->ops.close(hinfo, apcm->codec, substream);
    1626                 snd_hda_power_down(apcm->codec);
    1627                 mutex_unlock(&chip->open_mutex);
    1628                 return -EINVAL;
    1629         }
    1630         spin_lock_irqsave(&chip->reg_lock, flags);
    1631         azx_dev->substream = substream;
    1632         azx_dev->running = 0;
    1633         spin_unlock_irqrestore(&chip->reg_lock, flags);
    1634 
    1635         runtime->private_data = azx_dev;
    1636         snd_pcm_set_sync(substream);
    1637         mutex_unlock(&chip->open_mutex);
    1638         return 0;
     1587  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1588  struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
     1589  struct azx *chip = apcm->chip;
     1590  struct azx_dev *azx_dev;
     1591  struct snd_pcm_runtime *runtime = substream->runtime;
     1592  unsigned long flags;
     1593  int err;
     1594
     1595  mutex_lock(&chip->open_mutex);
     1596  azx_dev = azx_assign_device(chip, substream);
     1597  if (azx_dev == NULL) {
     1598    mutex_unlock(&chip->open_mutex);
     1599    return -EBUSY;
     1600  }
     1601  runtime->hw = azx_pcm_hw;
     1602  runtime->hw.channels_min = hinfo->channels_min;
     1603  runtime->hw.channels_max = hinfo->channels_max;
     1604  runtime->hw.formats = hinfo->formats;
     1605  runtime->hw.rates = hinfo->rates;
     1606  snd_pcm_limit_hw_rates(runtime);
     1607  snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
     1608  snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
     1609           128);
     1610  snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
     1611           128);
     1612  snd_hda_power_up(apcm->codec);
     1613  err = hinfo->ops.open(hinfo, apcm->codec, substream);
     1614  if (err < 0) {
     1615    azx_release_device(azx_dev);
     1616    snd_hda_power_down(apcm->codec);
     1617    mutex_unlock(&chip->open_mutex);
     1618    return err;
     1619  }
     1620  snd_pcm_limit_hw_rates(runtime);
     1621  /* sanity check */
     1622  if (snd_BUG_ON(!runtime->hw.channels_min) ||
     1623      snd_BUG_ON(!runtime->hw.channels_max) ||
     1624      snd_BUG_ON(!runtime->hw.formats) ||
     1625      snd_BUG_ON(!runtime->hw.rates)) {
     1626    azx_release_device(azx_dev);
     1627    hinfo->ops.close(hinfo, apcm->codec, substream);
     1628    snd_hda_power_down(apcm->codec);
     1629    mutex_unlock(&chip->open_mutex);
     1630    return -EINVAL;
     1631  }
     1632  spin_lock_irqsave(&chip->reg_lock, flags);
     1633  azx_dev->substream = substream;
     1634  azx_dev->running = 0;
     1635  spin_unlock_irqrestore(&chip->reg_lock, flags);
     1636
     1637  runtime->private_data = azx_dev;
     1638  snd_pcm_set_sync(substream);
     1639  mutex_unlock(&chip->open_mutex);
     1640  return 0;
    16391641}
    16401642
    16411643static int azx_pcm_close(struct snd_pcm_substream *substream)
    16421644{
    1643         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1644         struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
    1645         struct azx *chip = apcm->chip;
    1646         struct azx_dev *azx_dev = get_azx_dev(substream);
    1647         unsigned long flags;
    1648 
    1649         mutex_lock(&chip->open_mutex);
    1650         spin_lock_irqsave(&chip->reg_lock, flags);
    1651         azx_dev->substream = NULL;
    1652         azx_dev->running = 0;
    1653         spin_unlock_irqrestore(&chip->reg_lock, flags);
    1654         azx_release_device(azx_dev);
    1655         hinfo->ops.close(hinfo, apcm->codec, substream);
    1656         snd_hda_power_down(apcm->codec);
    1657         mutex_unlock(&chip->open_mutex);
    1658         return 0;
     1645  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1646  struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
     1647  struct azx *chip = apcm->chip;
     1648  struct azx_dev *azx_dev = get_azx_dev(substream);
     1649  unsigned long flags;
     1650
     1651  mutex_lock(&chip->open_mutex);
     1652  spin_lock_irqsave(&chip->reg_lock, flags);
     1653  azx_dev->substream = NULL;
     1654  azx_dev->running = 0;
     1655  spin_unlock_irqrestore(&chip->reg_lock, flags);
     1656  azx_release_device(azx_dev);
     1657  hinfo->ops.close(hinfo, apcm->codec, substream);
     1658  snd_hda_power_down(apcm->codec);
     1659  mutex_unlock(&chip->open_mutex);
     1660  return 0;
    16591661}
    16601662
    16611663static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
    1662                              struct snd_pcm_hw_params *hw_params)
    1663 {
    1664         struct azx_dev *azx_dev = get_azx_dev(substream);
    1665 
    1666         azx_dev->bufsize = 0;
    1667         azx_dev->period_bytes = 0;
    1668         azx_dev->format_val = 0;
    1669         return snd_pcm_lib_malloc_pages(substream,
    1670                                         params_buffer_bytes(hw_params));
     1664           struct snd_pcm_hw_params *hw_params)
     1665{
     1666  struct azx_dev *azx_dev = get_azx_dev(substream);
     1667
     1668  azx_dev->bufsize = 0;
     1669  azx_dev->period_bytes = 0;
     1670  azx_dev->format_val = 0;
     1671  return snd_pcm_lib_malloc_pages(substream,
     1672          params_buffer_bytes(hw_params));
    16711673}
    16721674
    16731675static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
    16741676{
    1675         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1676         struct azx_dev *azx_dev = get_azx_dev(substream);
    1677         struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
    1678 
    1679         /* reset BDL address */
    1680         azx_sd_writel(azx_dev, SD_BDLPL, 0);
    1681         azx_sd_writel(azx_dev, SD_BDLPU, 0);
    1682         azx_sd_writel(azx_dev, SD_CTL, 0);
    1683         azx_dev->bufsize = 0;
    1684         azx_dev->period_bytes = 0;
    1685         azx_dev->format_val = 0;
    1686 
    1687         snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
    1688 
    1689         return snd_pcm_lib_free_pages(substream);
     1677  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1678  struct azx_dev *azx_dev = get_azx_dev(substream);
     1679  struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
     1680
     1681  /* reset BDL address */
     1682  azx_sd_writel(azx_dev, SD_BDLPL, 0);
     1683  azx_sd_writel(azx_dev, SD_BDLPU, 0);
     1684  azx_sd_writel(azx_dev, SD_CTL, 0);
     1685  azx_dev->bufsize = 0;
     1686  azx_dev->period_bytes = 0;
     1687  azx_dev->format_val = 0;
     1688
     1689  snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
     1690
     1691  return snd_pcm_lib_free_pages(substream);
    16901692}
    16911693
    16921694static int azx_pcm_prepare(struct snd_pcm_substream *substream)
    16931695{
    1694         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1695         struct azx *chip = apcm->chip;
    1696         struct azx_dev *azx_dev = get_azx_dev(substream);
    1697         struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
    1698         struct snd_pcm_runtime *runtime = substream->runtime;
    1699         unsigned int bufsize, period_bytes, format_val, stream_tag;
    1700         int err;
    1701 
    1702         azx_stream_reset(chip, azx_dev);
    1703         format_val = snd_hda_calc_stream_format(runtime->rate,
    1704                                                 runtime->channels,
    1705                                                 runtime->format,
    1706                                                 hinfo->maxbps,
    1707                                                 apcm->codec->spdif_ctls);
    1708         if (!format_val) {
    1709                 snd_printk(KERN_ERR SFX
    1710                            "invalid format_val, rate=%d, ch=%d, format=%d\n",
    1711                            runtime->rate, runtime->channels, runtime->format);
    1712                 return -EINVAL;
    1713         }
    1714 
    1715         bufsize = snd_pcm_lib_buffer_bytes(substream);
    1716         period_bytes = snd_pcm_lib_period_bytes(substream);
    1717 
    1718         snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
    1719                     bufsize, format_val);
    1720 
    1721         if (bufsize != azx_dev->bufsize ||
    1722             period_bytes != azx_dev->period_bytes ||
    1723             format_val != azx_dev->format_val) {
    1724                 azx_dev->bufsize = bufsize;
    1725                 azx_dev->period_bytes = period_bytes;
    1726                 azx_dev->format_val = format_val;
    1727                 err = azx_setup_periods(chip, substream, azx_dev);
    1728                 if (err < 0)
    1729                         return err;
    1730         }
    1731 
    1732         /* wallclk has 24Mhz clock source */
    1733         azx_dev->period_wallclk = (((runtime->period_size * 24000) /
    1734                                                 runtime->rate) * 1000);
    1735         azx_setup_controller(chip, azx_dev);
    1736         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
    1737                 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
    1738         else
    1739                 azx_dev->fifo_size = 0;
    1740 
    1741         stream_tag = azx_dev->stream_tag;
    1742         /* CA-IBG chips need the playback stream starting from 1 */
    1743         if (chip->driver_type == AZX_DRIVER_CTX &&
    1744             stream_tag > chip->capture_streams)
    1745                 stream_tag -= chip->capture_streams;
    1746         return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
    1747                                      azx_dev->format_val, substream);
     1696  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1697  struct azx *chip = apcm->chip;
     1698  struct azx_dev *azx_dev = get_azx_dev(substream);
     1699  struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
     1700  struct snd_pcm_runtime *runtime = substream->runtime;
     1701  unsigned int bufsize, period_bytes, format_val, stream_tag;
     1702  int err;
     1703
     1704  azx_stream_reset(chip, azx_dev);
     1705  format_val = snd_hda_calc_stream_format(runtime->rate,
     1706            runtime->channels,
     1707            runtime->format,
     1708            hinfo->maxbps,
     1709            apcm->codec->spdif_ctls);
     1710  if (!format_val) {
     1711    snd_printk(KERN_ERR SFX
     1712         "invalid format_val, rate=%d, ch=%d, format=%d\n",
     1713         runtime->rate, runtime->channels, runtime->format);
     1714    return -EINVAL;
     1715  }
     1716
     1717  bufsize = snd_pcm_lib_buffer_bytes(substream);
     1718  period_bytes = snd_pcm_lib_period_bytes(substream);
     1719
     1720  snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
     1721        bufsize, format_val);
     1722
     1723  if (bufsize != azx_dev->bufsize ||
     1724      period_bytes != azx_dev->period_bytes ||
     1725      format_val != azx_dev->format_val) {
     1726    azx_dev->bufsize = bufsize;
     1727    azx_dev->period_bytes = period_bytes;
     1728    azx_dev->format_val = format_val;
     1729    err = azx_setup_periods(chip, substream, azx_dev);
     1730    if (err < 0)
     1731      return err;
     1732  }
     1733
     1734  /* wallclk has 24Mhz clock source */
     1735  azx_dev->period_wallclk = (((runtime->period_size * 24000) /
     1736            runtime->rate) * 1000);
     1737  azx_setup_controller(chip, azx_dev);
     1738  if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
     1739    azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
     1740  else
     1741    azx_dev->fifo_size = 0;
     1742
     1743  stream_tag = azx_dev->stream_tag;
     1744  /* CA-IBG chips need the playback stream starting from 1 */
     1745  if (chip->driver_type == AZX_DRIVER_CTX &&
     1746      stream_tag > chip->capture_streams)
     1747    stream_tag -= chip->capture_streams;
     1748  return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
     1749             azx_dev->format_val, substream);
    17481750}
    17491751
    17501752static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
    17511753{
    1752         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1753         struct azx *chip = apcm->chip;
    1754         struct azx_dev *azx_dev;
    1755         struct snd_pcm_substream *s;
    1756         int rstart = 0, start, nsync = 0, sbits = 0;
    1757         int nwait, timeout;
    1758 
    1759         switch (cmd) {
    1760         case SNDRV_PCM_TRIGGER_START:
    1761                 rstart = 1;
    1762         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    1763         case SNDRV_PCM_TRIGGER_RESUME:
    1764                 start = 1;
    1765                 break;
    1766         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    1767         case SNDRV_PCM_TRIGGER_SUSPEND:
    1768         case SNDRV_PCM_TRIGGER_STOP:
    1769                 start = 0;
    1770                 break;
    1771         default:
    1772                 return -EINVAL;
    1773         }
    1774 
    1775         snd_pcm_group_for_each_entry(s, substream) {
    1776                 if (s->pcm->card != substream->pcm->card)
    1777                         continue;
    1778                 azx_dev = get_azx_dev(s);
    1779                 sbits |= 1 << azx_dev->index;
    1780                 nsync++;
    1781                 snd_pcm_trigger_done(s, substream);
    1782         }
    1783 
    1784         spin_lock(&chip->reg_lock);
    1785         if (nsync > 1) {
    1786                 /* first, set SYNC bits of corresponding streams */
    1787                 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
    1788         }
    1789         snd_pcm_group_for_each_entry(s, substream) {
    1790                 if (s->pcm->card != substream->pcm->card)
    1791                         continue;
    1792                 azx_dev = get_azx_dev(s);
    1793                 if (start) {
    1794                         azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
    1795                         if (!rstart)
    1796                                 azx_dev->start_wallclk -=
    1797                                                 azx_dev->period_wallclk;
    1798                         azx_stream_start(chip, azx_dev);
    1799                 } else {
    1800                         azx_stream_stop(chip, azx_dev);
    1801                 }
    1802                 azx_dev->running = start;
    1803         }
    1804         spin_unlock(&chip->reg_lock);
    1805         if (start) {
    1806                 if (nsync == 1)
    1807                         return 0;
    1808                 /* wait until all FIFOs get ready */
    1809                 for (timeout = 5000; timeout; timeout--) {
    1810                         nwait = 0;
    1811                         snd_pcm_group_for_each_entry(s, substream) {
    1812                                 if (s->pcm->card != substream->pcm->card)
    1813                                         continue;
    1814                                 azx_dev = get_azx_dev(s);
    1815                                 if (!(azx_sd_readb(azx_dev, SD_STS) &
    1816                                       SD_STS_FIFO_READY))
    1817                                         nwait++;
    1818                         }
    1819                         if (!nwait)
    1820                                 break;
    1821                         cpu_relax();
    1822                 }
    1823         } else {
    1824                 /* wait until all RUN bits are cleared */
    1825                 for (timeout = 5000; timeout; timeout--) {
    1826                         nwait = 0;
    1827                         snd_pcm_group_for_each_entry(s, substream) {
    1828                                 if (s->pcm->card != substream->pcm->card)
    1829                                         continue;
    1830                                 azx_dev = get_azx_dev(s);
    1831                                 if (azx_sd_readb(azx_dev, SD_CTL) &
    1832                                     SD_CTL_DMA_START)
    1833                                         nwait++;
    1834                         }
    1835                         if (!nwait)
    1836                                 break;
    1837                         cpu_relax();
    1838                 }
    1839         }
    1840         if (nsync > 1) {
    1841                 spin_lock(&chip->reg_lock);
    1842                 /* reset SYNC bits */
    1843                 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
    1844                 spin_unlock(&chip->reg_lock);
    1845         }
    1846         return 0;
     1754  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1755  struct azx *chip = apcm->chip;
     1756  struct azx_dev *azx_dev;
     1757  struct snd_pcm_substream *s;
     1758  int rstart = 0, start, nsync = 0, sbits = 0;
     1759  int nwait, timeout;
     1760
     1761  switch (cmd) {
     1762  case SNDRV_PCM_TRIGGER_START:
     1763    rstart = 1;
     1764  case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     1765  case SNDRV_PCM_TRIGGER_RESUME:
     1766    start = 1;
     1767    break;
     1768  case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     1769  case SNDRV_PCM_TRIGGER_SUSPEND:
     1770  case SNDRV_PCM_TRIGGER_STOP:
     1771    start = 0;
     1772    break;
     1773  default:
     1774    return -EINVAL;
     1775  }
     1776
     1777  snd_pcm_group_for_each_entry(s, substream) {
     1778    if (s->pcm->card != substream->pcm->card)
     1779      continue;
     1780    azx_dev = get_azx_dev(s);
     1781    sbits |= 1 << azx_dev->index;
     1782    nsync++;
     1783    snd_pcm_trigger_done(s, substream);
     1784  }
     1785
     1786  spin_lock(&chip->reg_lock);
     1787  if (nsync > 1) {
     1788    /* first, set SYNC bits of corresponding streams */
     1789    azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
     1790  }
     1791  snd_pcm_group_for_each_entry(s, substream) {
     1792    if (s->pcm->card != substream->pcm->card)
     1793      continue;
     1794    azx_dev = get_azx_dev(s);
     1795    if (start) {
     1796      azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
     1797      if (!rstart)
     1798        azx_dev->start_wallclk -=
     1799            azx_dev->period_wallclk;
     1800      azx_stream_start(chip, azx_dev);
     1801    } else {
     1802      azx_stream_stop(chip, azx_dev);
     1803    }
     1804    azx_dev->running = start;
     1805  }
     1806  spin_unlock(&chip->reg_lock);
     1807  if (start) {
     1808    if (nsync == 1)
     1809      return 0;
     1810    /* wait until all FIFOs get ready */
     1811    for (timeout = 5000; timeout; timeout--) {
     1812      nwait = 0;
     1813      snd_pcm_group_for_each_entry(s, substream) {
     1814        if (s->pcm->card != substream->pcm->card)
     1815          continue;
     1816        azx_dev = get_azx_dev(s);
     1817        if (!(azx_sd_readb(azx_dev, SD_STS) &
     1818              SD_STS_FIFO_READY))
     1819          nwait++;
     1820      }
     1821      if (!nwait)
     1822        break;
     1823      cpu_relax();
     1824    }
     1825  } else {
     1826    /* wait until all RUN bits are cleared */
     1827    for (timeout = 5000; timeout; timeout--) {
     1828      nwait = 0;
     1829      snd_pcm_group_for_each_entry(s, substream) {
     1830        if (s->pcm->card != substream->pcm->card)
     1831          continue;
     1832        azx_dev = get_azx_dev(s);
     1833        if (azx_sd_readb(azx_dev, SD_CTL) &
     1834            SD_CTL_DMA_START)
     1835          nwait++;
     1836      }
     1837      if (!nwait)
     1838        break;
     1839      cpu_relax();
     1840    }
     1841  }
     1842  if (nsync > 1) {
     1843    spin_lock(&chip->reg_lock);
     1844    /* reset SYNC bits */
     1845    azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
     1846    spin_unlock(&chip->reg_lock);
     1847  }
     1848  return 0;
    18471849}
    18481850
    18491851/* get the current DMA position with correction on VIA chips */
    18501852static unsigned int azx_via_get_position(struct azx *chip,
    1851                                         struct azx_dev *azx_dev)
    1852 {
    1853         unsigned int link_pos, mini_pos, bound_pos;
    1854         unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
    1855         unsigned int fifo_size;
    1856 
    1857         link_pos = azx_sd_readl(azx_dev, SD_LPIB);
    1858         if (azx_dev->index >= 4) {
    1859                 /* Playback, no problem using link position */
    1860                 return link_pos;
    1861         }
    1862 
    1863         /* Capture */
    1864         /* For new chipset,
    1865         * use mod to get the DMA position just like old chipset
    1866         */
    1867         mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
    1868         mod_dma_pos %= azx_dev->period_bytes;
    1869 
    1870         /* azx_dev->fifo_size can't get FIFO size of in stream.
    1871         * Get from base address + offset.
    1872         */
    1873         fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
    1874 
    1875         if (azx_dev->insufficient) {
    1876                 /* Link position never gather than FIFO size */
    1877                 if (link_pos <= fifo_size)
    1878                         return 0;
    1879 
    1880                 azx_dev->insufficient = 0;
    1881         }
    1882 
    1883         if (link_pos <= fifo_size)
    1884                 mini_pos = azx_dev->bufsize + link_pos - fifo_size;
    1885         else
    1886                 mini_pos = link_pos - fifo_size;
    1887 
    1888         /* Find nearest previous boudary */
    1889         mod_mini_pos = mini_pos % azx_dev->period_bytes;
    1890         mod_link_pos = link_pos % azx_dev->period_bytes;
    1891         if (mod_link_pos >= fifo_size)
    1892                 bound_pos = link_pos - mod_link_pos;
    1893         else if (mod_dma_pos >= mod_mini_pos)
    1894                 bound_pos = mini_pos - mod_mini_pos;
    1895         else {
    1896                 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
    1897                 if (bound_pos >= azx_dev->bufsize)
    1898                         bound_pos = 0;
    1899         }
    1900 
    1901         /* Calculate real DMA position we want */
    1902         return bound_pos + mod_dma_pos;
     1853          struct azx_dev *azx_dev)
     1854{
     1855  unsigned int link_pos, mini_pos, bound_pos;
     1856  unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
     1857  unsigned int fifo_size;
     1858
     1859  link_pos = azx_sd_readl(azx_dev, SD_LPIB);
     1860  if (azx_dev->index >= 4) {
     1861    /* Playback, no problem using link position */
     1862    return link_pos;
     1863  }
     1864
     1865  /* Capture */
     1866  /* For new chipset,
     1867  * use mod to get the DMA position just like old chipset
     1868  */
     1869  mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
     1870  mod_dma_pos %= azx_dev->period_bytes;
     1871
     1872  /* azx_dev->fifo_size can't get FIFO size of in stream.
     1873  * Get from base address + offset.
     1874  */
     1875  fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
     1876
     1877  if (azx_dev->insufficient) {
     1878    /* Link position never gather than FIFO size */
     1879    if (link_pos <= fifo_size)
     1880      return 0;
     1881
     1882    azx_dev->insufficient = 0;
     1883  }
     1884
     1885  if (link_pos <= fifo_size)
     1886    mini_pos = azx_dev->bufsize + link_pos - fifo_size;
     1887  else
     1888    mini_pos = link_pos - fifo_size;
     1889
     1890  /* Find nearest previous boudary */
     1891  mod_mini_pos = mini_pos % azx_dev->period_bytes;
     1892  mod_link_pos = link_pos % azx_dev->period_bytes;
     1893  if (mod_link_pos >= fifo_size)
     1894    bound_pos = link_pos - mod_link_pos;
     1895  else if (mod_dma_pos >= mod_mini_pos)
     1896    bound_pos = mini_pos - mod_mini_pos;
     1897  else {
     1898    bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
     1899    if (bound_pos >= azx_dev->bufsize)
     1900      bound_pos = 0;
     1901  }
     1902
     1903  /* Calculate real DMA position we want */
     1904  return bound_pos + mod_dma_pos;
    19031905}
    19041906
    19051907static unsigned int azx_get_position(struct azx *chip,
    1906                                      struct azx_dev *azx_dev)
    1907 {
    1908         unsigned int pos;
    1909         int stream = azx_dev->substream->stream;
    1910 
    1911         switch (chip->position_fix[stream]) {
    1912         case POS_FIX_LPIB:
    1913                 /* read LPIB */
    1914                 pos = azx_sd_readl(azx_dev, SD_LPIB);
    1915                 break;
    1916         case POS_FIX_VIACOMBO:
    1917                 pos = azx_via_get_position(chip, azx_dev);
    1918                 break;
    1919         default:
    1920                 /* use the position buffer */
    1921                 pos = le32_to_cpu(*azx_dev->posbuf);
    1922         }
    1923 
    1924         if (pos >= azx_dev->bufsize)
    1925                 pos = 0;
    1926         return pos;
     1908             struct azx_dev *azx_dev)
     1909{
     1910  unsigned int pos;
     1911  int stream = azx_dev->substream->stream;
     1912
     1913  switch (chip->position_fix[stream]) {
     1914  case POS_FIX_LPIB:
     1915    /* read LPIB */
     1916    pos = azx_sd_readl(azx_dev, SD_LPIB);
     1917    break;
     1918  case POS_FIX_VIACOMBO:
     1919    pos = azx_via_get_position(chip, azx_dev);
     1920    break;
     1921  default:
     1922    /* use the position buffer */
     1923    pos = le32_to_cpu(*azx_dev->posbuf);
     1924  }
     1925
     1926  if (pos >= azx_dev->bufsize)
     1927    pos = 0;
     1928  return pos;
    19271929}
    19281930
    19291931static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
    19301932{
    1931         struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
    1932         struct azx *chip = apcm->chip;
    1933         struct azx_dev *azx_dev = get_azx_dev(substream);
    1934         return bytes_to_frames(substream->runtime,
    1935                                azx_get_position(chip, azx_dev));
     1933  struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
     1934  struct azx *chip = apcm->chip;
     1935  struct azx_dev *azx_dev = get_azx_dev(substream);
     1936  return bytes_to_frames(substream->runtime,
     1937             azx_get_position(chip, azx_dev));
    19361938}
    19371939
     
    19471949static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
    19481950{
    1949         u32 wallclk;
    1950         unsigned int pos;
    1951         int stream;
    1952 
    1953         wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
    1954         if (wallclk < (azx_dev->period_wallclk * 2) / 3)
    1955                 return -1;      /* bogus (too early) interrupt */
    1956 
    1957         stream = azx_dev->substream->stream;
    1958         pos = azx_get_position(chip, azx_dev);
    1959         if (chip->position_fix[stream] == POS_FIX_AUTO) {
    1960                 if (!pos) {
    1961                         printk(KERN_WARNING
    1962                                "hda-intel: Invalid position buffer, "
    1963                                "using LPIB read method instead.\n");
    1964                         chip->position_fix[stream] = POS_FIX_LPIB;
    1965                         pos = azx_get_position(chip, azx_dev);
    1966                 } else
    1967                         chip->position_fix[stream] = POS_FIX_POSBUF;
    1968         }
     1951  u32 wallclk;
     1952  unsigned int pos;
     1953  int stream;
     1954
     1955  wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
     1956  if (wallclk < (azx_dev->period_wallclk * 2) / 3)
     1957    return -1;  /* bogus (too early) interrupt */
     1958
     1959  stream = azx_dev->substream->stream;
     1960  pos = azx_get_position(chip, azx_dev);
     1961  if (chip->position_fix[stream] == POS_FIX_AUTO) {
     1962    if (!pos) {
     1963      printk(KERN_WARNING
     1964             "hda-intel: Invalid position buffer, "
     1965             "using LPIB read method instead.\n");
     1966      chip->position_fix[stream] = POS_FIX_LPIB;
     1967      pos = azx_get_position(chip, azx_dev);
     1968    } else
     1969      chip->position_fix[stream] = POS_FIX_POSBUF;
     1970  }
    19691971
    19701972#ifndef TARGET_OS2
    1971         if (WARN_ONCE(!azx_dev->period_bytes,
    1972                       "hda-intel: zero azx_dev->period_bytes"))
    1973                 return -1; /* this shouldn't happen! */
     1973  if (WARN_ONCE(!azx_dev->period_bytes,
     1974          "hda-intel: zero azx_dev->period_bytes"))
     1975    return -1; /* this shouldn't happen! */
    19741976#endif
    1975         if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
    1976             pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
    1977                 /* NG - it's below the first next period boundary */
    1978                 return bdl_pos_adj[chip->dev_index] ? 0 : -1;
    1979         azx_dev->start_wallclk += wallclk;
    1980         return 1; /* OK, it's fine */
     1977  if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
     1978      pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
     1979    /* NG - it's below the first next period boundary */
     1980    return bdl_pos_adj[chip->dev_index] ? 0 : -1;
     1981  azx_dev->start_wallclk += wallclk;
     1982  return 1; /* OK, it's fine */
    19811983}
    19821984
     
    19861988static void azx_irq_pending_work(struct work_struct *work)
    19871989{
    1988         struct azx *chip = container_of(work, struct azx, irq_pending_work);
    1989         int i, pending, ok;
    1990 
    1991         if (!chip->irq_pending_warned) {
    1992                 printk(KERN_WARNING
    1993                        "hda-intel: IRQ timing workaround is activated "
    1994                        "for card #%d. Suggest a bigger bdl_pos_adj.\n",
    1995                        chip->card->number);
    1996                 chip->irq_pending_warned = 1;
    1997         }
    1998 
    1999         for (;;) {
    2000                 pending = 0;
    2001                 spin_lock_irq(&chip->reg_lock);
    2002                 for (i = 0; i < chip->num_streams; i++) {
    2003                         struct azx_dev *azx_dev = &chip->azx_dev[i];
    2004                         if (!azx_dev->irq_pending ||
    2005                             !azx_dev->substream ||
    2006                             !azx_dev->running)
    2007                                 continue;
    2008                         ok = azx_position_ok(chip, azx_dev);
    2009                         if (ok > 0) {
    2010                                 azx_dev->irq_pending = 0;
    2011                                 spin_unlock(&chip->reg_lock);
    2012                                 snd_pcm_period_elapsed(azx_dev->substream);
    2013                                 spin_lock(&chip->reg_lock);
    2014                         } else if (ok < 0) {
    2015                                 pending = 0;    /* too early */
    2016                         } else
    2017                                 pending++;
    2018                 }
    2019                 spin_unlock_irq(&chip->reg_lock);
    2020                 if (!pending)
    2021                         return;
    2022                 msleep(1);
    2023         }
     1990  struct azx *chip = container_of(work, struct azx, irq_pending_work);
     1991  int i, pending, ok;
     1992
     1993  if (!chip->irq_pending_warned) {
     1994    printk(KERN_WARNING
     1995           "hda-intel: IRQ timing workaround is activated "
     1996           "for card #%d. Suggest a bigger bdl_pos_adj.\n",
     1997           chip->card->number);
     1998    chip->irq_pending_warned = 1;
     1999  }
     2000
     2001  for (;;) {
     2002    pending = 0;
     2003    spin_lock_irq(&chip->reg_lock);
     2004    for (i = 0; i < chip->num_streams; i++) {
     2005      struct azx_dev *azx_dev = &chip->azx_dev[i];
     2006      if (!azx_dev->irq_pending ||
     2007          !azx_dev->substream ||
     2008          !azx_dev->running)
     2009        continue;
     2010      ok = azx_position_ok(chip, azx_dev);
     2011      if (ok > 0) {
     2012        azx_dev->irq_pending = 0;
     2013        spin_unlock(&chip->reg_lock);
     2014        snd_pcm_period_elapsed(azx_dev->substream);
     2015        spin_lock(&chip->reg_lock);
     2016      } else if (ok < 0) {
     2017        pending = 0;  /* too early */
     2018      } else
     2019        pending++;
     2020    }
     2021    spin_unlock_irq(&chip->reg_lock);
     2022    if (!pending)
     2023      return;
     2024    msleep(1);
     2025  }
    20242026}
    20252027
     
    20272029static void azx_clear_irq_pending(struct azx *chip)
    20282030{
    2029         int i;
    2030 
    2031         spin_lock_irq(&chip->reg_lock);
    2032         for (i = 0; i < chip->num_streams; i++)
    2033                 chip->azx_dev[i].irq_pending = 0;
    2034         spin_unlock_irq(&chip->reg_lock);
     2031  int i;
     2032
     2033  spin_lock_irq(&chip->reg_lock);
     2034  for (i = 0; i < chip->num_streams; i++)
     2035    chip->azx_dev[i].irq_pending = 0;
     2036  spin_unlock_irq(&chip->reg_lock);
    20352037}
    20362038
    20372039static struct snd_pcm_ops azx_pcm_ops = {
    2038         .open = azx_pcm_open,
    2039         .close = azx_pcm_close,
    2040         .ioctl = snd_pcm_lib_ioctl,
    2041         .hw_params = azx_pcm_hw_params,
    2042         .hw_free = azx_pcm_hw_free,
    2043         .prepare = azx_pcm_prepare,
    2044         .trigger = azx_pcm_trigger,
    2045         .pointer = azx_pcm_pointer,
    2046         .page = snd_pcm_sgbuf_ops_page,
     2040  .open = azx_pcm_open,
     2041  .close = azx_pcm_close,
     2042  .ioctl = snd_pcm_lib_ioctl,
     2043  .hw_params = azx_pcm_hw_params,
     2044  .hw_free = azx_pcm_hw_free,
     2045  .prepare = azx_pcm_prepare,
     2046  .trigger = azx_pcm_trigger,
     2047  .pointer = azx_pcm_pointer,
     2048  .page = snd_pcm_sgbuf_ops_page,
    20472049};
    20482050
    20492051static void azx_pcm_free(struct snd_pcm *pcm)
    20502052{
    2051         struct azx_pcm *apcm = pcm->private_data;
    2052         if (apcm) {
    2053                 apcm->chip->pcm[pcm->device] = NULL;
    2054                 kfree(apcm);
    2055         }
     2053  struct azx_pcm *apcm = pcm->private_data;
     2054  if (apcm) {
     2055    apcm->chip->pcm[pcm->device] = NULL;
     2056    kfree(apcm);
     2057  }
    20562058}
    20572059
    20582060static int
    20592061azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
    2060                       struct hda_pcm *cpcm)
    2061 {
    2062         struct azx *chip = bus->private_data;
    2063         struct snd_pcm *pcm;
    2064         struct azx_pcm *apcm;
    2065         int pcm_dev = cpcm->device;
    2066         int s, err;
    2067 
    2068         if (pcm_dev >= HDA_MAX_PCMS) {
    2069                 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
    2070                            pcm_dev);
    2071                 return -EINVAL;
    2072         }
    2073         if (chip->pcm[pcm_dev]) {
    2074                 snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
    2075                 return -EBUSY;
    2076         }
    2077         err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
    2078                           cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
    2079                           cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
    2080                           &pcm);
    2081         if (err < 0)
    2082                 return err;
    2083         strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
    2084         apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
    2085         if (apcm == NULL)
    2086                 return -ENOMEM;
    2087         apcm->chip = chip;
    2088         apcm->codec = codec;
    2089         pcm->private_data = apcm;
    2090         pcm->private_free = azx_pcm_free;
    2091         if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
    2092                 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
    2093         chip->pcm[pcm_dev] = pcm;
    2094         cpcm->pcm = pcm;
    2095         for (s = 0; s < 2; s++) {
    2096                 apcm->hinfo[s] = &cpcm->stream[s];
    2097                 if (cpcm->stream[s].substreams)
    2098                         snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
    2099         }
    2100         /* buffer pre-allocation */
    2101         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
    2102                                               snd_dma_pci_data(chip->pci),
    2103                                               1024 * 64, 32 * 1024 * 1024);
    2104         return 0;
     2062          struct hda_pcm *cpcm)
     2063{
     2064  struct azx *chip = bus->private_data;
     2065  struct snd_pcm *pcm;
     2066  struct azx_pcm *apcm;
     2067  int pcm_dev = cpcm->device;
     2068  int s, err;
     2069
     2070  if (pcm_dev >= HDA_MAX_PCMS) {
     2071    snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",
     2072         pcm_dev);
     2073    return -EINVAL;
     2074  }
     2075  if (chip->pcm[pcm_dev]) {
     2076    snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);
     2077    return -EBUSY;
     2078  }
     2079  err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
     2080        cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
     2081        cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
     2082        &pcm);
     2083  if (err < 0)
     2084    return err;
     2085  strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
     2086  apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
     2087  if (apcm == NULL)
     2088    return -ENOMEM;
     2089  apcm->chip = chip;
     2090  apcm->codec = codec;
     2091  pcm->private_data = apcm;
     2092  pcm->private_free = azx_pcm_free;
     2093  if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
     2094    pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
     2095  chip->pcm[pcm_dev] = pcm;
     2096  cpcm->pcm = pcm;
     2097  for (s = 0; s < 2; s++) {
     2098    apcm->hinfo[s] = &cpcm->stream[s];
     2099    if (cpcm->stream[s].substreams)
     2100      snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
     2101  }
     2102  /* buffer pre-allocation */
     2103  snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
     2104                snd_dma_pci_data(chip->pci),
     2105                1024 * 64, 32 * 1024 * 1024);
     2106  return 0;
    21052107}
    21062108
     
    21102112static int __devinit azx_mixer_create(struct azx *chip)
    21112113{
    2112         return snd_hda_build_controls(chip->bus);
     2114  return snd_hda_build_controls(chip->bus);
    21132115}
    21142116
     
    21192121static int __devinit azx_init_stream(struct azx *chip)
    21202122{
    2121         int i;
    2122 
    2123         /* initialize each stream (aka device)
    2124         * assign the starting bdl address to each stream (device)
    2125         * and initialize
    2126         */
    2127         for (i = 0; i < chip->num_streams; i++) {
    2128                 struct azx_dev *azx_dev = &chip->azx_dev[i];
    2129                 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
    2130                 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
    2131                 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
    2132                 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
    2133                 azx_dev->sd_int_sta_mask = 1 << i;
    2134                 /* stream tag: must be non-zero and unique */
    2135                 azx_dev->index = i;
    2136                 azx_dev->stream_tag = i + 1;
    2137         }
    2138 
    2139         return 0;
     2123  int i;
     2124
     2125  /* initialize each stream (aka device)
     2126  * assign the starting bdl address to each stream (device)
     2127  * and initialize
     2128  */
     2129  for (i = 0; i < chip->num_streams; i++) {
     2130    struct azx_dev *azx_dev = &chip->azx_dev[i];
     2131    azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
     2132    /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
     2133    azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
     2134    /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
     2135    azx_dev->sd_int_sta_mask = 1 << i;
     2136    /* stream tag: must be non-zero and unique */
     2137    azx_dev->index = i;
     2138    azx_dev->stream_tag = i + 1;
     2139  }
     2140
     2141  return 0;
    21402142}
    21412143
    21422144static int azx_acquire_irq(struct azx *chip, int do_disconnect)
    21432145{
    2144         if (request_irq(chip->pci->irq, azx_interrupt,
    2145                         chip->msi ? 0 : IRQF_SHARED,
    2146                         "hda_intel", chip)) {
    2147                 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
    2148                        "disabling device\n", chip->pci->irq);
     2146  if (request_irq(chip->pci->irq, azx_interrupt,
     2147      chip->msi ? 0 : IRQF_SHARED,
     2148      "hda_intel", chip)) {
     2149    printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "
     2150           "disabling device\n", chip->pci->irq);
    21492151#ifndef TARGET_OS2
    2150                 if (do_disconnect)
    2151                         snd_card_disconnect(chip->card);
     2152    if (do_disconnect)
     2153      snd_card_disconnect(chip->card);
    21522154#endif
    2153                 return -1;
    2154         }
    2155         chip->irq = chip->pci->irq;
    2156         pci_intx(chip->pci, !chip->msi);
    2157         return 0;
     2155    return -1;
     2156  }
     2157  chip->irq = chip->pci->irq;
     2158  pci_intx(chip->pci, !chip->msi);
     2159  return 0;
    21582160}
    21592161
     
    21612163static void azx_stop_chip(struct azx *chip)
    21622164{
    2163         if (!chip->initialized)
    2164                 return;
    2165 
    2166         /* disable interrupts */
    2167         azx_int_disable(chip);
    2168         azx_int_clear(chip);
    2169 
    2170         /* disable CORB/RIRB */
    2171         azx_free_cmd_io(chip);
    2172 
    2173         /* disable position buffer */
    2174         azx_writel(chip, DPLBASE, 0);
    2175         azx_writel(chip, DPUBASE, 0);
    2176 
    2177         chip->initialized = 0;
     2165  if (!chip->initialized)
     2166    return;
     2167
     2168  /* disable interrupts */
     2169  azx_int_disable(chip);
     2170  azx_int_clear(chip);
     2171
     2172  /* disable CORB/RIRB */
     2173  azx_free_cmd_io(chip);
     2174
     2175  /* disable position buffer */
     2176  azx_writel(chip, DPLBASE, 0);
     2177  azx_writel(chip, DPUBASE, 0);
     2178
     2179  chip->initialized = 0;
    21782180}
    21792181
     
    21822184static void azx_power_notify(struct hda_bus *bus)
    21832185{
    2184         struct azx *chip = bus->private_data;
    2185         struct hda_codec *c;
    2186         int power_on = 0;
    2187 
    2188         list_for_each_entry(c, &bus->codec_list, list, struct hda_codec) {
    2189                 if (c->power_on) {
    2190                         power_on = 1;
    2191                         break;
    2192                 }
    2193         }
    2194         if (power_on)
    2195                 azx_init_chip(chip, 1);
    2196         else if (chip->running && power_save_controller &&
    2197                 !bus->power_keep_link_on)
    2198                 azx_stop_chip(chip);
     2186  struct azx *chip = bus->private_data;
     2187  struct hda_codec *c;
     2188  int power_on = 0;
     2189
     2190  list_for_each_entry(c, &bus->codec_list, list, struct hda_codec) {
     2191    if (c->power_on) {
     2192      power_on = 1;
     2193      break;
     2194    }
     2195  }
     2196  if (power_on)
     2197    azx_init_chip(chip, 1);
     2198  else if (chip->running && power_save_controller &&
     2199    !bus->power_keep_link_on)
     2200    azx_stop_chip(chip);
    21992201}
    22002202#endif /* CONFIG_SND_HDA_POWER_SAVE */
     
    22072209static int snd_hda_codecs_inuse(struct hda_bus *bus)
    22082210{
    2209         struct hda_codec *codec;
    2210 
    2211         list_for_each_entry(codec, &bus->codec_list, list, struct hda_codec) {
    2212                 if (snd_hda_codec_needs_resume(codec))
    2213                         return 1;
    2214         }
    2215         return 0;
     2211  struct hda_codec *codec;
     2212
     2213  list_for_each_entry(codec, &bus->codec_list, list, struct hda_codec) {
     2214    if (snd_hda_codec_needs_resume(codec))
     2215      return 1;
     2216  }
     2217  return 0;
    22162218}
    22172219
    22182220static int azx_suspend(struct pci_dev *pci, pm_message_t state)
    22192221{
    2220         struct snd_card *card = pci_get_drvdata(pci);
    2221         struct azx *chip = card->private_data;
    2222         int i;
    2223 
    2224         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    2225         azx_clear_irq_pending(chip);
    2226         for (i = 0; i < HDA_MAX_PCMS; i++)
    2227                 snd_pcm_suspend_all(chip->pcm[i]);
    2228         if (chip->initialized)
    2229                 snd_hda_suspend(chip->bus);
    2230         azx_stop_chip(chip);
    2231         if (chip->irq >= 0) {
    2232                 free_irq(chip->irq, chip);
    2233                 chip->irq = -1;
    2234         }
    2235         if (chip->msi)
    2236                 pci_disable_msi(chip->pci);
    2237         pci_disable_device(pci);
    2238         pci_save_state(pci);
    2239         pci_set_power_state(pci, pci_choose_state(pci, state));
    2240         return 0;
     2222  struct snd_card *card = pci_get_drvdata(pci);
     2223  struct azx *chip = card->private_data;
     2224  int i;
     2225
     2226  snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
     2227  azx_clear_irq_pending(chip);
     2228  for (i = 0; i < HDA_MAX_PCMS; i++)
     2229    snd_pcm_suspend_all(chip->pcm[i]);
     2230  if (chip->initialized)
     2231    snd_hda_suspend(chip->bus);
     2232  azx_stop_chip(chip);
     2233  if (chip->irq >= 0) {
     2234    free_irq(chip->irq, chip);
     2235    chip->irq = -1;
     2236  }
     2237  if (chip->msi)
     2238    pci_disable_msi(chip->pci);
     2239  pci_disable_device(pci);
     2240  pci_save_state(pci);
     2241  pci_set_power_state(pci, pci_choose_state(pci, state));
     2242  return 0;
    22412243}
    22422244
    22432245static int azx_resume(struct pci_dev *pci)
    22442246{
    2245         struct snd_card *card = pci_get_drvdata(pci);
    2246         struct azx *chip = card->private_data;
    2247 
    2248         pci_set_power_state(pci, PCI_D0);
    2249         pci_restore_state(pci);
    2250         if (pci_enable_device(pci) < 0) {
    2251                 printk(KERN_ERR "hda-intel: pci_enable_device failed, "
    2252                        "disabling device\n");
    2253                 snd_card_disconnect(card);
    2254                 return -EIO;
    2255         }
    2256         pci_set_master(pci);
    2257         if (chip->msi)
    2258                 if (pci_enable_msi(pci) < 0)
    2259                         chip->msi = 0;
    2260         if (azx_acquire_irq(chip, 1) < 0)
    2261                 return -EIO;
    2262         azx_init_pci(chip);
    2263 
    2264         if (snd_hda_codecs_inuse(chip->bus))
    2265                 azx_init_chip(chip, 1);
    2266 
    2267         snd_hda_resume(chip->bus);
    2268         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
    2269         return 0;
     2247  struct snd_card *card = pci_get_drvdata(pci);
     2248  struct azx *chip = card->private_data;
     2249
     2250  pci_set_power_state(pci, PCI_D0);
     2251  pci_restore_state(pci);
     2252  if (pci_enable_device(pci) < 0) {
     2253    printk(KERN_ERR "hda-intel: pci_enable_device failed, "
     2254           "disabling device\n");
     2255    snd_card_disconnect(card);
     2256    return -EIO;
     2257  }
     2258  pci_set_master(pci);
     2259  if (chip->msi)
     2260    if (pci_enable_msi(pci) < 0)
     2261      chip->msi = 0;
     2262  if (azx_acquire_irq(chip, 1) < 0)
     2263    return -EIO;
     2264  azx_init_pci(chip);
     2265
     2266  if (snd_hda_codecs_inuse(chip->bus))
     2267    azx_init_chip(chip, 1);
     2268
     2269  snd_hda_resume(chip->bus);
     2270  snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     2271  return 0;
    22702272}
    22712273#endif /* CONFIG_PM */
     
    22772279static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf)
    22782280{
    2279         struct azx *chip = container_of(nb, struct azx, reboot_notifier);
    2280         snd_hda_bus_reboot_notify(chip->bus);
    2281         azx_stop_chip(chip);
    2282         return NOTIFY_OK;
     2281  struct azx *chip = container_of(nb, struct azx, reboot_notifier);
     2282  snd_hda_bus_reboot_notify(chip->bus);
     2283  azx_stop_chip(chip);
     2284  return NOTIFY_OK;
    22832285}
    22842286
    22852287static void azx_notifier_register(struct azx *chip)
    22862288{
    2287         chip->reboot_notifier.notifier_call = azx_halt;
    2288         register_reboot_notifier(&chip->reboot_notifier);
     2289  chip->reboot_notifier.notifier_call = azx_halt;
     2290  register_reboot_notifier(&chip->reboot_notifier);
    22892291}
    22902292
    22912293static void azx_notifier_unregister(struct azx *chip)
    22922294{
    2293         if (chip->reboot_notifier.notifier_call)
    2294                 unregister_reboot_notifier(&chip->reboot_notifier);
     2295  if (chip->reboot_notifier.notifier_call)
     2296    unregister_reboot_notifier(&chip->reboot_notifier);
    22952297}
    22962298
     
    23002302static int azx_free(struct azx *chip)
    23012303{
    2302         int i;
    2303 
    2304         azx_notifier_unregister(chip);
    2305 
    2306         if (chip->initialized) {
    2307                 azx_clear_irq_pending(chip);
    2308                 for (i = 0; i < chip->num_streams; i++)
    2309                         azx_stream_stop(chip, &chip->azx_dev[i]);
    2310                 azx_stop_chip(chip);
    2311         }
    2312 
    2313         if (chip->irq >= 0)
    2314                 free_irq(chip->irq, (void*)chip);
    2315         if (chip->msi)
    2316                 pci_disable_msi(chip->pci);
    2317         if (chip->remap_addr)
     2304  int i;
     2305
     2306  azx_notifier_unregister(chip);
     2307
     2308  if (chip->initialized) {
     2309    azx_clear_irq_pending(chip);
     2310    for (i = 0; i < chip->num_streams; i++)
     2311      azx_stream_stop(chip, &chip->azx_dev[i]);
     2312    azx_stop_chip(chip);
     2313  }
     2314
     2315  if (chip->irq >= 0)
     2316    free_irq(chip->irq, (void*)chip);
     2317  if (chip->msi)
     2318    pci_disable_msi(chip->pci);
     2319  if (chip->remap_addr)
    23182320#ifdef TARGET_OS2
    2319                 iounmap((void *)chip->remap_addr);
     2321    iounmap((void *)chip->remap_addr);
    23202322#else
    2321                 iounmap(chip->remap_addr);
     2323    iounmap(chip->remap_addr);
    23222324#endif
    2323         if (chip->azx_dev) {
    2324                 for (i = 0; i < chip->num_streams; i++)
    2325                         if (chip->azx_dev[i].bdl.area)
    2326                                 snd_dma_free_pages(&chip->azx_dev[i].bdl);
    2327         }
    2328         if (chip->rb.area)
    2329                 snd_dma_free_pages(&chip->rb);
    2330         if (chip->posbuf.area)
    2331                 snd_dma_free_pages(&chip->posbuf);
    2332         pci_release_regions(chip->pci);
    2333         pci_disable_device(chip->pci);
    2334         kfree(chip->azx_dev);
    2335         kfree(chip);
    2336 
    2337         return 0;
     2325  if (chip->azx_dev) {
     2326    for (i = 0; i < chip->num_streams; i++)
     2327      if (chip->azx_dev[i].bdl.area)
     2328        snd_dma_free_pages(&chip->azx_dev[i].bdl);
     2329  }
     2330  if (chip->rb.area)
     2331    snd_dma_free_pages(&chip->rb);
     2332  if (chip->posbuf.area)
     2333    snd_dma_free_pages(&chip->posbuf);
     2334  pci_release_regions(chip->pci);
     2335  pci_disable_device(chip->pci);
     2336  kfree(chip->azx_dev);
     2337  kfree(chip);
     2338
     2339  return 0;
    23382340}
    23392341
    23402342static int azx_dev_free(struct snd_device *device)
    23412343{
    2342         return azx_free(device->device_data);
     2344  return azx_free(device->device_data);
    23432345}
    23442346
     
    23472349 */
    23482350static struct snd_pci_quirk position_fix_list[] __devinitdata = {
    2349         SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
    2350         SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB),
    2351         SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
    2352         SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
    2353         SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
    2354         SND_PCI_QUIRK(0x1028, 0x0470, "Dell Inspiron 1120", POS_FIX_LPIB),
    2355         SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
    2356         SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
    2357         SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
    2358         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
    2359         SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
    2360         SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
    2361         SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),
    2362         SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
    2363         SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
    2364         SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
    2365         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
    2366         SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
    2367         SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
    2368         SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
    2369         SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
    2370         {0}
     2351  SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),
     2352  SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB),
     2353  SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
     2354  SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
     2355  SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),
     2356  SND_PCI_QUIRK(0x1028, 0x0470, "Dell Inspiron 1120", POS_FIX_LPIB),
     2357  SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
     2358  SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
     2359  SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
     2360  SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),
     2361  SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),
     2362  SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),
     2363  SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),
     2364  SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),
     2365  SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),
     2366  SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),
     2367  SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),
     2368  SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),
     2369  SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),
     2370  SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),
     2371  SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),
     2372  {0}
    23712373};
    23722374
    23732375static int __devinit check_position_fix(struct azx *chip, int fix)
    23742376{
    2375         const struct snd_pci_quirk *q;
    2376 
    2377         switch (fix) {
    2378         case POS_FIX_LPIB:
    2379         case POS_FIX_POSBUF:
    2380         case POS_FIX_VIACOMBO:
    2381                 return fix;
    2382         }
    2383 
    2384         q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
    2385         if (q) {
    2386                 printk(KERN_INFO
    2387                        "hda_intel: position_fix set to %d "
    2388                        "for device %04x:%04x\n",
    2389                        q->value, q->subvendor, q->subdevice);
    2390                 return q->value;
    2391         }
    2392 
    2393         /* Check VIA/ATI HD Audio Controller exist */
    2394         switch (chip->driver_type) {
    2395         case AZX_DRIVER_VIA:
    2396         case AZX_DRIVER_ATI:
    2397                 /* Use link position directly, avoid any transfer problem. */
    2398                 return POS_FIX_VIACOMBO;
    2399         }
    2400 
    2401         return POS_FIX_AUTO;
     2377  const struct snd_pci_quirk *q;
     2378
     2379  switch (fix) {
     2380  case POS_FIX_LPIB:
     2381  case POS_FIX_POSBUF:
     2382  case POS_FIX_VIACOMBO:
     2383    return fix;
     2384  }
     2385
     2386  q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
     2387  if (q) {
     2388    printk(KERN_INFO
     2389           "hda_intel: position_fix set to %d "
     2390           "for device %04x:%04x\n",
     2391           q->value, q->subvendor, q->subdevice);
     2392    return q->value;
     2393  }
     2394
     2395  /* Check VIA/ATI HD Audio Controller exist */
     2396  switch (chip->driver_type) {
     2397  case AZX_DRIVER_VIA:
     2398  case AZX_DRIVER_ATI:
     2399    /* Use link position directly, avoid any transfer problem. */
     2400    return POS_FIX_VIACOMBO;
     2401  }
     2402
     2403  return POS_FIX_AUTO;
    24022404}
    24032405
     
    24062408 */
    24072409static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
    2408         /* Thinkpad often breaks the controller communication when accessing
    2409         * to the non-working (or non-existing) modem codec slot.
    2410         */
    2411         SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
    2412         SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
    2413         SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
    2414         /* broken BIOS */
    2415         SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
    2416         /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
    2417         SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
    2418         /* forced codec slots */
    2419         SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
    2420         SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
    2421         {0}
     2410  /* Thinkpad often breaks the controller communication when accessing
     2411  * to the non-working (or non-existing) modem codec slot.
     2412  */
     2413  SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),
     2414  SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),
     2415  SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),
     2416  /* broken BIOS */
     2417  SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
     2418  /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
     2419  SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
     2420  /* forced codec slots */
     2421  SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),
     2422  SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
     2423  {0}
    24222424};
    24232425
    2424 #define AZX_FORCE_CODEC_MASK    0x100
     2426#define AZX_FORCE_CODEC_MASK  0x100
    24252427
    24262428static void __devinit check_probe_mask(struct azx *chip, int dev)
    24272429{
    2428         const struct snd_pci_quirk *q;
    2429 
    2430         chip->codec_probe_mask = probe_mask[dev];
    2431         if (chip->codec_probe_mask == -1) {
    2432                 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
    2433                 if (q) {
    2434                         printk(KERN_INFO
    2435                                "hda_intel: probe_mask set to 0x%x "
    2436                                "for device %04x:%04x\n",
    2437                                q->value, q->subvendor, q->subdevice);
    2438                         chip->codec_probe_mask = q->value;
    2439                 }
    2440         }
    2441 
    2442         /* check forced option */
    2443         if (chip->codec_probe_mask != -1 &&
    2444             (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
    2445                 chip->codec_mask = chip->codec_probe_mask & 0xff;
    2446                 printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
    2447                        chip->codec_mask);
    2448         }
     2430  const struct snd_pci_quirk *q;
     2431
     2432  chip->codec_probe_mask = probe_mask[dev];
     2433  if (chip->codec_probe_mask == -1) {
     2434    q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
     2435    if (q) {
     2436      printk(KERN_INFO
     2437             "hda_intel: probe_mask set to 0x%x "
     2438             "for device %04x:%04x\n",
     2439             q->value, q->subvendor, q->subdevice);
     2440      chip->codec_probe_mask = q->value;
     2441    }
     2442  }
     2443
     2444  /* check forced option */
     2445  if (chip->codec_probe_mask != -1 &&
     2446      (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
     2447    chip->codec_mask = chip->codec_probe_mask & 0xff;
     2448    printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
     2449           chip->codec_mask);
     2450  }
    24492451}
    24502452
     
    24532455 */
    24542456static struct snd_pci_quirk msi_black_list[] __devinitdata = {
    2455         SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
    2456         SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
    2457         SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
    2458         SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
    2459         SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
    2460         {0}
     2457  SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */
     2458  SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */
     2459  SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */
     2460  SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */
     2461  SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */
     2462  {0}
    24612463};
    24622464
    24632465static void __devinit check_msi(struct azx *chip)
    24642466{
    2465         const struct snd_pci_quirk *q;
    2466 
    2467         if (enable_msi >= 0) {
    2468                 chip->msi = !!enable_msi;
    2469                 return;
    2470         }
    2471         chip->msi = 1;  /* enable MSI as default */
    2472         q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
    2473         if (q) {
    2474                 printk(KERN_INFO
    2475                        "hda_intel: msi for device %04x:%04x set to %d\n",
    2476                        q->subvendor, q->subdevice, q->value);
    2477                 chip->msi = q->value;
    2478                 return;
    2479         }
    2480 
    2481         /* NVidia chipsets seem to cause troubles with MSI */
    2482         if (chip->driver_type == AZX_DRIVER_NVIDIA) {
    2483                 printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
    2484                 chip->msi = 0;
    2485         }
     2467  const struct snd_pci_quirk *q;
     2468
     2469  if (enable_msi >= 0) {
     2470    chip->msi = !!enable_msi;
     2471    return;
     2472  }
     2473  chip->msi = 1;  /* enable MSI as default */
     2474  q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
     2475  if (q) {
     2476    printk(KERN_INFO
     2477           "hda_intel: msi for device %04x:%04x set to %d\n",
     2478           q->subvendor, q->subdevice, q->value);
     2479    chip->msi = q->value;
     2480    return;
     2481  }
     2482
     2483  /* NVidia chipsets seem to cause troubles with MSI */
     2484  if (chip->driver_type == AZX_DRIVER_NVIDIA) {
     2485    printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");
     2486    chip->msi = 0;
     2487  }
    24862488}
    24872489
     
    24912493 */
    24922494static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
    2493                                 int dev, int driver_type,
    2494                                 struct azx **rchip)
    2495 {
    2496         struct azx *chip;
    2497         int i, err;
    2498         unsigned short gcap;
    2499         static struct snd_device_ops ops = {
    2500                 .dev_free = azx_dev_free,
    2501         };
    2502 
    2503         *rchip = NULL;
    2504 
    2505         err = pci_enable_device(pci);
    2506         if (err < 0)
    2507                 return err;
    2508 
    2509         chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    2510         if (!chip) {
    2511                 snd_printk(KERN_ERR SFX "cannot allocate chip\n");
    2512                 pci_disable_device(pci);
    2513                 return -ENOMEM;
    2514         }
    2515 
    2516         spin_lock_init(&chip->reg_lock);
    2517         mutex_init(&chip->open_mutex);
    2518         chip->card = card;
    2519         chip->pci = pci;
    2520         chip->irq = -1;
    2521         chip->driver_type = driver_type;
    2522         check_msi(chip);
    2523         chip->dev_index = dev;
    2524         INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
    2525 
    2526         chip->position_fix[0] = chip->position_fix[1] =
    2527                 check_position_fix(chip, position_fix[dev]);
    2528         check_probe_mask(chip, dev);
    2529 
    2530         chip->single_cmd = single_cmd;
    2531 
    2532         if (bdl_pos_adj[dev] < 0) {
    2533                 switch (chip->driver_type) {
    2534                 case AZX_DRIVER_ICH:
    2535                 case AZX_DRIVER_PCH:
    2536                         bdl_pos_adj[dev] = 1;
    2537                         break;
    2538                 default:
    2539                         bdl_pos_adj[dev] = 32;
    2540                         break;
    2541                 }
    2542         }
     2495        int dev, int driver_type,
     2496        struct azx **rchip)
     2497{
     2498  struct azx *chip;
     2499  int i, err;
     2500  unsigned short gcap;
     2501  static struct snd_device_ops ops = {
     2502    .dev_free = azx_dev_free,
     2503  };
     2504
     2505  *rchip = NULL;
     2506
     2507  err = pci_enable_device(pci);
     2508  if (err < 0)
     2509    return err;
     2510
     2511  chip = kzalloc(sizeof(*chip), GFP_KERNEL);
     2512  if (!chip) {
     2513    snd_printk(KERN_ERR SFX "cannot allocate chip\n");
     2514    pci_disable_device(pci);
     2515    return -ENOMEM;
     2516  }
     2517
     2518  spin_lock_init(&chip->reg_lock);
     2519  mutex_init(&chip->open_mutex);
     2520  chip->card = card;
     2521  chip->pci = pci;
     2522  chip->irq = -1;
     2523  chip->driver_type = driver_type;
     2524  check_msi(chip);
     2525  chip->dev_index = dev;
     2526  INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
     2527
     2528  chip->position_fix[0] = chip->position_fix[1] =
     2529    check_position_fix(chip, position_fix[dev]);
     2530  check_probe_mask(chip, dev);
     2531
     2532  chip->single_cmd = single_cmd;
     2533
     2534  if (bdl_pos_adj[dev] < 0) {
     2535    switch (chip->driver_type) {
     2536    case AZX_DRIVER_ICH:
     2537    case AZX_DRIVER_PCH:
     2538      bdl_pos_adj[dev] = 1;
     2539      break;
     2540    default:
     2541      bdl_pos_adj[dev] = 32;
     2542      break;
     2543    }
     2544  }
    25432545
    25442546#if BITS_PER_LONG != 64
    2545         /* Fix up base address on ULI M5461 */
    2546         if (chip->driver_type == AZX_DRIVER_ULI) {
    2547                 u16 tmp3;
    2548                 pci_read_config_word(pci, 0x40, &tmp3);
    2549                 pci_write_config_word(pci, 0x40, tmp3 | 0x10);
    2550                 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
    2551         }
     2547  /* Fix up base address on ULI M5461 */
     2548  if (chip->driver_type == AZX_DRIVER_ULI) {
     2549    u16 tmp3;
     2550    pci_read_config_word(pci, 0x40, &tmp3);
     2551    pci_write_config_word(pci, 0x40, tmp3 | 0x10);
     2552    pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);
     2553  }
    25522554#endif
    25532555
    2554         err = pci_request_regions(pci, "ICH HD audio");
    2555         if (err < 0) {
    2556                 kfree(chip);
    2557                 pci_disable_device(pci);
    2558                 return err;
    2559         }
    2560 
    2561         chip->addr = pci_resource_start(pci, 0);
    2562         chip->remap_addr = pci_ioremap_bar(pci, 0);
    2563         if (chip->remap_addr == NULL) {
    2564                 snd_printk(KERN_ERR SFX "ioremap error\n");
    2565                 err = -ENXIO;
    2566                 goto errout;
    2567         }
    2568 
    2569         if (chip->msi)
    2570                 if (pci_enable_msi(pci) < 0)
    2571                         chip->msi = 0;
    2572 
    2573         if (azx_acquire_irq(chip, 0) < 0) {
    2574                 err = -EBUSY;
    2575                 goto errout;
    2576         }
    2577 
    2578         pci_set_master(pci);
    2579         synchronize_irq(chip->irq);
    2580 
    2581         gcap = azx_readw(chip, GCAP);
    2582         snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
    2583 
    2584         /* disable SB600 64bit support for safety */
    2585         if ((chip->driver_type == AZX_DRIVER_ATI) ||
    2586             (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
    2587                 struct pci_dev *p_smbus;
    2588                 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
    2589                                         PCI_DEVICE_ID_ATI_SBX00_SMBUS,
    2590                                         NULL);
    2591                 if (p_smbus) {
    2592                         if (snd_pci_revision(p_smbus) < 0x30)
    2593                                 gcap &= ~ICH6_GCAP_64OK;
    2594                         pci_dev_put(p_smbus);
    2595                 }
    2596         }
    2597 
    2598         /* disable 64bit DMA address for Teradici */
    2599         /* it does not work with device 6549:1200 subsys e4a2:040b */
    2600         if (chip->driver_type == AZX_DRIVER_TERA)
    2601                 gcap &= ~ICH6_GCAP_64OK;
     2556  err = pci_request_regions(pci, "ICH HD audio");
     2557  if (err < 0) {
     2558    kfree(chip);
     2559    pci_disable_device(pci);
     2560    return err;
     2561  }
     2562
     2563  chip->addr = pci_resource_start(pci, 0);
     2564  chip->remap_addr = pci_ioremap_bar(pci, 0);
     2565  if (chip->remap_addr == NULL) {
     2566    snd_printk(KERN_ERR SFX "ioremap error\n");
     2567    err = -ENXIO;
     2568    goto errout;
     2569  }
     2570
     2571  if (chip->msi)
     2572    if (pci_enable_msi(pci) < 0)
     2573      chip->msi = 0;
     2574
     2575  if (azx_acquire_irq(chip, 0) < 0) {
     2576    err = -EBUSY;
     2577    goto errout;
     2578  }
     2579
     2580  pci_set_master(pci);
     2581  synchronize_irq(chip->irq);
     2582
     2583  gcap = azx_readw(chip, GCAP);
     2584  snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);
     2585
     2586  /* disable SB600 64bit support for safety */
     2587  if ((chip->driver_type == AZX_DRIVER_ATI) ||
     2588      (chip->driver_type == AZX_DRIVER_ATIHDMI)) {
     2589    struct pci_dev *p_smbus;
     2590    p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
     2591          PCI_DEVICE_ID_ATI_SBX00_SMBUS,
     2592          NULL);
     2593    if (p_smbus) {
     2594      if (snd_pci_revision(p_smbus) < 0x30)
     2595        gcap &= ~ICH6_GCAP_64OK;
     2596      pci_dev_put(p_smbus);
     2597    }
     2598  }
     2599
     2600  /* disable 64bit DMA address for Teradici */
     2601  /* it does not work with device 6549:1200 subsys e4a2:040b */
     2602  if (chip->driver_type == AZX_DRIVER_TERA)
     2603    gcap &= ~ICH6_GCAP_64OK;
    26022604
    26032605#pragma disable_message (135,302)
    2604         /* allow 64bit DMA address if supported by H/W */
    2605         if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
    2606                 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
    2607         else {
    2608                 pci_set_dma_mask(pci, DMA_BIT_MASK(32));
    2609                 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
    2610         }
     2606  /* allow 64bit DMA address if supported by H/W */
     2607  if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
     2608    pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
     2609  else {
     2610    pci_set_dma_mask(pci, DMA_BIT_MASK(32));
     2611    pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
     2612  }
    26112613#pragma enable_message (135,302)
    26122614
    2613         /* read number of streams from GCAP register instead of using
    2614         * hardcoded value
    2615         */
    2616         chip->capture_streams = (gcap >> 8) & 0x0f;
    2617         chip->playback_streams = (gcap >> 12) & 0x0f;
    2618         if (!chip->playback_streams && !chip->capture_streams) {
    2619                 /* gcap didn't give any info, switching to old method */
    2620 
    2621                 switch (chip->driver_type) {
    2622                 case AZX_DRIVER_ULI:
    2623                         chip->playback_streams = ULI_NUM_PLAYBACK;
    2624                         chip->capture_streams = ULI_NUM_CAPTURE;
    2625                         break;
    2626                 case AZX_DRIVER_ATIHDMI:
    2627                         chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
    2628                         chip->capture_streams = ATIHDMI_NUM_CAPTURE;
    2629                         break;
    2630                 case AZX_DRIVER_GENERIC:
    2631                 default:
    2632                         chip->playback_streams = ICH6_NUM_PLAYBACK;
    2633                         chip->capture_streams = ICH6_NUM_CAPTURE;
    2634                         break;
    2635                 }
    2636         }
    2637         chip->capture_index_offset = 0;
    2638         chip->playback_index_offset = chip->capture_streams;
    2639         chip->num_streams = chip->playback_streams + chip->capture_streams;
    2640         chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
    2641                                 GFP_KERNEL);
    2642         if (!chip->azx_dev) {
    2643                 snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");
    2644                 goto errout;
    2645         }
    2646 
    2647         for (i = 0; i < chip->num_streams; i++) {
    2648                 /* allocate memory for the BDL for each stream */
    2649                 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
    2650                                           snd_dma_pci_data(chip->pci),
    2651                                           BDL_SIZE, &chip->azx_dev[i].bdl);
    2652                 if (err < 0) {
    2653                         snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
    2654                         goto errout;
    2655                 }
    2656         }
    2657         /* allocate memory for the position buffer */
    2658         err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
    2659                                   snd_dma_pci_data(chip->pci),
    2660                                   chip->num_streams * 8, &chip->posbuf);
    2661         if (err < 0) {
    2662                 snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
    2663                 goto errout;
    2664         }
    2665         /* allocate CORB/RIRB */
    2666         err = azx_alloc_cmd_io(chip);
    2667         if (err < 0)
    2668                 goto errout;
    2669 
    2670         /* initialize streams */
    2671         azx_init_stream(chip);
    2672 
    2673         /* initialize chip */
    2674         azx_init_pci(chip);
    2675         azx_init_chip(chip, (probe_only[dev] & 2) == 0);
    2676 
    2677         /* codec detection */
    2678         if (!chip->codec_mask) {
    2679                 snd_printk(KERN_ERR SFX "no codecs found!\n");
    2680                 err = -ENODEV;
    2681                 goto errout;
    2682         }
    2683 
    2684         err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
    2685         if (err <0) {
    2686                 snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
    2687                 goto errout;
    2688         }
    2689 
    2690         strcpy(card->driver, "HDA-Intel");
    2691         strlcpy(card->shortname, driver_short_names[chip->driver_type],
    2692                 sizeof(card->shortname));
    2693         snprintf(card->longname, sizeof(card->longname),
    2694                 "%s at 0x%lx irq %i",
    2695                 card->shortname, chip->addr, chip->irq);
    2696 
    2697         *rchip = chip;
    2698         return 0;
     2615  /* read number of streams from GCAP register instead of using
     2616  * hardcoded value
     2617  */
     2618  chip->capture_streams = (gcap >> 8) & 0x0f;
     2619  chip->playback_streams = (gcap >> 12) & 0x0f;
     2620  if (!chip->playback_streams && !chip->capture_streams) {
     2621    /* gcap didn't give any info, switching to old method */
     2622
     2623    switch (chip->driver_type) {
     2624    case AZX_DRIVER_ULI:
     2625      chip->playback_streams = ULI_NUM_PLAYBACK;
     2626      chip->capture_streams = ULI_NUM_CAPTURE;
     2627      break;
     2628    case AZX_DRIVER_ATIHDMI:
     2629      chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
     2630      chip->capture_streams = ATIHDMI_NUM_CAPTURE;
     2631      break;
     2632    case AZX_DRIVER_GENERIC:
     2633    default:
     2634      chip->playback_streams = ICH6_NUM_PLAYBACK;
     2635      chip->capture_streams = ICH6_NUM_CAPTURE;
     2636      break;
     2637    }
     2638  }
     2639  chip->capture_index_offset = 0;
     2640  chip->playback_index_offset = chip->capture_streams;
     2641  chip->num_streams = chip->playback_streams + chip->capture_streams;
     2642  chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
     2643        GFP_KERNEL);
     2644  if (!chip->azx_dev) {
     2645    snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");
     2646    goto errout;
     2647  }
     2648
     2649  for (i = 0; i < chip->num_streams; i++) {
     2650    /* allocate memory for the BDL for each stream */
     2651    err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
     2652            snd_dma_pci_data(chip->pci),
     2653            BDL_SIZE, &chip->azx_dev[i].bdl);
     2654    if (err < 0) {
     2655      snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
     2656      goto errout;
     2657    }
     2658  }
     2659  /* allocate memory for the position buffer */
     2660  err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
     2661          snd_dma_pci_data(chip->pci),
     2662          chip->num_streams * 8, &chip->posbuf);
     2663  if (err < 0) {
     2664    snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
     2665    goto errout;
     2666  }
     2667  /* allocate CORB/RIRB */
     2668  err = azx_alloc_cmd_io(chip);
     2669  if (err < 0)
     2670    goto errout;
     2671
     2672  /* initialize streams */
     2673  azx_init_stream(chip);
     2674
     2675  /* initialize chip */
     2676  azx_init_pci(chip);
     2677  azx_init_chip(chip, (probe_only[dev] & 2) == 0);
     2678
     2679  /* codec detection */
     2680  if (!chip->codec_mask) {
     2681    snd_printk(KERN_ERR SFX "no codecs found!\n");
     2682    err = -ENODEV;
     2683    goto errout;
     2684  }
     2685
     2686  err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
     2687  if (err <0) {
     2688    snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
     2689    goto errout;
     2690  }
     2691
     2692  strcpy(card->driver, "HDA-Intel");
     2693  strlcpy(card->shortname, driver_short_names[chip->driver_type],
     2694    sizeof(card->shortname));
     2695  snprintf(card->longname, sizeof(card->longname),
     2696    "%s at 0x%lx irq %i",
     2697    card->shortname, chip->addr, chip->irq);
     2698
     2699  *rchip = chip;
     2700  return 0;
    26992701
    27002702 errout:
    2701         azx_free(chip);
    2702         return err;
     2703  azx_free(chip);
     2704  return err;
    27032705}
    27042706
     
    27062708{
    27072709#ifdef CONFIG_SND_HDA_POWER_SAVE
    2708         /* The codecs were powered up in snd_hda_codec_new().
    2709         * Now all initialization done, so turn them down if possible
    2710         */
    2711         struct hda_codec *codec;
    2712         list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {
    2713                 snd_hda_power_down(codec);
    2714         }
     2710  /* The codecs were powered up in snd_hda_codec_new().
     2711  * Now all initialization done, so turn them down if possible
     2712  */
     2713  struct hda_codec *codec;
     2714  list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {
     2715    snd_hda_power_down(codec);
     2716  }
    27152717#endif
    27162718}
    27172719
    27182720static int __devinit azx_probe(struct pci_dev *pci,
    2719                                const struct pci_device_id *pci_id)
    2720 {
    2721         static int dev;
    2722         struct snd_card *card;
    2723         struct azx *chip;
    2724         int err;
    2725 
    2726         if (dev >= SNDRV_CARDS)
    2727                 return -ENODEV;
    2728         if (!enable[dev]) {
    2729                 dev++;
    2730                 return -ENOENT;
    2731         }
    2732 
    2733         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
    2734         if (err < 0) {
    2735                 snd_printk(KERN_ERR SFX "Error creating card!\n");
    2736                 return err;
    2737         }
    2738 
    2739         /* set this here since it's referred in snd_hda_load_patch() */
    2740         snd_card_set_dev(card, &pci->dev);
    2741 
    2742         err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
    2743         if (err < 0)
    2744                 goto out_free;
    2745         card->private_data = chip;
     2721             const struct pci_device_id *pci_id)
     2722{
     2723  static int dev;
     2724  struct snd_card *card;
     2725  struct azx *chip;
     2726  int err;
     2727
     2728  if (dev >= SNDRV_CARDS)
     2729    return -ENODEV;
     2730  if (!enable[dev]) {
     2731    dev++;
     2732    return -ENOENT;
     2733  }
     2734
     2735  err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     2736  if (err < 0) {
     2737    snd_printk(KERN_ERR SFX "Error creating card!\n");
     2738    return err;
     2739  }
     2740
     2741  /* set this here since it's referred in snd_hda_load_patch() */
     2742  snd_card_set_dev(card, &pci->dev);
     2743
     2744  err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
     2745  if (err < 0)
     2746    goto out_free;
     2747  card->private_data = chip;
    27462748
    27472749#ifdef CONFIG_SND_HDA_INPUT_BEEP
    2748         chip->beep_mode = beep_mode[dev];
     2750  chip->beep_mode = beep_mode[dev];
    27492751#endif
    27502752
    2751         /* create codec instances */
    2752         err = azx_codec_create(chip, model[dev]);
    2753         if (err < 0)
    2754                 goto out_free;
     2753  /* create codec instances */
     2754  err = azx_codec_create(chip, model[dev]);
     2755  if (err < 0)
     2756    goto out_free;
    27552757#ifdef CONFIG_SND_HDA_PATCH_LOADER
    2756         if (patch[dev]) {
    2757                 snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
    2758                            patch[dev]);
    2759                 err = snd_hda_load_patch(chip->bus, patch[dev]);
    2760                 if (err < 0)
    2761                         goto out_free;
    2762         }
     2758  if (patch[dev]) {
     2759    snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",
     2760         patch[dev]);
     2761    err = snd_hda_load_patch(chip->bus, patch[dev]);
     2762    if (err < 0)
     2763      goto out_free;
     2764  }
    27632765#endif
    2764         if ((probe_only[dev] & 1) == 0) {
    2765                 err = azx_codec_configure(chip);
    2766                 if (err < 0)
    2767                         goto out_free;
    2768         }
    2769 
    2770         /* create PCM streams */
    2771         err = snd_hda_build_pcms(chip->bus);
    2772         if (err < 0)
    2773                 goto out_free;
    2774                
    2775         /* create mixer controls */
    2776         err = azx_mixer_create(chip);
    2777         if (err < 0)
    2778                 goto out_free;
    2779 
    2780         err = snd_card_register(card);
    2781         if (err < 0)
    2782                 goto out_free;
    2783 
    2784         pci_set_drvdata(pci, card);
    2785         chip->running = 1;
    2786         power_down_all_codecs(chip);
    2787         azx_notifier_register(chip);
    2788 
    2789         dev++;
    2790         return err;
     2766  if ((probe_only[dev] & 1) == 0) {
     2767    err = azx_codec_configure(chip);
     2768    if (err < 0)
     2769      goto out_free;
     2770  }
     2771
     2772  /* create PCM streams */
     2773  err = snd_hda_build_pcms(chip->bus);
     2774  if (err < 0)
     2775    goto out_free;
     2776
     2777  /* create mixer controls */
     2778  err = azx_mixer_create(chip);
     2779  if (err < 0)
     2780    goto out_free;
     2781
     2782  err = snd_card_register(card);
     2783  if (err < 0)
     2784    goto out_free;
     2785
     2786  pci_set_drvdata(pci, card);
     2787  chip->running = 1;
     2788  power_down_all_codecs(chip);
     2789  azx_notifier_register(chip);
     2790
     2791  dev++;
     2792  return err;
    27912793out_free:
    2792         snd_card_free(card);
    2793         return err;
     2794  snd_card_free(card);
     2795  return err;
    27942796}
    27952797
    27962798static void __devexit azx_remove(struct pci_dev *pci)
    27972799{
    2798         snd_card_free(pci_get_drvdata(pci));
    2799         pci_set_drvdata(pci, NULL);
     2800  snd_card_free(pci_get_drvdata(pci));
     2801  pci_set_drvdata(pci, NULL);
    28002802}
    28012803
    28022804/* PCI IDs */
    28032805static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
    2804         /* CPT */
    2805         { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
    2806         /* PBG */
    2807         { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH },
    2808         /* SCH */
    2809         { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
    2810         /* Generic Intel */
    2811         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
    2812           .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
    2813           .class_mask = 0xffffff,
    2814           .driver_data = AZX_DRIVER_ICH },
    2815         /* ATI SB 450/600 */
    2816         { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
    2817         { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
    2818         /* ATI HDMI */
    2819         { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
    2820         { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
    2821         { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
    2822         { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI },
    2823         { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
    2824         { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
    2825         { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
    2826         { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
    2827         { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
    2828         { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
    2829         { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
    2830         { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
    2831         { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
    2832         { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
    2833         /* VIA VT8251/VT8237A */
    2834         { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
    2835         /* SIS966 */
    2836         { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
    2837         /* ULI M5461 */
    2838         { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
    2839         /* NVIDIA MCP */
    2840         { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
    2841           .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
    2842           .class_mask = 0xffffff,
    2843           .driver_data = AZX_DRIVER_NVIDIA },
    2844         /* Teradici */
    2845         { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
    2846         /* Creative X-Fi (CA0110-IBG) */
     2806  /* CPT */
     2807  { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH },
     2808  /* PBG */
     2809  { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH },
     2810  { PCI_DEVICE(0x8086, 0x1e20), .driver_data = AZX_DRIVER_PCH },
     2811        { PCI_DEVICE(0x8086, 0x8c20), .driver_data = AZX_DRIVER_PCH },
     2812        { PCI_DEVICE(0x8086, 0x8d20), .driver_data = AZX_DRIVER_PCH },
     2813        { PCI_DEVICE(0x8086, 0x8d21), .driver_data = AZX_DRIVER_PCH },
     2814        { PCI_DEVICE(0x8086, 0x9c20), .driver_data = AZX_DRIVER_PCH },
     2815        { PCI_DEVICE(0x8086, 0x9c21), .driver_data = AZX_DRIVER_PCH },
     2816        { PCI_DEVICE(0x8086, 0x9ca0), .driver_data = AZX_DRIVER_PCH },
     2817  /* SCH */
     2818  { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
     2819  /* Generic Intel */
     2820  { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
     2821    .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
     2822    .class_mask = 0xffffff,
     2823    .driver_data = AZX_DRIVER_ICH },
     2824  /* ATI SB 450/600 */
     2825  { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
     2826  { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
     2827  /* ATI HDMI */
     2828  { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
     2829  { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
     2830  { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
     2831  { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI },
     2832  { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
     2833  { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
     2834  { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
     2835  { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
     2836  { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
     2837  { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
     2838  { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
     2839  { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
     2840  { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
     2841  { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
     2842  /* VIA VT8251/VT8237A */
     2843  { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
     2844  /* SIS966 */
     2845  { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
     2846  /* ULI M5461 */
     2847  { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
     2848  /* NVIDIA MCP */
     2849  { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
     2850    .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
     2851    .class_mask = 0xffffff,
     2852    .driver_data = AZX_DRIVER_NVIDIA },
     2853  /* Teradici */
     2854  { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
     2855  /* Creative X-Fi (CA0110-IBG) */
    28472856#if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE)
    2848         /* the following entry conflicts with snd-ctxfi driver,
    2849         * as ctxfi driver mutates from HD-audio to native mode with
    2850         * a special command sequence.
    2851         */
    2852         { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
    2853           .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
    2854           .class_mask = 0xffffff,
    2855           .driver_data = AZX_DRIVER_CTX },
     2857  /* the following entry conflicts with snd-ctxfi driver,
     2858  * as ctxfi driver mutates from HD-audio to native mode with
     2859  * a special command sequence.
     2860  */
     2861  { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),
     2862    .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
     2863    .class_mask = 0xffffff,
     2864    .driver_data = AZX_DRIVER_CTX },
    28562865#else
    2857         /* this entry seems still valid -- i.e. without emu20kx chip */
    2858         { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX },
     2866  /* this entry seems still valid -- i.e. without emu20kx chip */
     2867  { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX },
    28592868#endif
    2860         /* Vortex86MX */
    2861         { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
    2862         /* VMware HDAudio */
    2863         { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
    2864         /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
    2865         { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
    2866           .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
    2867           .class_mask = 0xffffff,
    2868           .driver_data = AZX_DRIVER_GENERIC },
    2869         { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
    2870           .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
    2871           .class_mask = 0xffffff,
    2872           .driver_data = AZX_DRIVER_GENERIC },
    2873         { 0, }
     2869  /* Vortex86MX */
     2870  { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },
     2871  /* VMware HDAudio */
     2872  { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },
     2873  /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */
     2874  { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),
     2875    .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
     2876    .class_mask = 0xffffff,
     2877    .driver_data = AZX_DRIVER_GENERIC },
     2878  { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),
     2879    .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
     2880    .class_mask = 0xffffff,
     2881    .driver_data = AZX_DRIVER_GENERIC },
     2882  { 0, }
    28742883};
    28752884MODULE_DEVICE_TABLE(pci, azx_ids);
     
    28772886/* pci_driver definition */
    28782887static struct pci_driver driver = {
    2879         .name = "HDA Intel",
    2880         .id_table = azx_ids,
    2881         .probe = azx_probe,
    2882         .remove = __devexit_p(azx_remove),
     2888  .name = "HDA Intel",
     2889  .id_table = azx_ids,
     2890  .probe = azx_probe,
     2891  .remove = __devexit_p(azx_remove),
    28832892#ifdef CONFIG_PM
    2884         .suspend = azx_suspend,
    2885         .resume = azx_resume,
     2893  .suspend = azx_suspend,
     2894  .resume = azx_resume,
    28862895#endif
    28872896};
     
    28892898static int __init alsa_card_azx_init(void)
    28902899{
    2891         return pci_register_driver(&driver);
     2900  return pci_register_driver(&driver);
    28922901}
    28932902
    28942903static void __exit alsa_card_azx_exit(void)
    28952904{
    2896         pci_unregister_driver(&driver);
     2905  pci_unregister_driver(&driver);
    28972906}
    28982907
  • GPL/trunk/drv32/Makefile

    r596 r604  
    4848!endif
    4949
    50 
    5150#===================================================================
    5251#
     
    6766FILES += end.obj
    6867
    69 LIBS     = $(ALSA_LIB)\linuxlib.lib $(ALSA_LIB)\core.lib $(ALSA_LIB)\ac97.lib $(ALSA_LIB)\pci.lib $(ALSA_LIB)\ca0106.lib $(ALSA_LIB)\hda.lib $(ALSA_LIB)\sequencer.lib $(ALSA_LIB)\opl3.lib $(ALSA_LIB)\mpu401.lib $(ALSA_LIB)\synth.lib $(ALSA_LIB)\cs46xx.lib $(ALSA_LIB)\cs5535audio.lib $(ALSA_LIB)\emu10k1.lib $(ALSA_LIB)\ymfpci.lib $(ALSA_LIB)\ali5451.lib $(ALSA_LIB)\trident.lib $(ALSA_LIB)\nm256.lib $(ALSA_LIB)\sb.lib $(ALSA_LIB)\core_oss.lib
     68LIBS = $(ALSA_LIB)\linuxlib.lib $(ALSA_LIB)\core.lib $(ALSA_LIB)\ac97.lib $(ALSA_LIB)\pci.lib &
     69 $(ALSA_LIB)\ca0106.lib $(ALSA_LIB)\hda.lib $(ALSA_LIB)\sequencer.lib $(ALSA_LIB)\opl3.lib &
     70 $(ALSA_LIB)\mpu401.lib $(ALSA_LIB)\synth.lib $(ALSA_LIB)\cs46xx.lib $(ALSA_LIB)\cs5535audio.lib &
     71 $(ALSA_LIB)\emu10k1.lib $(ALSA_LIB)\ymfpci.lib $(ALSA_LIB)\ali5451.lib $(ALSA_LIB)\trident.lib &
     72 $(ALSA_LIB)\nm256.lib $(ALSA_LIB)\sb.lib $(ALSA_LIB)\core_oss.lib
    7073WMAPNAME = $(OBJDIR)\$(TARGET).wmap
    7174
     
    100103  @%write $^@ $(WATCOM)\lib386\os2\clib3r.lib
    101104  @%write $^@ $(WATCOM)\lib386\os2\os2386.lib
     105!ifdef %DRV32KIT
     106  @%write $^@ $(%DRV32KIT)\drv32.lib
     107!endif
    102108  @%write $^@ $(DEFFILE)
    103109!endif
  • GPL/trunk/drv32/irq.c

    r587 r604  
    5151BOOL ALSA_SetIrq(ULONG ulIrq, ULONG ulSlotNo, BOOL fShared)
    5252{
    53     USHORT rc = 1;
     53  USHORT rc = 1;
    5454
    55     if( ulSlotNo >= MAX_IRQ_SLOTS ) {
    56         DebugInt3();
    57         return FALSE;
    58     }
     55  if( ulSlotNo >= MAX_IRQ_SLOTS )
     56  {
     57    DebugInt3();
     58    return FALSE;
     59  }
    5960
    60     if(fShared)
    61     {
    62         rc = DevIRQSet((WORD16) *pISR[ulSlotNo],
    63                        (WORD16)ulIrq,
    64                        1 );   // first try shared shared
    65     }
     61  if(fShared)
     62  {
     63    rc = DevIRQSet((WORD16) *pISR[ulSlotNo], (WORD16)ulIrq, 1 );   // first try shared shared
     64  }
    6665
    67     if (rc != 0) {                    // If error ...
    68        rprintf(("ERROR: RMSetIrq %d %d %x - failed to set shared - trying exclusive!!", ulIrq, fShared, ulSlotNo));
    69         rc = DevIRQSet((WORD16) *pISR[ulSlotNo],
    70                        (WORD16)ulIrq,
    71                        0);   // failed, so try exclusive instead
    72     }
     66  if (rc != 0)
     67  {                    // If error ...
     68    rprintf(("ERROR: RMSetIrq %d %d %x - failed to set shared - trying exclusive!!", ulIrq, fShared, ulSlotNo));
     69    rc = DevIRQSet((WORD16) *pISR[ulSlotNo], (WORD16)ulIrq, 0);   // failed, so try exclusive instead
     70  }
    7371
    74     if (rc != 0) {                    // If error ...
    75         rprintf(("ERROR: RMSetIrq %d %d %x FAILED shared and exclusive mode!!", ulIrq, fShared, ulSlotNo));
    76         DebugInt3();
    77         return FALSE;
    78     }
     72  if (rc != 0)
     73  {                    // If error ...
     74    rprintf(("ERROR: RMSetIrq %d %d %x FAILED shared and exclusive mode!!", ulIrq, fShared, ulSlotNo));
     75    DebugInt3();
     76    return FALSE;
     77  }
    7978
    80     return TRUE;
     79  return TRUE;
    8180}
    8281
     
    8483BOOL ALSA_FreeIrq(ULONG ulIrq)
    8584{
    86     return (DevIRQClear((WORD16)ulIrq) == 0);
     85  return (DevIRQClear((WORD16)ulIrq) == 0);
    8786}
    8887
     
    9190ULONG ALSA_Interrupt(ULONG ulSlotNo)
    9291{
    93     ULONG       ulIrqNo;
     92  ULONG ulIrqNo;
    9493
    95    // enable interrupts that have higher priority we should
    96    // allow higher priority interrupts
    97    sti();
    98    if( process_interrupt(ulSlotNo, &ulIrqNo) ) {
    99                 DbgInt.ulIntServiced[DbgInt.ulState]++;
    100        // We've cleared all service requests.
    101        // Clear (disable) Interrupts, Send EOI
    102        // and clear the carry flag (tells OS/2 kernel that Int was handled).
    103        // Note carry flag is handled in setup.asm
    104        cli();
    105        DevEOI( (WORD16)ulIrqNo );
    106        return TRUE;
    107    }
    108         DbgInt.ulIntUnserviced[DbgInt.ulState]++;
    109    // Indicate Interrupt not serviced by setting carry flag before
    110    // returning to OS/2 kernel.  OS/2 will then shut down the interrupt!
    111    // NOTE: Make sure interrupts are not turned on again when this irq isn't ours!
    112    return FALSE;
     94  // enable interrupts that have higher priority we should
     95  // allow higher priority interrupts
     96  sti();
     97  if( process_interrupt(ulSlotNo, &ulIrqNo) )
     98  {
     99    DbgInt.ulIntServiced[DbgInt.ulState]++;
     100    // We've cleared all service requests.
     101    // Clear (disable) Interrupts, Send EOI
     102    // and clear the carry flag (tells OS/2 kernel that Int was handled).
     103    // Note carry flag is handled in setup.asm
     104    cli();
     105    DevEOI( (WORD16)ulIrqNo );
     106    return TRUE;
     107  }
     108  DbgInt.ulIntUnserviced[DbgInt.ulState]++;
     109  // Indicate Interrupt not serviced by setting carry flag before
     110  // returning to OS/2 kernel.  OS/2 will then shut down the interrupt!
     111  // NOTE: Make sure interrupts are not turned on again when this irq isn't ours!
     112  return FALSE;
    113113}
    114114
  • GPL/trunk/include/linux/pci.h

    r598 r604  
    11/*
    2  *      PCI defines and function prototypes
    3  *      Copyright 1994, Drew Eckhardt
    4  *      Copyright 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
     2 *  PCI defines and function prototypes
     3 *  Copyright 1994, Drew Eckhardt
     4 *  Copyright 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
    55 *
    6  *      For more information, please consult the following manuals (look at
    7  *      http://www.pcisig.com/ for how to get them):
     6 *  For more information, please consult the following manuals (look at
     7 *  http://www.pcisig.com/ for how to get them):
    88 *
    9  *      PCI BIOS Specification
    10  *      PCI Local Bus Specification
    11  *      PCI to PCI Bridge Specification
    12  *      PCI System Design Guide
     9 *  PCI BIOS Specification
     10 *  PCI Local Bus Specification
     11 *  PCI to PCI Bridge Specification
     12 *  PCI System Design Guide
    1313 */
    1414
     
    2323 * of which the first 64 bytes are standardized as follows:
    2424 */
    25 #define PCI_VENDOR_ID           0x00    /* 16 bits */
    26 #define PCI_DEVICE_ID           0x02    /* 16 bits */
    27 #define PCI_COMMAND             0x04    /* 16 bits */
    28 #define  PCI_COMMAND_IO         0x1     /* Enable response in I/O space */
    29 #define  PCI_COMMAND_MEMORY     0x2     /* Enable response in Memory space */
    30 #define  PCI_COMMAND_MASTER     0x4     /* Enable bus mastering */
    31 #define  PCI_COMMAND_SPECIAL    0x8     /* Enable response to special cycles */
    32 #define  PCI_COMMAND_INVALIDATE 0x10    /* Use memory write and invalidate */
    33 #define  PCI_COMMAND_VGA_PALETTE 0x20   /* Enable palette snooping */
    34 #define  PCI_COMMAND_PARITY     0x40    /* Enable parity checking */
    35 #define  PCI_COMMAND_WAIT       0x80    /* Enable address/data stepping */
    36 #define  PCI_COMMAND_SERR       0x100   /* Enable SERR */
    37 #define  PCI_COMMAND_FAST_BACK  0x200   /* Enable back-to-back writes */
    38 
    39 #define PCI_STATUS              0x06    /* 16 bits */
    40 #define  PCI_STATUS_CAP_LIST    0x10    /* Support Capability List */
    41 #define  PCI_STATUS_66MHZ       0x20    /* Support 66 Mhz PCI 2.1 bus */
    42 #define  PCI_STATUS_UDF         0x40    /* Support User Definable Features [obsolete] */
    43 #define  PCI_STATUS_FAST_BACK   0x80    /* Accept fast-back to back */
    44 #define  PCI_STATUS_PARITY      0x100   /* Detected parity error */
    45 #define  PCI_STATUS_DEVSEL_MASK 0x600   /* DEVSEL timing */
    46 #define  PCI_STATUS_DEVSEL_FAST 0x000   
     25#define PCI_VENDOR_ID   0x00  /* 16 bits */
     26#define PCI_DEVICE_ID   0x02  /* 16 bits */
     27#define PCI_COMMAND   0x04  /* 16 bits */
     28#define  PCI_COMMAND_IO   0x1 /* Enable response in I/O space */
     29#define  PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */
     30#define  PCI_COMMAND_MASTER 0x4 /* Enable bus mastering */
     31#define  PCI_COMMAND_SPECIAL  0x8 /* Enable response to special cycles */
     32#define  PCI_COMMAND_INVALIDATE 0x10  /* Use memory write and invalidate */
     33#define  PCI_COMMAND_VGA_PALETTE 0x20 /* Enable palette snooping */
     34#define  PCI_COMMAND_PARITY 0x40  /* Enable parity checking */
     35#define  PCI_COMMAND_WAIT   0x80  /* Enable address/data stepping */
     36#define  PCI_COMMAND_SERR 0x100 /* Enable SERR */
     37#define  PCI_COMMAND_FAST_BACK  0x200 /* Enable back-to-back writes */
     38
     39#define PCI_STATUS    0x06  /* 16 bits */
     40#define  PCI_STATUS_CAP_LIST  0x10  /* Support Capability List */
     41#define  PCI_STATUS_66MHZ 0x20  /* Support 66 Mhz PCI 2.1 bus */
     42#define  PCI_STATUS_UDF   0x40  /* Support User Definable Features [obsolete] */
     43#define  PCI_STATUS_FAST_BACK 0x80  /* Accept fast-back to back */
     44#define  PCI_STATUS_PARITY  0x100 /* Detected parity error */
     45#define  PCI_STATUS_DEVSEL_MASK 0x600 /* DEVSEL timing */
     46#define  PCI_STATUS_DEVSEL_FAST 0x000
    4747#define  PCI_STATUS_DEVSEL_MEDIUM 0x200
    4848#define  PCI_STATUS_DEVSEL_SLOW 0x400
     
    5353#define  PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */
    5454
    55 #define PCI_CLASS_REVISION      0x08    /* High 24 bits are class, low 8
    56                                            revision */
     55#define PCI_CLASS_REVISION  0x08  /* High 24 bits are class, low 8
     56             revision */
    5757#define PCI_REVISION_ID         0x08    /* Revision ID */
    5858#define PCI_CLASS_PROG          0x09    /* Reg. Level Programming Interface */
    5959#define PCI_CLASS_DEVICE        0x0a    /* Device class */
    6060
    61 #define PCI_CACHE_LINE_SIZE     0x0c    /* 8 bits */
    62 #define PCI_LATENCY_TIMER       0x0d    /* 8 bits */
    63 #define PCI_HEADER_TYPE         0x0e    /* 8 bits */
    64 #define  PCI_HEADER_TYPE_NORMAL 0
     61#define PCI_CACHE_LINE_SIZE 0x0c  /* 8 bits */
     62#define PCI_LATENCY_TIMER 0x0d  /* 8 bits */
     63#define PCI_HEADER_TYPE   0x0e  /* 8 bits */
     64#define  PCI_HEADER_TYPE_NORMAL 0
    6565#define  PCI_HEADER_TYPE_BRIDGE 1
    6666#define  PCI_HEADER_TYPE_CARDBUS 2
    6767
    68 #define PCI_BIST                0x0f    /* 8 bits */
    69 #define PCI_BIST_CODE_MASK      0x0f    /* Return result */
    70 #define PCI_BIST_START          0x40    /* 1 to start BIST, 2 secs or less */
    71 #define PCI_BIST_CAPABLE        0x80    /* 1 if BIST capable */
     68#define PCI_BIST    0x0f  /* 8 bits */
     69#define PCI_BIST_CODE_MASK  0x0f  /* Return result */
     70#define PCI_BIST_START    0x40  /* 1 to start BIST, 2 secs or less */
     71#define PCI_BIST_CAPABLE  0x80  /* 1 if BIST capable */
    7272
    7373/*
     
    7777 * 1 bits are decoded.
    7878 */
    79 #define PCI_BASE_ADDRESS_0      0x10    /* 32 bits */
    80 #define PCI_BASE_ADDRESS_1      0x14    /* 32 bits [htype 0,1 only] */
    81 #define PCI_BASE_ADDRESS_2      0x18    /* 32 bits [htype 0 only] */
    82 #define PCI_BASE_ADDRESS_3      0x1c    /* 32 bits */
    83 #define PCI_BASE_ADDRESS_4      0x20    /* 32 bits */
    84 #define PCI_BASE_ADDRESS_5      0x24    /* 32 bits */
    85 #define  PCI_BASE_ADDRESS_SPACE 0x01    /* 0 = memory, 1 = I/O */
     79#define PCI_BASE_ADDRESS_0  0x10  /* 32 bits */
     80#define PCI_BASE_ADDRESS_1  0x14  /* 32 bits [htype 0,1 only] */
     81#define PCI_BASE_ADDRESS_2  0x18  /* 32 bits [htype 0 only] */
     82#define PCI_BASE_ADDRESS_3  0x1c  /* 32 bits */
     83#define PCI_BASE_ADDRESS_4  0x20  /* 32 bits */
     84#define PCI_BASE_ADDRESS_5  0x24  /* 32 bits */
     85#define  PCI_BASE_ADDRESS_SPACE 0x01  /* 0 = memory, 1 = I/O */
    8686#define  PCI_BASE_ADDRESS_SPACE_IO 0x01
    8787#define  PCI_BASE_ADDRESS_SPACE_MEMORY 0x00
    8888#define  PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
    89 #define  PCI_BASE_ADDRESS_MEM_TYPE_32   0x00    /* 32 bit address */
    90 #define  PCI_BASE_ADDRESS_MEM_TYPE_1M   0x02    /* Below 1M [obsolete] */
    91 #define  PCI_BASE_ADDRESS_MEM_TYPE_64   0x04    /* 64 bit address */
    92 #define  PCI_BASE_ADDRESS_MEM_PREFETCH  0x08    /* prefetchable? */
    93 #define  PCI_BASE_ADDRESS_MEM_MASK      (~0x0fUL)
    94 #define  PCI_BASE_ADDRESS_IO_MASK       (~0x03UL)
     89#define  PCI_BASE_ADDRESS_MEM_TYPE_32 0x00  /* 32 bit address */
     90#define  PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02  /* Below 1M [obsolete] */
     91#define  PCI_BASE_ADDRESS_MEM_TYPE_64 0x04  /* 64 bit address */
     92#define  PCI_BASE_ADDRESS_MEM_PREFETCH  0x08  /* prefetchable? */
     93#define  PCI_BASE_ADDRESS_MEM_MASK  (~0x0fUL)
     94#define  PCI_BASE_ADDRESS_IO_MASK (~0x03UL)
    9595/* bit 1 is reserved if address_space = 1 */
    9696
    9797/* Header type 0 (normal devices) */
    98 #define PCI_CARDBUS_CIS         0x28
    99 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c
    100 #define PCI_SUBSYSTEM_ID        0x2e
    101 #define PCI_ROM_ADDRESS         0x30    /* Bits 31..11 are address, 10..1 reserved */
    102 #define  PCI_ROM_ADDRESS_ENABLE 0x01
    103 #define PCI_ROM_ADDRESS_MASK    (~0x7ffUL)
    104 
    105 #define PCI_CAPABILITY_LIST     0x34    /* Offset of first capability list entry */
     98#define PCI_CARDBUS_CIS   0x28
     99#define PCI_SUBSYSTEM_VENDOR_ID 0x2c
     100#define PCI_SUBSYSTEM_ID  0x2e
     101#define PCI_ROM_ADDRESS   0x30  /* Bits 31..11 are address, 10..1 reserved */
     102#define  PCI_ROM_ADDRESS_ENABLE 0x01
     103#define PCI_ROM_ADDRESS_MASK  (~0x7ffUL)
     104
     105#define PCI_CAPABILITY_LIST 0x34  /* Offset of first capability list entry */
    106106
    107107/* 0x35-0x3b are reserved */
    108 #define PCI_INTERRUPT_LINE      0x3c    /* 8 bits */
    109 #define PCI_INTERRUPT_PIN       0x3d    /* 8 bits */
    110 #define PCI_MIN_GNT             0x3e    /* 8 bits */
    111 #define PCI_MAX_LAT             0x3f    /* 8 bits */
     108#define PCI_INTERRUPT_LINE  0x3c  /* 8 bits */
     109#define PCI_INTERRUPT_PIN 0x3d  /* 8 bits */
     110#define PCI_MIN_GNT   0x3e  /* 8 bits */
     111#define PCI_MAX_LAT   0x3f  /* 8 bits */
    112112
    113113/* Header type 1 (PCI-to-PCI bridges) */
    114 #define PCI_PRIMARY_BUS         0x18    /* Primary bus number */
    115 #define PCI_SECONDARY_BUS       0x19    /* Secondary bus number */
    116 #define PCI_SUBORDINATE_BUS     0x1a    /* Highest bus number behind the bridge */
    117 #define PCI_SEC_LATENCY_TIMER   0x1b    /* Latency timer for secondary interface */
    118 #define PCI_IO_BASE             0x1c    /* I/O range behind the bridge */
    119 #define PCI_IO_LIMIT            0x1d
    120 #define  PCI_IO_RANGE_TYPE_MASK 0x0f    /* I/O bridging type */
    121 #define  PCI_IO_RANGE_TYPE_16   0x00
    122 #define  PCI_IO_RANGE_TYPE_32   0x01
    123 #define  PCI_IO_RANGE_MASK      ~0x0f
    124 #define PCI_SEC_STATUS          0x1e    /* Secondary status register, only bit 14 used */
    125 #define PCI_MEMORY_BASE         0x20    /* Memory range behind */
    126 #define PCI_MEMORY_LIMIT        0x22
     114#define PCI_PRIMARY_BUS   0x18  /* Primary bus number */
     115#define PCI_SECONDARY_BUS 0x19  /* Secondary bus number */
     116#define PCI_SUBORDINATE_BUS 0x1a  /* Highest bus number behind the bridge */
     117#define PCI_SEC_LATENCY_TIMER 0x1b  /* Latency timer for secondary interface */
     118#define PCI_IO_BASE   0x1c  /* I/O range behind the bridge */
     119#define PCI_IO_LIMIT    0x1d
     120#define  PCI_IO_RANGE_TYPE_MASK 0x0f  /* I/O bridging type */
     121#define  PCI_IO_RANGE_TYPE_16 0x00
     122#define  PCI_IO_RANGE_TYPE_32 0x01
     123#define  PCI_IO_RANGE_MASK  ~0x0f
     124#define PCI_SEC_STATUS    0x1e  /* Secondary status register, only bit 14 used */
     125#define PCI_MEMORY_BASE   0x20  /* Memory range behind */
     126#define PCI_MEMORY_LIMIT  0x22
    127127#define  PCI_MEMORY_RANGE_TYPE_MASK 0x0f
    128 #define  PCI_MEMORY_RANGE_MASK  ~0x0f
    129 #define PCI_PREF_MEMORY_BASE    0x24    /* Prefetchable memory range behind */
    130 #define PCI_PREF_MEMORY_LIMIT   0x26
     128#define  PCI_MEMORY_RANGE_MASK  ~0x0f
     129#define PCI_PREF_MEMORY_BASE  0x24  /* Prefetchable memory range behind */
     130#define PCI_PREF_MEMORY_LIMIT 0x26
    131131#define  PCI_PREF_RANGE_TYPE_MASK 0x0f
    132 #define  PCI_PREF_RANGE_TYPE_32 0x00
    133 #define  PCI_PREF_RANGE_TYPE_64 0x01
    134 #define  PCI_PREF_RANGE_MASK    ~0x0f
    135 #define PCI_PREF_BASE_UPPER32   0x28    /* Upper half of prefetchable memory range */
    136 #define PCI_PREF_LIMIT_UPPER32  0x2c
    137 #define PCI_IO_BASE_UPPER16     0x30    /* Upper half of I/O addresses */
    138 #define PCI_IO_LIMIT_UPPER16    0x32
     132#define  PCI_PREF_RANGE_TYPE_32 0x00
     133#define  PCI_PREF_RANGE_TYPE_64 0x01
     134#define  PCI_PREF_RANGE_MASK  ~0x0f
     135#define PCI_PREF_BASE_UPPER32 0x28  /* Upper half of prefetchable memory range */
     136#define PCI_PREF_LIMIT_UPPER32  0x2c
     137#define PCI_IO_BASE_UPPER16 0x30  /* Upper half of I/O addresses */
     138#define PCI_IO_LIMIT_UPPER16  0x32
    139139/* 0x34 same as for htype 0 */
    140140/* 0x35-0x3b is reserved */
    141 #define PCI_ROM_ADDRESS1        0x38    /* Same as PCI_ROM_ADDRESS, but for htype 1 */
     141#define PCI_ROM_ADDRESS1  0x38  /* Same as PCI_ROM_ADDRESS, but for htype 1 */
    142142/* 0x3c-0x3d are same as for htype 0 */
    143 #define PCI_BRIDGE_CONTROL      0x3e
    144 #define  PCI_BRIDGE_CTL_PARITY  0x01    /* Enable parity detection on secondary interface */
    145 #define  PCI_BRIDGE_CTL_SERR    0x02    /* The same for SERR forwarding */
    146 #define  PCI_BRIDGE_CTL_NO_ISA  0x04    /* Disable bridging of ISA ports */
    147 #define  PCI_BRIDGE_CTL_VGA     0x08    /* Forward VGA addresses */
     143#define PCI_BRIDGE_CONTROL  0x3e
     144#define  PCI_BRIDGE_CTL_PARITY  0x01  /* Enable parity detection on secondary interface */
     145#define  PCI_BRIDGE_CTL_SERR  0x02  /* The same for SERR forwarding */
     146#define  PCI_BRIDGE_CTL_NO_ISA  0x04  /* Disable bridging of ISA ports */
     147#define  PCI_BRIDGE_CTL_VGA 0x08  /* Forward VGA addresses */
    148148#define  PCI_BRIDGE_CTL_MASTER_ABORT 0x20  /* Report master aborts */
    149 #define  PCI_BRIDGE_CTL_BUS_RESET 0x40  /* Secondary bus reset */
    150 #define  PCI_BRIDGE_CTL_FAST_BACK 0x80  /* Fast Back2Back enabled on secondary interface */
     149#define  PCI_BRIDGE_CTL_BUS_RESET 0x40  /* Secondary bus reset */
     150#define  PCI_BRIDGE_CTL_FAST_BACK 0x80  /* Fast Back2Back enabled on secondary interface */
    151151
    152152/* Header type 2 (CardBus bridges) */
    153153/* 0x14-0x15 reserved */
    154154#define PCI_CB_CAPABILITY_LIST  0x14
    155 #define PCI_CB_SEC_STATUS       0x16    /* Secondary status */
    156 #define PCI_CB_PRIMARY_BUS      0x18    /* PCI bus number */
    157 #define PCI_CB_CARD_BUS         0x19    /* CardBus bus number */
    158 #define PCI_CB_SUBORDINATE_BUS  0x1a    /* Subordinate bus number */
    159 #define PCI_CB_LATENCY_TIMER    0x1b    /* CardBus latency timer */
    160 #define PCI_CB_MEMORY_BASE_0    0x1c
    161 #define PCI_CB_MEMORY_LIMIT_0   0x20
    162 #define PCI_CB_MEMORY_BASE_1    0x24
    163 #define PCI_CB_MEMORY_LIMIT_1   0x28
    164 #define PCI_CB_IO_BASE_0        0x2c
    165 #define PCI_CB_IO_BASE_0_HI     0x2e
    166 #define PCI_CB_IO_LIMIT_0       0x30
    167 #define PCI_CB_IO_LIMIT_0_HI    0x32
    168 #define PCI_CB_IO_BASE_1        0x34
    169 #define PCI_CB_IO_BASE_1_HI     0x36
    170 #define PCI_CB_IO_LIMIT_1       0x38
    171 #define PCI_CB_IO_LIMIT_1_HI    0x3a
    172 #define  PCI_CB_IO_RANGE_MASK   ~0x03
     155#define PCI_CB_SEC_STATUS 0x16  /* Secondary status */
     156#define PCI_CB_PRIMARY_BUS  0x18  /* PCI bus number */
     157#define PCI_CB_CARD_BUS   0x19  /* CardBus bus number */
     158#define PCI_CB_SUBORDINATE_BUS  0x1a  /* Subordinate bus number */
     159#define PCI_CB_LATENCY_TIMER  0x1b  /* CardBus latency timer */
     160#define PCI_CB_MEMORY_BASE_0  0x1c
     161#define PCI_CB_MEMORY_LIMIT_0 0x20
     162#define PCI_CB_MEMORY_BASE_1  0x24
     163#define PCI_CB_MEMORY_LIMIT_1 0x28
     164#define PCI_CB_IO_BASE_0  0x2c
     165#define PCI_CB_IO_BASE_0_HI 0x2e
     166#define PCI_CB_IO_LIMIT_0 0x30
     167#define PCI_CB_IO_LIMIT_0_HI  0x32
     168#define PCI_CB_IO_BASE_1  0x34
     169#define PCI_CB_IO_BASE_1_HI 0x36
     170#define PCI_CB_IO_LIMIT_1 0x38
     171#define PCI_CB_IO_LIMIT_1_HI  0x3a
     172#define  PCI_CB_IO_RANGE_MASK ~0x03
    173173/* 0x3c-0x3d are same as for htype 0 */
    174 #define PCI_CB_BRIDGE_CONTROL   0x3e
    175 #define  PCI_CB_BRIDGE_CTL_PARITY       0x01    /* Similar to standard bridge control register */
    176 #define  PCI_CB_BRIDGE_CTL_SERR         0x02
    177 #define  PCI_CB_BRIDGE_CTL_ISA          0x04
    178 #define  PCI_CB_BRIDGE_CTL_VGA          0x08
    179 #define  PCI_CB_BRIDGE_CTL_MASTER_ABORT 0x20
    180 #define  PCI_CB_BRIDGE_CTL_CB_RESET     0x40    /* CardBus reset */
    181 #define  PCI_CB_BRIDGE_CTL_16BIT_INT    0x80    /* Enable interrupt for 16-bit cards */
    182 #define  PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100  /* Prefetch enable for both memory regions */
     174#define PCI_CB_BRIDGE_CONTROL 0x3e
     175#define  PCI_CB_BRIDGE_CTL_PARITY 0x01  /* Similar to standard bridge control register */
     176#define  PCI_CB_BRIDGE_CTL_SERR   0x02
     177#define  PCI_CB_BRIDGE_CTL_ISA    0x04
     178#define  PCI_CB_BRIDGE_CTL_VGA    0x08
     179#define  PCI_CB_BRIDGE_CTL_MASTER_ABORT 0x20
     180#define  PCI_CB_BRIDGE_CTL_CB_RESET 0x40  /* CardBus reset */
     181#define  PCI_CB_BRIDGE_CTL_16BIT_INT  0x80  /* Enable interrupt for 16-bit cards */
     182#define  PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100  /* Prefetch enable for both memory regions */
    183183#define  PCI_CB_BRIDGE_CTL_PREFETCH_MEM1 0x200
    184 #define  PCI_CB_BRIDGE_CTL_POST_WRITES  0x400
     184#define  PCI_CB_BRIDGE_CTL_POST_WRITES  0x400
    185185#define PCI_CB_SUBSYSTEM_VENDOR_ID 0x40
    186 #define PCI_CB_SUBSYSTEM_ID     0x42
    187 #define PCI_CB_LEGACY_MODE_BASE 0x44    /* 16-bit PC Card legacy mode base address (ExCa) */
     186#define PCI_CB_SUBSYSTEM_ID 0x42
     187#define PCI_CB_LEGACY_MODE_BASE 0x44  /* 16-bit PC Card legacy mode base address (ExCa) */
    188188/* 0x48-0x7f reserved */
    189189
    190190/* Capability lists */
    191191
    192 #define PCI_CAP_LIST_ID         0       /* Capability ID */
    193 #define  PCI_CAP_ID_PM          0x01    /* Power Management */
    194 #define  PCI_CAP_ID_AGP         0x02    /* Accelerated Graphics Port */
    195 #define  PCI_CAP_ID_VPD         0x03    /* Vital Product Data */
    196 #define  PCI_CAP_ID_SLOTID      0x04    /* Slot Identification */
    197 #define  PCI_CAP_ID_MSI         0x05    /* Message Signalled Interrupts */
    198 #define  PCI_CAP_ID_CHSWP       0x06    /* CompactPCI HotSwap */
    199 #define PCI_CAP_LIST_NEXT       1       /* Next capability in the list */
    200 #define PCI_CAP_FLAGS           2       /* Capability defined flags (16 bits) */
    201 #define PCI_CAP_SIZEOF          4
     192#define PCI_CAP_LIST_ID   0 /* Capability ID */
     193#define  PCI_CAP_ID_PM    0x01  /* Power Management */
     194#define  PCI_CAP_ID_AGP   0x02  /* Accelerated Graphics Port */
     195#define  PCI_CAP_ID_VPD   0x03  /* Vital Product Data */
     196#define  PCI_CAP_ID_SLOTID  0x04  /* Slot Identification */
     197#define  PCI_CAP_ID_MSI   0x05  /* Message Signalled Interrupts */
     198#define  PCI_CAP_ID_CHSWP 0x06  /* CompactPCI HotSwap */
     199#define PCI_CAP_LIST_NEXT 1 /* Next capability in the list */
     200#define PCI_CAP_FLAGS   2 /* Capability defined flags (16 bits) */
     201#define PCI_CAP_SIZEOF    4
    202202
    203203/* Power Management Registers */
    204204#define  PCI_PM_PMC              2       /* PM Capabilities Register */
    205 #define  PCI_PM_CAP_VER_MASK    0x0007  /* Version */
    206 #define  PCI_PM_CAP_PME_CLOCK   0x0008  /* PME clock required */
    207 #define  PCI_PM_CAP_AUX_POWER   0x0010  /* Auxilliary power support */
    208 #define  PCI_PM_CAP_DSI         0x0020  /* Device specific initialization */
    209 #define  PCI_PM_CAP_D1          0x0200  /* D1 power state support */
    210 #define  PCI_PM_CAP_D2          0x0400  /* D2 power state support */
    211 #define  PCI_PM_CAP_PME         0x0800  /* PME pin supported */
    212 #define  PCI_PM_CTRL            4       /* PM control and status register */
    213 #define  PCI_PM_CTRL_STATE_MASK 0x0003  /* Current power state (D0 to D3) */
    214 #define  PCI_PM_CTRL_PME_ENABLE 0x0100  /* PME pin enable */
    215 #define  PCI_PM_CTRL_DATA_SEL_MASK      0x1e00  /* Data select (??) */
    216 #define  PCI_PM_CTRL_DATA_SCALE_MASK    0x6000  /* Data scale (??) */
    217 #define  PCI_PM_CTRL_PME_STATUS 0x8000  /* PME pin status */
    218 #define  PCI_PM_PPB_EXTENSIONS  6       /* PPB support extensions (??) */
    219 #define  PCI_PM_PPB_B2_B3       0x40    /* Stop clock when in D3hot (??) */
    220 #define  PCI_PM_BPCC_ENABLE     0x80    /* Bus power/clock control enable (??) */
    221 #define  PCI_PM_DATA_REGISTER   7       /* (??) */
    222 #define  PCI_PM_SIZEOF          8
     205#define  PCI_PM_CAP_VER_MASK  0x0007  /* Version */
     206#define  PCI_PM_CAP_PME_CLOCK 0x0008  /* PME clock required */
     207#define  PCI_PM_CAP_AUX_POWER 0x0010  /* Auxilliary power support */
     208#define  PCI_PM_CAP_DSI   0x0020  /* Device specific initialization */
     209#define  PCI_PM_CAP_D1    0x0200  /* D1 power state support */
     210#define  PCI_PM_CAP_D2    0x0400  /* D2 power state support */
     211#define  PCI_PM_CAP_PME   0x0800  /* PME pin supported */
     212#define  PCI_PM_CTRL    4 /* PM control and status register */
     213#define  PCI_PM_CTRL_STATE_MASK 0x0003  /* Current power state (D0 to D3) */
     214#define  PCI_PM_CTRL_PME_ENABLE 0x0100  /* PME pin enable */
     215#define  PCI_PM_CTRL_DATA_SEL_MASK  0x1e00  /* Data select (??) */
     216#define  PCI_PM_CTRL_DATA_SCALE_MASK  0x6000  /* Data scale (??) */
     217#define  PCI_PM_CTRL_PME_STATUS 0x8000  /* PME pin status */
     218#define  PCI_PM_PPB_EXTENSIONS  6 /* PPB support extensions (??) */
     219#define  PCI_PM_PPB_B2_B3 0x40  /* Stop clock when in D3hot (??) */
     220#define  PCI_PM_BPCC_ENABLE 0x80  /* Bus power/clock control enable (??) */
     221#define  PCI_PM_DATA_REGISTER 7 /* (??) */
     222#define  PCI_PM_SIZEOF    8
    223223
    224224/* AGP registers */
    225225
    226 #define PCI_AGP_VERSION         2       /* BCD version number */
    227 #define PCI_AGP_RFU             3       /* Rest of capability flags */
    228 #define PCI_AGP_STATUS          4       /* Status register */
    229 #define  PCI_AGP_STATUS_RQ_MASK 0xff000000      /* Maximum number of requests - 1 */
    230 #define  PCI_AGP_STATUS_SBA     0x0200  /* Sideband addressing supported */
    231 #define  PCI_AGP_STATUS_64BIT   0x0020  /* 64-bit addressing supported */
    232 #define  PCI_AGP_STATUS_FW      0x0010  /* FW transfers supported */
    233 #define  PCI_AGP_STATUS_RATE4   0x0004  /* 4x transfer rate supported */
    234 #define  PCI_AGP_STATUS_RATE2   0x0002  /* 2x transfer rate supported */
    235 #define  PCI_AGP_STATUS_RATE1   0x0001  /* 1x transfer rate supported */
    236 #define PCI_AGP_COMMAND         8       /* Control register */
     226#define PCI_AGP_VERSION   2 /* BCD version number */
     227#define PCI_AGP_RFU   3 /* Rest of capability flags */
     228#define PCI_AGP_STATUS    4 /* Status register */
     229#define  PCI_AGP_STATUS_RQ_MASK 0xff000000  /* Maximum number of requests - 1 */
     230#define  PCI_AGP_STATUS_SBA 0x0200  /* Sideband addressing supported */
     231#define  PCI_AGP_STATUS_64BIT 0x0020  /* 64-bit addressing supported */
     232#define  PCI_AGP_STATUS_FW  0x0010  /* FW transfers supported */
     233#define  PCI_AGP_STATUS_RATE4 0x0004  /* 4x transfer rate supported */
     234#define  PCI_AGP_STATUS_RATE2 0x0002  /* 2x transfer rate supported */
     235#define  PCI_AGP_STATUS_RATE1 0x0001  /* 1x transfer rate supported */
     236#define PCI_AGP_COMMAND   8 /* Control register */
    237237#define  PCI_AGP_COMMAND_RQ_MASK 0xff000000  /* Master: Maximum number of requests */
    238 #define  PCI_AGP_COMMAND_SBA    0x0200  /* Sideband addressing enabled */
    239 #define  PCI_AGP_COMMAND_AGP    0x0100  /* Allow processing of AGP transactions */
    240 #define  PCI_AGP_COMMAND_64BIT  0x0020  /* Allow processing of 64-bit addresses */
    241 #define  PCI_AGP_COMMAND_FW     0x0010  /* Force FW transfers */
    242 #define  PCI_AGP_COMMAND_RATE4  0x0004  /* Use 4x rate */
    243 #define  PCI_AGP_COMMAND_RATE2  0x0002  /* Use 4x rate */
    244 #define  PCI_AGP_COMMAND_RATE1  0x0001  /* Use 4x rate */
    245 #define PCI_AGP_SIZEOF          12
     238#define  PCI_AGP_COMMAND_SBA  0x0200  /* Sideband addressing enabled */
     239#define  PCI_AGP_COMMAND_AGP  0x0100  /* Allow processing of AGP transactions */
     240#define  PCI_AGP_COMMAND_64BIT  0x0020  /* Allow processing of 64-bit addresses */
     241#define  PCI_AGP_COMMAND_FW 0x0010  /* Force FW transfers */
     242#define  PCI_AGP_COMMAND_RATE4  0x0004  /* Use 4x rate */
     243#define  PCI_AGP_COMMAND_RATE2  0x0002  /* Use 4x rate */
     244#define  PCI_AGP_COMMAND_RATE1  0x0001  /* Use 4x rate */
     245#define PCI_AGP_SIZEOF    12
    246246
    247247/* Slot Identification */
    248248
    249 #define PCI_SID_ESR             2       /* Expansion Slot Register */
    250 #define  PCI_SID_ESR_NSLOTS     0x1f    /* Number of expansion slots available */
    251 #define  PCI_SID_ESR_FIC        0x20    /* First In Chassis Flag */
    252 #define PCI_SID_CHASSIS_NR      3       /* Chassis Number */
     249#define PCI_SID_ESR   2 /* Expansion Slot Register */
     250#define  PCI_SID_ESR_NSLOTS 0x1f  /* Number of expansion slots available */
     251#define  PCI_SID_ESR_FIC  0x20  /* First In Chassis Flag */
     252#define PCI_SID_CHASSIS_NR  3 /* Chassis Number */
    253253
    254254/* Message Signalled Interrupts registers */
    255255
    256 #define PCI_MSI_FLAGS           2       /* Various flags */
    257 #define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
    258 #define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured */
    259 #define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available */
    260 #define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
    261 #define PCI_MSI_RFU             3       /* Rest of capability flags */
    262 #define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
    263 #define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
    264 #define PCI_MSI_DATA_32         8       /* 16 bits of data for 32-bit devices */
    265 #define PCI_MSI_DATA_64         12      /* 16 bits of data for 64-bit devices */
     256#define PCI_MSI_FLAGS   2 /* Various flags */
     257#define  PCI_MSI_FLAGS_64BIT  0x80  /* 64-bit addresses allowed */
     258#define  PCI_MSI_FLAGS_QSIZE  0x70  /* Message queue size configured */
     259#define  PCI_MSI_FLAGS_QMASK  0x0e  /* Maximum queue size available */
     260#define  PCI_MSI_FLAGS_ENABLE 0x01  /* MSI feature enabled */
     261#define PCI_MSI_RFU   3 /* Rest of capability flags */
     262#define PCI_MSI_ADDRESS_LO  4 /* Lower 32 bits */
     263#define PCI_MSI_ADDRESS_HI  8 /* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
     264#define PCI_MSI_DATA_32   8 /* 16 bits of data for 32-bit devices */
     265#define PCI_MSI_DATA_64   12  /* 16 bits of data for 64-bit devices */
    266266
    267267/* Include the ID list */
     
    274274 * in a single byte as follows:
    275275 *
    276  *      7:3 = slot
    277  *      2:0 = function
    278  */
    279 #define PCI_DEVFN(slot,func)    ((((slot) & 0x1f) << 3) | ((func) & 0x07))
    280 #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
    281 #define PCI_FUNC(devfn)         ((devfn) & 0x07)
     276 *  7:3 = slot
     277 *  2:0 = function
     278 */
     279#define PCI_DEVFN(slot,func)  ((((slot) & 0x1f) << 3) | ((func) & 0x07))
     280#define PCI_SLOT(devfn)   (((devfn) >> 3) & 0x1f)
     281#define PCI_FUNC(devfn)   ((devfn) & 0x07)
    282282
    283283#ifdef __KERNEL__
     
    287287
    288288#include <asm/pci.h>
    289 #define BUS_ID_SIZE             20
    290 #define DEVICE_COUNT_COMPATIBLE 4
    291 #define DEVICE_COUNT_IRQ        2
    292 #define DEVICE_COUNT_DMA        2
    293 #define DEVICE_COUNT_RESOURCE   12
     289#define BUS_ID_SIZE   20
     290#define DEVICE_COUNT_COMPATIBLE 4
     291#define DEVICE_COUNT_IRQ  2
     292#define DEVICE_COUNT_DMA  2
     293#define DEVICE_COUNT_RESOURCE 12
    294294
    295295typedef struct pci_dev;
     
    303303
    304304typedef struct device {
    305     struct pci_dev *pci;        /* for PCI and PCI-SG types */
    306         struct device   * parent;
    307         struct bus_type * bus;          /* type of bus device is on */
    308         char    bus_id[BUS_ID_SIZE];    /* position on parent bus */
    309         void    (*release)(struct device * dev);
    310     unsigned int flags; /* GFP_XXX for continous and ISA types */
     305    struct pci_dev *pci;  /* for PCI and PCI-SG types */
     306  struct device   * parent;
     307  struct bus_type * bus;    /* type of bus device is on */
     308  char  bus_id[BUS_ID_SIZE];  /* position on parent bus */
     309  void  (*release)(struct device * dev);
     310    unsigned int flags; /* GFP_XXX for continous and ISA types */
    311311#ifdef CONFIG_SBUS
    312     struct sbus_dev *sbus;      /* for SBUS type */
     312    struct sbus_dev *sbus;  /* for SBUS type */
    313313#endif
    314         void *private_data;
    315         void *platform_data;
    316 
    317         struct device_driver *driver;
    318         struct pm_dev *pm_dev;
    319         char    bus_id[20];
     314  void *private_data;
     315  void *platform_data;
     316
     317  struct device_driver *driver;
     318  struct pm_dev *pm_dev;
     319  char  bus_id[20];
    320320} device;
    321321
     
    324324 */
    325325struct pci_dev {
    326         int active;                     /* device is active */
    327         int ro;                         /* Read/Only */
    328 
    329         struct pci_bus  *bus;           /* bus this device is on */
    330         struct pci_dev  *sibling;       /* next device on this bus */
    331         struct pci_dev  *next;          /* chain of all devices */
    332 
    333         void            *sysdata;       /* hook for sys-specific extension */
    334         struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
     326  int active;     /* device is active */
     327  int ro;       /* Read/Only */
     328
     329  struct pci_bus  *bus;   /* bus this device is on */
     330  struct pci_dev  *sibling; /* next device on this bus */
     331  struct pci_dev  *next;    /* chain of all devices */
     332
     333  void    *sysdata; /* hook for sys-specific extension */
     334  struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
    335335
    336336        struct device   dev;
    337337
    338         unsigned int    devfn;          /* encoded device & function index */
    339         unsigned short  vendor;
    340         unsigned short  device;
    341         unsigned short  subsystem_vendor;
    342         unsigned short  subsystem_device;
    343         unsigned int    _class;         /* 3 bytes: (base,sub,prog-if) */
    344         u8              hdr_type;       /* PCI header type (`multi' flag masked out) */
    345         u8              rom_base_reg;   /* Which config register controls the ROM */
    346 
    347         unsigned short  regs;
    348 
    349         u32             current_state;  /* Current operating state. In ACPI-speak,
    350                                            this is D0-D3, D0 being fully functional,
    351                                            and D3 being off. */
    352 
    353         /* device is compatible with these IDs */
    354         unsigned short vendor_compatible[DEVICE_COUNT_COMPATIBLE];
    355         unsigned short device_compatible[DEVICE_COUNT_COMPATIBLE];
    356 
    357         /*
    358          * Instead of touching interrupt line and base address registers
    359          * directly, use the values stored here. They might be different!
    360          */
    361         unsigned int    irq;
    362         struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
    363         struct resource dma_resource[DEVICE_COUNT_DMA];
    364         struct resource irq_resource[DEVICE_COUNT_IRQ];
    365 
    366         char            name[48];       /* Device name */
    367         char            slot_name[8];   /* Slot name */
    368 
    369         void           *driver_data;
    370         unsigned long   dma_mask;
    371 
    372         int (*prepare)(struct pci_dev *dev);
    373         int (*activate)(struct pci_dev *dev);
    374         int (*deactivate)(struct pci_dev *dev);
     338  unsigned int  devfn;    /* encoded device & function index */
     339  unsigned short  vendor;
     340  unsigned short  device;
     341  unsigned short  subsystem_vendor;
     342  unsigned short  subsystem_device;
     343  unsigned int  _class;   /* 3 bytes: (base,sub,prog-if) */
     344  u8    hdr_type; /* PCI header type (`multi' flag masked out) */
     345  u8    rom_base_reg; /* Which config register controls the ROM */
     346
     347        unsigned short  regs;
     348
     349  u32             current_state;  /* Current operating state. In ACPI-speak,
     350             this is D0-D3, D0 being fully functional,
     351             and D3 being off. */
     352
     353  /* device is compatible with these IDs */
     354  unsigned short vendor_compatible[DEVICE_COUNT_COMPATIBLE];
     355  unsigned short device_compatible[DEVICE_COUNT_COMPATIBLE];
     356
     357  /*
     358   * Instead of touching interrupt line and base address registers
     359   * directly, use the values stored here. They might be different!
     360   */
     361  unsigned int  irq;
     362  unsigned char irq_pin;
     363  struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
     364  struct resource dma_resource[DEVICE_COUNT_DMA];
     365  struct resource irq_resource[DEVICE_COUNT_IRQ];
     366
     367  char    name[48]; /* Device name */
     368  char    slot_name[8]; /* Slot name */
     369
     370  void         *driver_data;
     371  unsigned long   dma_mask;
     372
     373  int (*prepare)(struct pci_dev *dev);
     374  int (*activate)(struct pci_dev *dev);
     375  int (*deactivate)(struct pci_dev *dev);
    375376#ifdef TARGET_OS2
    376         unsigned int picirq;
    377         unsigned int apicirq;
    378         unsigned long hAdapter;
    379         unsigned long hDevice;
    380         void *pcidriver;
     377//DAZ unsigned int picirq;
     378//DAZ unsigned int apicirq;
     379  unsigned long hAdapter;
     380  unsigned long hDevice;
     381  void *pcidriver;
    381382#endif
    382383};
     
    385386 *  For PCI devices, the region numbers are assigned this way:
    386387 *
    387  *      0-5     standard PCI regions
    388  *      6       expansion ROM
    389  *      7-10    bridges: address space assigned to buses behind the bridge
     388 *  0-5 standard PCI regions
     389 *  6 expansion ROM
     390 *  7-10  bridges: address space assigned to buses behind the bridge
    390391 */
    391392
     
    394395#define PCI_NUM_RESOURCES 11
    395396
    396 #define PCI_REGION_FLAG_MASK 0x0f       /* These bits of resource flags tell us the PCI region flags */
     397#define PCI_REGION_FLAG_MASK 0x0f /* These bits of resource flags tell us the PCI region flags */
    397398
    398399struct pci_bus {
    399         struct pci_bus  *parent;        /* parent bus this bridge is on */
    400         struct pci_bus  *children;      /* chain of P2P bridges on this bus */
    401         struct pci_bus  *next;          /* chain of all PCI buses */
    402         struct pci_ops  *ops;           /* configuration access functions */
    403 
    404         struct pci_dev  *self;          /* bridge device as seen by parent */
    405         struct pci_dev  *devices;       /* devices behind this bridge */
    406         struct resource *resource[4];   /* address space routed to this bus */
    407 
    408         void            *sysdata;       /* hook for sys-specific extension */
    409         struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
    410 
    411         unsigned char   number;         /* bus number */
    412         unsigned char   primary;        /* number of primary bridge */
    413         unsigned char   secondary;      /* number of secondary bridge */
    414         unsigned char   subordinate;    /* max number of subordinate buses */
    415 
    416         char            name[48];
    417         unsigned short  vendor;
    418         unsigned short  device;
    419         unsigned int    serial;         /* serial number */
    420         unsigned char   pnpver;         /* Plug & Play version */
    421         unsigned char   productver;     /* product version */
    422         unsigned char   checksum;       /* if zero - checksum passed */
    423         unsigned char   pad1;
     400  struct pci_bus  *parent;  /* parent bus this bridge is on */
     401  struct pci_bus  *children;  /* chain of P2P bridges on this bus */
     402  struct pci_bus  *next;    /* chain of all PCI buses */
     403  struct pci_ops  *ops;   /* configuration access functions */
     404
     405  struct pci_dev  *self;    /* bridge device as seen by parent */
     406  struct pci_dev  *devices; /* devices behind this bridge */
     407  struct resource *resource[4]; /* address space routed to this bus */
     408
     409  void    *sysdata; /* hook for sys-specific extension */
     410  struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
     411
     412  unsigned char number;   /* bus number */
     413  unsigned char primary;  /* number of primary bridge */
     414  unsigned char secondary;  /* number of secondary bridge */
     415  unsigned char subordinate;  /* max number of subordinate buses */
     416
     417  char    name[48];
     418  unsigned short  vendor;
     419  unsigned short  device;
     420  unsigned int  serial;   /* serial number */
     421  unsigned char pnpver;   /* Plug & Play version */
     422  unsigned char productver; /* product version */
     423  unsigned char checksum; /* if zero - checksum passed */
     424  unsigned char pad1;
    424425};
    425426
    426 //extern struct pci_bus *pci_root;      /* root bus */
    427 //extern struct pci_dev *pci_devices;   /* list of all devices */
     427//extern struct pci_bus *pci_root;  /* root bus */
     428//extern struct pci_dev *pci_devices; /* list of all devices */
    428429
    429430/*
    430431 * Error values that may be returned by PCI functions.
    431432 */
    432 #define PCIBIOS_SUCCESSFUL              0x00
    433 #define PCIBIOS_FUNC_NOT_SUPPORTED      0x81
    434 #define PCIBIOS_BAD_VENDOR_ID           0x83
    435 #define PCIBIOS_DEVICE_NOT_FOUND        0x86
    436 #define PCIBIOS_BAD_REGISTER_NUMBER     0x87
    437 #define PCIBIOS_SET_FAILED              0x88
    438 #define PCIBIOS_BUFFER_TOO_SMALL        0x89
     433#define PCIBIOS_SUCCESSFUL    0x00
     434#define PCIBIOS_FUNC_NOT_SUPPORTED  0x81
     435#define PCIBIOS_BAD_VENDOR_ID   0x83
     436#define PCIBIOS_DEVICE_NOT_FOUND  0x86
     437#define PCIBIOS_BAD_REGISTER_NUMBER 0x87
     438#define PCIBIOS_SET_FAILED    0x88
     439#define PCIBIOS_BUFFER_TOO_SMALL  0x89
    439440
    440441/* Low-level architecture-dependent routines */
    441442
    442443struct pci_ops {
    443         int (*read_byte)(struct pci_dev *, int where, u8 *val);
    444         int (*read_word)(struct pci_dev *, int where, u16 *val);
    445         int (*read_dword)(struct pci_dev *, int where, u32 *val);
    446         int (*write_byte)(struct pci_dev *, int where, u8 val);
    447         int (*write_word)(struct pci_dev *, int where, u16 val);
    448         int (*write_dword)(struct pci_dev *, int where, u32 val);
     444  int (*read_byte)(struct pci_dev *, int where, u8 *val);
     445  int (*read_word)(struct pci_dev *, int where, u16 *val);
     446  int (*read_dword)(struct pci_dev *, int where, u32 *val);
     447  int (*write_byte)(struct pci_dev *, int where, u8 val);
     448  int (*write_word)(struct pci_dev *, int where, u16 val);
     449  int (*write_dword)(struct pci_dev *, int where, u32 val);
    449450};
    450451
     
    455456
    456457void pcibios_update_resource(struct pci_dev *, struct resource *,
    457                              struct resource *, int);
     458           struct resource *, int);
    458459void pcibios_update_irq(struct pci_dev *, int irq);
    459460
     
    463464#define pci_present pcibios_present
    464465int pcibios_read_config_byte (unsigned char bus, unsigned char dev_fn,
    465                               unsigned char where, unsigned char *val);
     466            unsigned char where, unsigned char *val);
    466467int pcibios_read_config_word (unsigned char bus, unsigned char dev_fn,
    467                               unsigned char where, unsigned short *val);
     468            unsigned char where, unsigned short *val);
    468469int pcibios_read_config_dword (unsigned char bus, unsigned char dev_fn,
    469                                unsigned char where, unsigned int *val);
     470             unsigned char where, unsigned int *val);
    470471int pcibios_write_config_byte (unsigned char bus, unsigned char dev_fn,
    471                                unsigned char where, unsigned char val);
     472             unsigned char where, unsigned char val);
    472473int pcibios_write_config_word (unsigned char bus, unsigned char dev_fn,
    473                                unsigned char where, unsigned short val);
     474             unsigned char where, unsigned short val);
    474475int pcibios_write_config_dword (unsigned char bus, unsigned char dev_fn,
    475                                 unsigned char where, unsigned int val);
     476        unsigned char where, unsigned int val);
    476477int pcibios_find_class (unsigned int class_code, unsigned short index, unsigned char *bus, unsigned char *dev_fn);
    477478int pcibios_find_device (unsigned short vendor, unsigned short dev_id,
    478                         unsigned short index, unsigned char *bus,
    479                         unsigned char *dev_fn);
     479      unsigned short index, unsigned char *bus,
     480      unsigned char *dev_fn);
    480481
    481482/* Generic PCI interface functions */
     
    491492struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, struct pci_dev *from);
    492493struct pci_dev *pci_find_subsys (unsigned int vendor, unsigned int device,
    493                                 unsigned int ss_vendor, unsigned int ss_device,
    494                                 struct pci_dev *from);
     494        unsigned int ss_vendor, unsigned int ss_device,
     495        struct pci_dev *from);
    495496struct pci_dev *pci_find_class (unsigned int _class, struct pci_dev *from);
    496497struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn);
     
    516517void pci_set_bus_ranges(void);
    517518void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
    518                     int (*)(struct pci_dev *, u8, u8));
     519        int (*)(struct pci_dev *, u8, u8));
    519520
    520521/*
     
    524525struct pci_simple_probe_entry;
    525526typedef int (*pci_simple_probe_callback) (struct pci_dev *dev, int match_num,
    526                                           const struct pci_simple_probe_entry *ent,
    527                                           void *drvr_data);
     527              const struct pci_simple_probe_entry *ent,
     528            void *drvr_data);
    528529
    529530struct pci_simple_probe_entry {
    530         unsigned short vendor;  /* vendor id, PCI_ANY_ID, or 0 for last entry */
    531         unsigned short device;  /* device id, PCI_ANY_ID, or 0 for last entry */
    532         unsigned short subsys_vendor; /* subsystem vendor id, 0 for don't care */
    533         unsigned short subsys_device; /* subsystem device id, 0 for don't care */
    534         void *dev_data;         /* driver-private, entry-specific data */
     531  unsigned short vendor;  /* vendor id, PCI_ANY_ID, or 0 for last entry */
     532  unsigned short device;  /* device id, PCI_ANY_ID, or 0 for last entry */
     533  unsigned short subsys_vendor; /* subsystem vendor id, 0 for don't care */
     534  unsigned short subsys_device; /* subsystem device id, 0 for don't care */
     535  void *dev_data;   /* driver-private, entry-specific data */
    535536};
    536537
    537538int pci_simple_probe (const struct pci_simple_probe_entry *list,
    538                       size_t match_limit, pci_simple_probe_callback cb,
    539                       void *drvr_data);
     539          size_t match_limit, pci_simple_probe_callback cb,
     540          void *drvr_data);
    540541
    541542
     
    554555
    555556struct pci_fixup {
    556         int pass;
    557         u16 vendor, device;                     /* You can use PCI_ANY_ID here of course */
    558         void (*hook)(struct pci_dev *dev);
     557  int pass;
     558  u16 vendor, device;     /* You can use PCI_ANY_ID here of course */
     559  void (*hook)(struct pci_dev *dev);
    559560};
    560561
    561562extern struct pci_fixup pcibios_fixups[];
    562563
    563 #define PCI_FIXUP_HEADER        1               /* Called immediately after reading configuration header */
    564 #define PCI_FIXUP_FINAL         2               /* Final phase of device fixups */
     564#define PCI_FIXUP_HEADER  1   /* Called immediately after reading configuration header */
     565#define PCI_FIXUP_FINAL   2   /* Final phase of device fixups */
    565566
    566567void pci_fixup_device(int pass, struct pci_dev *dev);
    567568
    568569extern int pci_pci_problems;
    569 #define PCIPCI_FAIL             1
    570 #define PCIPCI_TRITON           2
    571 #define PCIPCI_NATOMA           4
     570#define PCIPCI_FAIL   1
     571#define PCIPCI_TRITON   2
     572#define PCIPCI_NATOMA   4
    572573
    573574
     
    590591#else
    591592struct pci_driver {
    592         struct list_head node;
    593         struct pci_dev *dev;
    594         char *name;
    595         const struct pci_device_id *id_table;   /* NULL if wants all devices */
    596         int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
    597         void (*remove)(struct pci_dev *dev);    /* Device removed (NULL if not a hot-plug capable driver) */
    598         int (*suspend)(struct pci_dev *dev, u32 stgate);        /* Device suspended */
    599         int (*resume)(struct pci_dev *dev);     /* Device woken up */
     593  struct list_head node;
     594  struct pci_dev *dev;
     595  char *name;
     596  const struct pci_device_id *id_table; /* NULL if wants all devices */
     597  int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
     598  void (*remove)(struct pci_dev *dev);  /* Device removed (NULL if not a hot-plug capable driver) */
     599  int (*suspend)(struct pci_dev *dev, u32 stgate);  /* Device suspended */
     600  int (*resume)(struct pci_dev *dev); /* Device woken up */
    600601};
    601602#endif
     
    619620
    620621#define pci_for_each_dev(dev) \
    621         for(dev = pci_devices; dev; dev = dev->next)
     622  for(dev = pci_devices; dev; dev = dev->next)
    622623
    623624#define pci_resource_start(dev,bar) \
     
    692693static inline unsigned char snd_pci_revision(struct pci_dev *pci)
    693694{
    694         unsigned char rev;
    695         pci_read_config_byte(pci, PCI_REVISION_ID, &rev);
    696         return rev;
     695  unsigned char rev;
     696  pci_read_config_byte(pci, PCI_REVISION_ID, &rev);
     697  return rev;
    697698}
    698699
     
    701702
    702703/* MSI */
    703 static inline int snd_pci_enable_msi(struct pci_dev *dev) { return -1; }
     704extern int snd_pci_enable_msi(struct pci_dev *dev);
    704705#undef pci_enable_msi
    705706#define pci_enable_msi(dev) snd_pci_enable_msi(dev)
     
    711712static inline void *pci_ioremap_bar(struct pci_dev *pdev, int bar)
    712713{
    713         return __ioremap(pci_resource_start(pdev, bar),
    714                                pci_resource_len(pdev, bar),0x010);
     714  return __ioremap(pci_resource_start(pdev, bar),
     715             pci_resource_len(pdev, bar),0x010);
    715716}
    716717
    717 #define PCI_VDEVICE(vendor, device)             \
    718         PCI_VENDOR_ID_##vendor, (device),       \
    719         PCI_ANY_ID, PCI_ANY_ID, 0, 0
     718#define PCI_VDEVICE(vendor, device)   \
     719  PCI_VENDOR_ID_##vendor, (device), \
     720  PCI_ANY_ID, PCI_ANY_ID, 0, 0
    720721
    721722#define pci_clear_master(x)
     
    725726 */
    726727#define DEFINE_PCI_DEVICE_TABLE(_table) \
    727         const struct pci_device_id _table[] __devinitdata
     728  const struct pci_device_id _table[] __devinitdata
    728729
    729730#endif /* LINUX_PCI_H */
  • GPL/trunk/lib32/Makefile

    r598 r604  
    1010!if "$(IBM_BUILD)" == "1"
    1111CDEFINES += -DIBM_BUILD
     12!endif
     13
     14!ifdef %DRV32KIT
     15CDEFINES+= -DUSE_MSI
    1216!endif
    1317
  • GPL/trunk/lib32/irq.c

    r577 r604  
    4242//******************************************************************************
    4343
    44 static IRQ_SLOT         arSlots[MAX_IRQ_SLOTS] = { 0 };
    45 static ULONG               eoiIrq[255] = {0};
     44static IRQ_SLOT   arSlots[MAX_IRQ_SLOTS] = { 0 };
     45static ULONG       eoiIrq[255] = {0};
    4646
    4747
     
    5050static IRQ_SLOT *FindSlot(unsigned irq)
    5151{
    52         IRQ_SLOT          *pSlot;
    53 
    54         for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
    55         {
    56                 if( pSlot->irqNo == irq )       return pSlot;
    57         }
    58 
    59         return NULL;
     52  IRQ_SLOT    *pSlot;
     53
     54  for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
     55  {
     56    if( pSlot->irqNo == irq ) return pSlot;
     57  }
     58
     59  return NULL;
    6060}
    6161
     
    6565
    6666int request_irq(unsigned irq, irq_handler_t handler,
    67                         unsigned long ulSharedFlag, const char *pchName, void *pUserData)
    68 {
    69         IRQ_SLOT        *pSlot = FindSlot(irq & 0xff);
    70         unsigned        u, uSlotNo = (unsigned)-1;
    71         ULONG hRes;
    72 
    73         rprintf(("request_irq: irq %d", irq & 0xff ));
    74         if ( !pSlot ) {
    75                 // find empty slot
    76                 for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ ) {
    77                         if( arSlots[uSlotNo].flHandlers == 0 ) {
    78                                 pSlot = &arSlots[uSlotNo];
    79                                 break;
    80                         }
    81                 }
    82         }
    83 
    84         if ( pSlot ) {
    85                 hRes = 0;
    86                 if (RMRequestIRQ(irq, (ulSharedFlag & SA_SHIRQ) != 0, &hRes) == FALSE) {
    87                         rprintf(("RMRequestIRQ failed for irq %d", irq));
    88                         return 1;
    89                 }
    90                 pSlot->irqNo = irq & 0xff;
    91                 pSlot->hRes = hRes;
    92 
    93                 for ( u = 0; u < MAX_SHAREDIRQS; u++ ) {
    94                         if ( pSlot->irqHandlers[u].handler == NULL ) {
    95                                 pSlot->irqHandlers[u].handler = handler;
    96                                 pSlot->irqHandlers[u].x0 = ulSharedFlag;
    97                                 pSlot->irqHandlers[u].x1 = (char *)pchName;
    98                                 pSlot->irqHandlers[u].x2 = pUserData;
    99 
    100                                 if( pSlot->flHandlers != 0 || ALSA_SetIrq( irq & 0xff, uSlotNo, (ulSharedFlag & SA_SHIRQ) != 0) ) {
    101                                         pSlot->flHandlers |= 1 << u;
    102                                         return 0;
    103                                 }
    104 
    105                                 break;
    106                         }
    107                 }
    108         }
    109 
    110         rprintf(("request_irq: Unable to register irq handler for irq %d", irq & 0xff ));
    111         return 1;
     67      unsigned long ulSharedFlag, const char *pchName, void *pUserData)
     68{
     69  IRQ_SLOT  *pSlot = FindSlot(irq & 0xff);
     70  unsigned  u, uSlotNo = (unsigned)-1;
     71  ULONG hRes;
     72
     73  rprintf(("request_irq: irq %d", irq & 0xff ));
     74  if ( !pSlot )
     75  {
     76    // find empty slot
     77    for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ )
     78    {
     79      if( arSlots[uSlotNo].flHandlers == 0 )
     80      {
     81        pSlot = &arSlots[uSlotNo];
     82        break;
     83      }
     84    }
     85  }
     86
     87  if ( pSlot )
     88  {
     89    hRes = 0;
     90    if (RMRequestIRQ(irq, (ulSharedFlag & SA_SHIRQ) != 0, &hRes) == FALSE)
     91    {
     92      rprintf(("RMRequestIRQ failed for irq %d", irq));
     93      return 1;
     94    }
     95    pSlot->irqNo = irq & 0xff;
     96    pSlot->hRes = hRes;
     97
     98    for ( u = 0; u < MAX_SHAREDIRQS; u++ )
     99    {
     100      if ( pSlot->irqHandlers[u].handler == NULL )
     101      {
     102        pSlot->irqHandlers[u].handler = handler;
     103        pSlot->irqHandlers[u].x0 = ulSharedFlag;
     104        pSlot->irqHandlers[u].x1 = (char *)pchName;
     105        pSlot->irqHandlers[u].x2 = pUserData;
     106
     107        if( pSlot->flHandlers != 0 || ALSA_SetIrq( irq & 0xff, uSlotNo, (ulSharedFlag & SA_SHIRQ) != 0) )
     108        {
     109          pSlot->flHandlers |= 1 << u;
     110          return 0;
     111        }
     112
     113        break;
     114      }
     115    }
     116  }
     117
     118  rprintf(("request_irq: Unable to register irq handler for irq %d", irq & 0xff ));
     119  return 1;
    112120}
    113121
     
    117125void free_irq(unsigned int irq, void *userdata)
    118126{
    119         unsigned        u;
    120         IRQ_SLOT        *pSlot;
    121 
    122         if( (pSlot = FindSlot(irq&0xff)) != NULL ) {
    123                 for( u = 0; u < MAX_SHAREDIRQS; u++ ) {
    124                         if( pSlot->irqHandlers[u].x2 == userdata ) {
    125                                 pSlot->flHandlers &= ~(1 << u);
    126                                 if( pSlot->flHandlers == 0 ) {
    127                                         rprintf(("free_irq: irq %d", irq & 0xff ));
    128                                         ALSA_FreeIrq(pSlot->irqNo);
    129                                         pSlot->irqNo = 0;
    130                                         RMDeallocateIRQ(pSlot->hRes);
    131                                         pSlot->hRes = 0;
    132                                         // pSlot->fEOI = 0;
    133                                 }
    134 
    135                                 pSlot->irqHandlers[u].handler = NULL;
    136                                 pSlot->irqHandlers[u].x0 = 0;
    137                                 pSlot->irqHandlers[u].x1 = NULL;
    138                                 pSlot->irqHandlers[u].x2 = NULL;
    139 
    140                                 return;
    141 
    142                         }
    143                 }
    144         }
     127  unsigned  u;
     128  IRQ_SLOT  *pSlot;
     129
     130  if( (pSlot = FindSlot(irq&0xff)) != NULL ) {
     131    for( u = 0; u < MAX_SHAREDIRQS; u++ ) {
     132      if( pSlot->irqHandlers[u].x2 == userdata ) {
     133        pSlot->flHandlers &= ~(1 << u);
     134        if( pSlot->flHandlers == 0 ) {
     135          rprintf(("free_irq: irq %d", irq & 0xff ));
     136          ALSA_FreeIrq(pSlot->irqNo);
     137          pSlot->irqNo = 0;
     138          RMDeallocateIRQ(pSlot->hRes);
     139          pSlot->hRes = 0;
     140          // pSlot->fEOI = 0;
     141        }
     142
     143        pSlot->irqHandlers[u].handler = NULL;
     144        pSlot->irqHandlers[u].x0 = 0;
     145        pSlot->irqHandlers[u].x1 = NULL;
     146        pSlot->irqHandlers[u].x2 = NULL;
     147
     148        return;
     149
     150      }
     151    }
     152  }
    145153}
    146154
     
    150158void eoi_irq(unsigned int irq)
    151159{
    152         /*(void)irq; */
    153         /*
    154          IRQ_SLOT       *pSlot = FindSlot(irq);
    155 
    156          if( pSlot )    pSlot->fEOI = 1;
    157         */
    158         eoiIrq[irq & 0xff]++;
     160  /*(void)irq; */
     161  /*
     162   IRQ_SLOT *pSlot = FindSlot(irq);
     163
     164   if( pSlot )  pSlot->fEOI = 1;
     165  */
     166  eoiIrq[irq & 0xff]++;
    159167}
    160168
     
    164172BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq)
    165173{
    166         unsigned        u;
    167         int rc;
    168         IRQ_SLOT        *pSlot;
    169 
    170         //dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
    171 
    172         if( ulSlotNo < MAX_IRQ_SLOTS )
    173         {
    174                 pSlot = &arSlots[ulSlotNo];
    175 
    176                 for( u = 0; u < MAX_SHAREDIRQS; u++ )
    177                 {
    178                         if(pSlot && pSlot->irqHandlers[u].handler )
    179                         {
    180                                 fInInterrupt = TRUE;
     174  unsigned  u;
     175  int rc;
     176  IRQ_SLOT  *pSlot;
     177
     178  //dprintf(("enter int proc %d %d",ulSlotNo, *pulIrq));
     179
     180  if( ulSlotNo < MAX_IRQ_SLOTS )
     181  {
     182    pSlot = &arSlots[ulSlotNo];
     183
     184    for( u = 0; u < MAX_SHAREDIRQS; u++ )
     185    {
     186      if(pSlot && pSlot->irqHandlers[u].handler )
     187      {
     188        fInInterrupt = TRUE;
    181189#if 0
    182                                 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
    183                                                                                                    pSlot->irqHandlers[u].x2, 0);
     190        rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
     191                           pSlot->irqHandlers[u].x2, 0);
    184192#else
    185                                 rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
    186                                                                                                    pSlot->irqHandlers[u].x2);
     193        rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
     194                           pSlot->irqHandlers[u].x2);
    187195#endif
    188196
    189                                 // HDA Hardware generates controller interrupts and stream interrupts
    190                                 // the uniaud16 driver only cares about stream interrupts.
    191                                 // azx_interrupt in alsa-kernel/pci/hda/hda_intel.c will return rc 2 if
    192                                 // the interrupt is from the  controller. There is no need to call uniaud16
    193                                 // for these interrupts
    194                                 if ( rc == 2 ) {
    195                                         fInInterrupt = FALSE;
    196                                         *pulIrq = pSlot->irqNo;
    197                                         eoiIrq[pSlot->irqNo] = 0;
    198                                         return TRUE;
    199                                 }
    200 
    201                                 if (rc == 1) eoi_irq(pSlot->irqNo);
    202                                 rc = (eoiIrq[pSlot->irqNo] > 0);
    203                                 fInInterrupt = FALSE;
    204 
    205                                 if( rc /*== 1 || pSlot->fEOI*/ ) {
    206 
    207                                         *pulIrq = pSlot->irqNo;
    208                                         //              pSlot->fEOI = 0;
    209 
    210                                         //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
    211                                         OSS32_ProcessIRQ();
    212                                         //dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
    213                                         eoiIrq[pSlot->irqNo] = 0;
    214                                         return TRUE;
    215                                 }
    216                         }
    217                 }
    218         }
    219         //dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
    220 
    221         return FALSE;
     197        // HDA Hardware generates controller interrupts and stream interrupts
     198        // the uniaud16 driver only cares about stream interrupts.
     199        // azx_interrupt in alsa-kernel/pci/hda/hda_intel.c will return rc 2 if
     200        // the interrupt is from the  controller. There is no need to call uniaud16
     201        // for these interrupts
     202        if ( rc == 2 ) {
     203          fInInterrupt = FALSE;
     204          *pulIrq = pSlot->irqNo;
     205          eoiIrq[pSlot->irqNo] = 0;
     206          return TRUE;
     207        }
     208
     209        if (rc == 1) eoi_irq(pSlot->irqNo);
     210        rc = (eoiIrq[pSlot->irqNo] > 0);
     211        fInInterrupt = FALSE;
     212
     213        if( rc /*== 1 || pSlot->fEOI*/ ) {
     214
     215          *pulIrq = pSlot->irqNo;
     216          //    pSlot->fEOI = 0;
     217
     218          //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
     219          OSS32_ProcessIRQ();
     220          //dprintf(("exit(1) int proc %d %d",ulSlotNo, *pulIrq));
     221          eoiIrq[pSlot->irqNo] = 0;
     222          return TRUE;
     223        }
     224      }
     225    }
     226  }
     227  //dprintf(("exit(0) int proc %d %d",ulSlotNo, *pulIrq));
     228
     229  return FALSE;
    222230}
    223231
     
    227235int in_interrupt()
    228236{
    229         return fInInterrupt;
     237  return fInInterrupt;
    230238}
    231239
     
    235243void disable_irq(int irq)
    236244{
    237         dprintf(("disable_irq %d NOT implemented", irq));
    238 }
    239 
    240 //******************************************************************************
    241 //******************************************************************************
    242 
     245  dprintf(("disable_irq %d NOT implemented", irq));
     246}
     247
     248//******************************************************************************
     249//******************************************************************************
     250
  • GPL/trunk/lib32/pci.c

    r602 r604  
    245245          pcidev->irq_resource[0].start = pcidev->irq_resource[0].end   = ulTmp1 & 0xffff;
    246246          pcidev->irq = (u8)ulTmp1; // This is the interrupt used for init time processing
     247          pcidev->irq_pin = ulTmp1>>8;
    247248        }
    248249
     
    10151016}
    10161017
     1018#ifdef USE_MSI
     1019extern int __syscall UniMsiAlloc(USHORT usBusDevFunc, ULONG *pulCount, UCHAR *pucIrq);
     1020int snd_pci_enable_msi(struct pci_dev *dev)
     1021{
     1022  ULONG p;
     1023  UCHAR irq;
     1024
     1025  if (dev->irq_pin)
     1026  {
     1027    p = 1; /* int count */
     1028    if (UniMsiAlloc((dev->bus->number<<8) | dev->devfn, &p, &irq)) return -1;
     1029    /* we have an msi interrupt */
     1030    dev->irq = irq;
     1031    dev->irq_pin = 0;
     1032  }
     1033  return 0;
     1034}
     1035#else
     1036int snd_pci_enable_msi(struct pci_dev *dev)
     1037{
     1038  return -1;
     1039}
     1040#endif
     1041
  • GPL/trunk/lib32/sound.c

    r598 r604  
    976976        _snd_pcm_hw_param_set(&params, SNDRV_PCM_HW_PARAM_RATE,
    977977                                                   pHwParams->ulSampleRate, 0);
     978                                               
     979  /* Change from Andy. If statement added around 5 statements.
     980   * Andy says: TODO:  determine why small buffers are a problem for this code
     981   * DAZ: This change is questionable.
     982   */
     983  if (periodsize > 6 * minperiodsize)
     984  {
    978985        _snd_pcm_hw_param_set(&params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
    979986                                                   periodsize, 0);
     
    986993        _snd_pcm_hw_param_set(&params, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
    987994                                                   periodbytes*nrperiods, 0);
    988 
     995  }
    989996
    990997        dprintf(("HWP: SR rate %ld, BPS %ld, CH %ld, PRSZ %lx, periods %lx",
  • GPL/trunk/lib32/soundmixer.c

    r598 r604  
    4141
    4242static struct {
    43         char *name;
    44         unsigned int index;
    45         unsigned int recsrc;
     43  char *name;
     44  unsigned int index;
     45  unsigned int recsrc;
    4646} ossid[OSS_MIXER_NRDEVICES] = {
    47         /* OSS_MIXER_VOLUME   */ { "Master", 0 , -1},
    48         /* OSS_MIXER_BASS         */ { "Tone Control - Bass", 0, -1},
    49         /* OSS_MIXER_TREBLE   */ { "Tone Control - Treble", 0, -1},
    50         /* OSS_MIXER_SYNTH        */ { "Synth", 0 , OSS32_MIX_RECSRC_SYNTH},
    51         /* OSS_MIXER_PCM          */ { "PCM", 0 , -1},
    52         /* OSS_MIXER_PCSPEAKER  */ { "PC Speaker", 0 , -1},
    53         /* OSS_MIXER_LINE         */ { "Line", 0 , OSS32_MIX_RECSRC_LINE},
    54         /* OSS_MIXER_MIC          */ { "Mic", 0, OSS32_MIX_RECSRC_MIC},
    55         /* OSS_MIXER_CD           */ { "CD", 0 , OSS32_MIX_RECSRC_CD},
    56         /* OSS_MIXER_IMIX         */ { "Monitor Mix", 0 , OSS32_MIX_RECSRC_MIXER},
    57         /* OSS_MIXER_ALTPCM   */ { "PCM",       1 , -1},
    58         /* OSS_MIXER_RECLEV   */ { "-- nothing --", 0 , -1},
    59         /* OSS_MIXER_IGAIN        */ { "Capture", 0 , -1},
    60         /* OSS_MIXER_OGAIN        */ { "Playback", 0 , -1},
    61         /* OSS_MIXER_LINE1        */ { "Aux", 0 , OSS32_MIX_RECSRC_AUX},
    62         /* OSS_MIXER_LINE2        */ { "Aux", 1 , -1},
    63         /* OSS_MIXER_LINE3        */ { "Aux", 2 , -1},
    64         /* OSS_MIXER_DIGITAL1 */ { "Digital", 0 , -1},
    65         /* OSS_MIXER_DIGITAL2 */ { "Digital", 1 , -1},
    66         /* OSS_MIXER_DIGITAL3 */ { "Digital", 2 , -1},
    67         /* OSS_MIXER_PHONEIN  */ { "Phone", 0 , OSS32_MIX_RECSRC_PHONE},
    68         /* OSS_MIXER_PHONEOUT */ { "Phone", 1 , -1},
    69         /* OSS_MIXER_VIDEO        */ { "Video", 0 , OSS32_MIX_RECSRC_VIDEO},
    70         /* OSS_MIXER_RADIO        */ { "Radio", 0 , -1},
    71         /* OSS_MIXER_MONITOR  */ { "Monitor", 0 , -1},
    72         /* OSS_MIXER_3DDEPTH  */ { "3D Control - Depth", 0 , -1},
    73         /* OSS_MIXER_3DCENTER */ { "3D Control - Center", 0 , -1},
    74         /* OSS_MIXER_FRONT        */ { "Front", 0 , -1},
    75         /* OSS_MIXER_SPEAKER  */ { "Speaker", 0 , -1},
    76         /* OSS_MIXER_HEADPHONE */ { "Headphone", 0 , -1},
     47  /* OSS_MIXER_VOLUME   */ { "Master", 0 , -1},
     48  /* OSS_MIXER_BASS   */ { "Tone Control - Bass", 0, -1},
     49  /* OSS_MIXER_TREBLE   */ { "Tone Control - Treble", 0, -1},
     50  /* OSS_MIXER_SYNTH    */ { "Synth", 0 , OSS32_MIX_RECSRC_SYNTH},
     51  /* OSS_MIXER_PCM    */ { "PCM", 0 , -1},
     52  /* OSS_MIXER_PCSPEAKER  */ { "PC Speaker", 0 , -1},
     53  /* OSS_MIXER_LINE   */ { "Line", 0 , OSS32_MIX_RECSRC_LINE},
     54  /* OSS_MIXER_MIC    */ { "Mic", 0, OSS32_MIX_RECSRC_MIC},
     55  /* OSS_MIXER_CD     */ { "CD", 0 , OSS32_MIX_RECSRC_CD},
     56  /* OSS_MIXER_IMIX   */ { "Monitor Mix", 0 , OSS32_MIX_RECSRC_MIXER},
     57  /* OSS_MIXER_ALTPCM   */ { "PCM", 1 , -1},
     58  /* OSS_MIXER_RECLEV   */ { "-- nothing --", 0 , -1},
     59  /* OSS_MIXER_IGAIN    */ { "Capture", 0 , -1},
     60  /* OSS_MIXER_OGAIN    */ { "Playback", 0 , -1},
     61  /* OSS_MIXER_LINE1    */ { "Aux", 0 , OSS32_MIX_RECSRC_AUX},
     62  /* OSS_MIXER_LINE2    */ { "Aux", 1 , -1},
     63  /* OSS_MIXER_LINE3    */ { "Aux", 2 , -1},
     64  /* OSS_MIXER_DIGITAL1 */ { "Digital", 0 , -1},
     65  /* OSS_MIXER_DIGITAL2 */ { "Digital", 1 , -1},
     66  /* OSS_MIXER_DIGITAL3 */ { "Digital", 2 , -1},
     67  /* OSS_MIXER_PHONEIN  */ { "Phone", 0 , OSS32_MIX_RECSRC_PHONE},
     68  /* OSS_MIXER_PHONEOUT */ { "Phone", 1 , -1},
     69  /* OSS_MIXER_VIDEO    */ { "Video", 0 , OSS32_MIX_RECSRC_VIDEO},
     70  /* OSS_MIXER_RADIO    */ { "Radio", 0 , -1},
     71  /* OSS_MIXER_MONITOR  */ { "Monitor", 0 , -1},
     72  /* OSS_MIXER_3DDEPTH  */ { "3D Control - Depth", 0 , -1},
     73  /* OSS_MIXER_3DCENTER */ { "3D Control - Center", 0 , -1},
     74  /* OSS_MIXER_FRONT    */ { "Front", 0 , -1},
     75  /* OSS_MIXER_SPEAKER  */ { "Speaker", 0 , -1},
     76  /* OSS_MIXER_HEADPHONE */ { "Headphone", 0 , -1},
    7777};
    7878char *szRecSources[OSS32_MIX_RECSRC_MAX] = {
    79         "Mic", "CD", "Line", "Video", "Aux", "Mix", "Mix Mono", "Phone", "Synth"
     79  "Mic", "CD", "Line", "Video", "Aux", "Mix", "Mix Mono", "Phone", "Synth"
    8080};
    8181
    8282static unsigned char LinToLog[OSS32_MAX_VOLUME+1] = {
    83   0,   0,       0,       0,   1,   2,   2,      5,   5,  10,
    84  10,  10,  16,  19,  20,  22,  24,      25,  27,  27,
    85  28,  28,  29,  30,  30,  35,  35,      35,  39,  39,
    86  43,  44,  45,  47,  48,  49,  50,      51,  52,  53,
    87  55,  56,  57,  59,  60,  62,  63,      64,  65,  66,
    88  67,  68,  69,  70,  71,  72,  73,      74,  74,  75,
    89  76,  77,  78,  79,  79,  80,  81,      82,  83,  84,
    90  85,  86,  87,  88,  89,  90,  91,      92,  92,  93,
    91  93,  94,  94,  95,  95,  96,  96,      97,  97,  98,
    92  98,  99,  99,  99,  99, 100, 100, 100, 100, 100,
     83  0,   0, 0,   0,   1,   2, 2,  5,   5,  10,
     84 10,  10,  16,  19,  20,  22,  24,  25,  27,  27,
     85 28,  28,  29,  30,  30,  35,  35,  35,  39,  39,
     86 43,  44,  45,  47,  48,  49,  50,  51,  52,  53,
     87 55,  56,  57,  59,  60,  62,  63,  64,  65,  66,
     88 67,  68,  69,  70,  71,  72,  73,  74,  74,  75,
     89 76,  77,  78,  79,  79,  80,  81,  82,  83,  84,
     90 85,  86,  87,  88,  89,  90,  91,  92,  92,  93,
     91 93,  94,  94,  95,  95,  96,  96,  97,  97,  98,
     92 98,  99,  99,  99,  99, 100, 100, 100, 100, 100,
    9393 100
    9494};
     
    9999ULONG ConvertVolume(ULONG ulLinVolume, ULONG ulLogVolMax)
    100100{
    101         if(ulLinVolume > OSS32_MAX_VOLUME) {
    102                 ulLinVolume = OSS32_MAX_VOLUME;
    103         }
    104         ulLinVolume = LinToLog[ulLinVolume];
    105 
    106         return (ulLinVolume * ulLogVolMax) / OSS32_MAX_VOLUME;
     101  if(ulLinVolume > OSS32_MAX_VOLUME) {
     102    ulLinVolume = OSS32_MAX_VOLUME;
     103  }
     104  ulLinVolume = LinToLog[ulLinVolume];
     105
     106  return (ulLinVolume * ulLogVolMax) / OSS32_MAX_VOLUME;
    107107}
    108108
     
    111111OSSRET OSS32_MixOpen(ULONG deviceid, OSSSTREAMID *pStreamId)
    112112{
    113         mixerhandle *pHandle = NULL;
    114         int              ret, i, j, sz;
    115 
    116         if(pStreamId == NULL) {
    117                 DebugInt3();
    118                 return OSSERR_INVALID_PARAMETER;
    119         }
    120         *pStreamId = 0;
    121 
    122         if(alsa_fops == NULL) {
    123                 ret = OSSERR_NO_DEVICE_AVAILABLE;
    124                 goto failure;
    125         }
    126 
    127         sz = sizeof(mixerhandle);
    128         pHandle = kmalloc(sz, GFP_KERNEL);
    129         if(pHandle == NULL) {
    130                 ret = OSSERR_OUT_OF_MEMORY;
    131                 goto failure;
    132         }
    133         memset(pHandle, 0, sizeof(mixerhandle));
    134 
    135         //set operation to non-blocking
    136         pHandle->file.f_flags = O_NONBLOCK;
    137 
    138         //setup pointers in file structure (used internally by ALSA)
    139         pHandle->file.f_dentry                  = &pHandle->d_entry;
    140         pHandle->file.f_dentry->d_inode = &pHandle->inode;
    141 
    142         pHandle->file.f_mode  = FMODE_WRITE;
    143         pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
    144 
    145         ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
    146         if(ret) {
    147                 goto failure;
    148         }
    149         //retrieve mixer information
    150         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
    151                                                                         SNDRV_CTL_IOCTL_CARD_INFO,
    152                                                                         (ULONG)&pHandle->info);
    153         if(ret) {
    154                 goto failure;
    155         }
    156         //get the number of mixer elements
    157         pHandle->list.offset = 0;
    158         pHandle->list.space  = 0;
    159         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
    160                                                                         SNDRV_CTL_IOCTL_ELEM_LIST,
    161                                                                         (ULONG)&pHandle->list);
    162         if(ret) {
    163                 goto failure;
    164         }
    165         //allocate memory for all mixer elements
    166         pHandle->pids = (struct snd_ctl_elem_id *)kmalloc(sizeof(struct snd_ctl_elem_id)*pHandle->list.count, GFP_KERNEL);
    167         if(pHandle->pids == NULL) {
    168                 goto failure;
    169         }
    170         //and retrieve all mixer elements
    171         pHandle->list.offset = 0;
    172         pHandle->list.space  = pHandle->list.count;
    173         pHandle->list.pids      = pHandle->pids;
    174         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
    175                                                                         SNDRV_CTL_IOCTL_ELEM_LIST,
    176                                                                         (ULONG)&pHandle->list);
    177         if(ret) {
    178                 goto failure;
    179         }
     113  mixerhandle *pHandle = NULL;
     114  int      ret, i, j, sz;
     115
     116  if(pStreamId == NULL) {
     117    DebugInt3();
     118    return OSSERR_INVALID_PARAMETER;
     119  }
     120  *pStreamId = 0;
     121
     122  if(alsa_fops == NULL) {
     123    ret = OSSERR_NO_DEVICE_AVAILABLE;
     124    goto failure;
     125  }
     126
     127  sz = sizeof(mixerhandle);
     128  pHandle = kmalloc(sz, GFP_KERNEL);
     129  if(pHandle == NULL) {
     130    ret = OSSERR_OUT_OF_MEMORY;
     131    goto failure;
     132  }
     133  memset(pHandle, 0, sizeof(mixerhandle));
     134
     135  //set operation to non-blocking
     136  pHandle->file.f_flags = O_NONBLOCK;
     137
     138  //setup pointers in file structure (used internally by ALSA)
     139  pHandle->file.f_dentry      = &pHandle->d_entry;
     140  pHandle->file.f_dentry->d_inode = &pHandle->inode;
     141
     142  pHandle->file.f_mode  = FMODE_WRITE;
     143  pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
     144
     145  ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
     146  if(ret) {
     147    goto failure;
     148  }
     149  //retrieve mixer information
     150  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
     151                  SNDRV_CTL_IOCTL_CARD_INFO,
     152                  (ULONG)&pHandle->info);
     153  if(ret) {
     154    goto failure;
     155  }
     156  //get the number of mixer elements
     157  pHandle->list.offset = 0;
     158  pHandle->list.space  = 0;
     159  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
     160                  SNDRV_CTL_IOCTL_ELEM_LIST,
     161                  (ULONG)&pHandle->list);
     162  if(ret) {
     163    goto failure;
     164  }
     165  //allocate memory for all mixer elements
     166  pHandle->pids = (struct snd_ctl_elem_id *)kmalloc(sizeof(struct snd_ctl_elem_id)*pHandle->list.count, GFP_KERNEL);
     167  if(pHandle->pids == NULL) {
     168    goto failure;
     169  }
     170  //and retrieve all mixer elements
     171  pHandle->list.offset = 0;
     172  pHandle->list.space  = pHandle->list.count;
     173  pHandle->list.pids  = pHandle->pids;
     174  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
     175                  SNDRV_CTL_IOCTL_ELEM_LIST,
     176                  (ULONG)&pHandle->list);
     177  if(ret) {
     178    goto failure;
     179  }
    180180
    181181#if 0
    182         dprintf(("Mixer name: %s", pHandle->info.mixername));
    183         dprintf(("List of mixer elements:"));
    184         for(i=0;i<pHandle->list.count;i++) {
    185                 dprintf(("index %d name %s id %d device %d subdevice %d", pHandle->pids[i].index, pHandle->pids[i].name, pHandle->pids[i].numid, pHandle->pids[i].device, pHandle->pids[i].subdevice));
    186         }
     182  dprintf(("Mixer name: %s", pHandle->info.mixername));
     183  dprintf(("List of mixer elements:"));
     184  for(i=0;i<pHandle->list.count;i++) {
     185    dprintf(("index %d name %s id %d device %d subdevice %d", pHandle->pids[i].index, pHandle->pids[i].name, pHandle->pids[i].numid, pHandle->pids[i].device, pHandle->pids[i].subdevice));
     186  }
    187187#endif
    188188
    189         //Extract standard mixer controls from array with control names
    190         for(j=0;j<OSS_MIXER_NRDEVICES;j++)
    191         {
    192                 int namelen = strlen(ossid[j].name);
    193 
    194                 pHandle->controls[j].idxVolume            = -1;
    195                 pHandle->controls[j].idxMute              = -1;
    196                 pHandle->controls[j].idxCustom            = -1;
    197                 pHandle->controls[j].idxCaptureSwitch = -1;
    198 
    199                 for(i=0;i<pHandle->list.count;i++) {
    200                         if (pHandle->pids[i].index == ossid[j].index && strncmp(pHandle->pids[i].name, ossid[j].name, namelen) == 0) {
    201                                 int controlnamelen = strlen(pHandle->pids[i].name);
    202 
    203                                 if(namelen == controlnamelen) { //control names are identical; found exact match
    204                                         pHandle->controls[j].idxVolume = i;
    205                                         break;
    206                                 } else { //first part of the control name is correct; now find out what is it exactly
    207                                         char *nextword = &pHandle->pids[i].name[namelen];
    208                                         while(*nextword && *nextword == ' ') nextword++;
    209 
    210                                         if(strncmp(nextword, MIXER_PLAYBACKVOLUME, sizeof(MIXER_PLAYBACKVOLUME)-1) == 0 ||
    211                                            strncmp(nextword, MIXER_VOLUME, sizeof(MIXER_VOLUME)-1) == 0)
    212                                         { //volume control
    213                                                 pHandle->controls[j].idxVolume = i;
    214                                         }
    215                                         else
    216                                         if(strncmp(nextword, MIXER_PLAYBACKSWITCH, sizeof(MIXER_PLAYBACKSWITCH)-1) == 0 ||
    217                                            strncmp(nextword, MIXER_SWITCH, sizeof(MIXER_SWITCH)-1) == 0)
    218                                         { //mute control
    219                                                 pHandle->controls[j].idxMute = i;
    220                                                 if (pHandle->controls[j].idxVolume == -1) pHandle->controls[j].idxVolume = i;
    221                                         }
    222                                         else
    223                                         if(strncmp(nextword, MIXER_SOURCE, sizeof(MIXER_SOURCE)-1) == 0)
    224                                         { //source control (e.g. recording source)
    225                                                 pHandle->controls[j].idxCustom = i;
    226                                         }
    227                                         else
    228                                         if(strncmp(nextword, MIXER_CAPTUREROUTE, sizeof(MIXER_CAPTUREROUTE)-1) == 0 ||
    229                                            strncmp(nextword, MIXER_CAPTURESWITCH, sizeof(MIXER_CAPTURESWITCH)-1) == 0)
    230                                         { //source control for recording (per input)
    231                                                 pHandle->controls[j].idxCaptureSwitch = i;
    232                                         }
    233                                         else
    234                                         if(i == OSS_MIXER_MIC) {
    235                                                 if(strncmp(nextword, MIXER_BOOST, sizeof(MIXER_BOOST)-1) == 0) { //mic boost switch
    236                                                         pHandle->controls[j].idxCustom = i;
    237                                                 }
    238                                         }
    239                                 }
    240                         }
    241                 }
    242         }
    243 
    244         pHandle->reccaps = 0;
    245         for (j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
    246                 pHandle->idxRecCaps[j] = -1;
    247         }
    248 
    249         //request information about available capture sources
    250         if (pHandle->controls[OSS_MIXER_IGAIN].idxCustom != -1) {
    251                 struct snd_ctl_elem_info  *pElemInfo = NULL;
    252                 int idx, j;
    253 
    254                 idx = pHandle->controls[OSS_MIXER_IGAIN].idxCustom;
    255 
    256                 //set operation to non-blocking
    257                 pHandle->file.f_flags = O_NONBLOCK;
    258 
    259                 pHandle->rectype = RECTYPE_SELECTOR;
    260 
    261                 //too big to put on the stack
    262                 pElemInfo = (struct snd_ctl_elem_info *)kmalloc(sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
    263                 if(pElemInfo == NULL) {
    264                         DebugInt3();
    265                         goto failure;
    266                 }
    267 
    268                 pElemInfo->value.enumerated.items = 1;
    269                 for(i=0;i<pElemInfo->value.enumerated.items;i++)
    270                 {
    271                         pElemInfo->value.enumerated.item = i;
    272                         pElemInfo->id.numid = pHandle->pids[idx].numid;
    273                         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
    274                         if(ret) {
    275                                 DebugInt3();
    276                                 break;
    277                         }
    278                         if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
    279                                 DebugInt3();
    280                                 break;
    281                         }
    282                         for(j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
    283                                 if(!strcmp(pElemInfo->value.enumerated.name, szRecSources[j])) {
    284                                         pHandle->reccaps          |= OSS32_MIX_FLAG(j);
    285                                         pHandle->idxRecCaps[j] = i; //save alsa index
    286                                         break;
    287                                 }
    288                         }
    289                 }
    290                 kfree(pElemInfo);
    291         }
    292         else
    293         {//This card has no record source selection, but probably route switches for
    294         //each input source (SB mixers (also ALS4000), CMedia)
    295                 pHandle->rectype = RECTYPE_SWITCH;
    296                 for(j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
    297                         pHandle->idxRecCaps[j] = -1;
    298                 }
    299                 for(j=0;j<OSS_MIXER_NRDEVICES;j++)
    300                 {
    301                         if(pHandle->controls[j].idxCaptureSwitch != -1) {
    302                                 pHandle->reccaps                                        |= OSS32_MIX_FLAG(ossid[j].recsrc);
    303                                 pHandle->idxRecCaps[ossid[j].recsrc] = pHandle->controls[j].idxCaptureSwitch; //save alsa index
    304                         }
    305                 }
    306         }
    307 
    308         pHandle->magic = MAGIC_MIXER_ALSA32;
    309         *pStreamId = (ULONG)pHandle;
    310         return OSSERR_SUCCESS;
     189  //Extract standard mixer controls from array with control names
     190  for(j=0;j<OSS_MIXER_NRDEVICES;j++)
     191  {
     192    int namelen = strlen(ossid[j].name);
     193
     194    pHandle->controls[j].idxVolume      = -1;
     195    pHandle->controls[j].idxMute      = -1;
     196    pHandle->controls[j].idxCustom      = -1;
     197    pHandle->controls[j].idxCaptureSwitch = -1;
     198
     199    for(i=0;i<pHandle->list.count;i++) {
     200      if (pHandle->pids[i].index == ossid[j].index && strncmp(pHandle->pids[i].name, ossid[j].name, namelen) == 0) {
     201        int controlnamelen = strlen(pHandle->pids[i].name);
     202
     203        if(namelen == controlnamelen) { //control names are identical; found exact match
     204          pHandle->controls[j].idxVolume = i;
     205          break;
     206        } else { //first part of the control name is correct; now find out what is it exactly
     207          char *nextword = &pHandle->pids[i].name[namelen];
     208          while(*nextword && *nextword == ' ') nextword++;
     209
     210          if(strncmp(nextword, MIXER_PLAYBACKVOLUME, sizeof(MIXER_PLAYBACKVOLUME)-1) == 0 ||
     211             strncmp(nextword, MIXER_VOLUME, sizeof(MIXER_VOLUME)-1) == 0)
     212          { //volume control
     213            pHandle->controls[j].idxVolume = i;
     214          }
     215          else
     216          if(strncmp(nextword, MIXER_PLAYBACKSWITCH, sizeof(MIXER_PLAYBACKSWITCH)-1) == 0 ||
     217             strncmp(nextword, MIXER_SWITCH, sizeof(MIXER_SWITCH)-1) == 0)
     218          { //mute control
     219            pHandle->controls[j].idxMute = i;
     220            if (pHandle->controls[j].idxVolume == -1) pHandle->controls[j].idxVolume = i;
     221          }
     222          else
     223          if(strncmp(nextword, MIXER_SOURCE, sizeof(MIXER_SOURCE)-1) == 0)
     224          { //source control (e.g. recording source)
     225            pHandle->controls[j].idxCustom = i;
     226          }
     227          else
     228          if(strncmp(nextword, MIXER_CAPTUREROUTE, sizeof(MIXER_CAPTUREROUTE)-1) == 0 ||
     229             strncmp(nextword, MIXER_CAPTURESWITCH, sizeof(MIXER_CAPTURESWITCH)-1) == 0)
     230          { //source control for recording (per input)
     231            pHandle->controls[j].idxCaptureSwitch = i;
     232          }
     233          else
     234          if(i == OSS_MIXER_MIC) {
     235            if(strncmp(nextword, MIXER_BOOST, sizeof(MIXER_BOOST)-1) == 0) { //mic boost switch
     236              pHandle->controls[j].idxCustom = i;
     237            }
     238          }
     239        }
     240      }
     241    }
     242  }
     243
     244  pHandle->reccaps = 0;
     245  for (j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
     246    pHandle->idxRecCaps[j] = -1;
     247  }
     248
     249  //request information about available capture sources
     250  if (pHandle->controls[OSS_MIXER_IGAIN].idxCustom != -1) {
     251    struct snd_ctl_elem_info  *pElemInfo = NULL;
     252    int idx, j;
     253
     254    idx = pHandle->controls[OSS_MIXER_IGAIN].idxCustom;
     255
     256    //set operation to non-blocking
     257    pHandle->file.f_flags = O_NONBLOCK;
     258
     259    pHandle->rectype = RECTYPE_SELECTOR;
     260
     261    //too big to put on the stack
     262    pElemInfo = (struct snd_ctl_elem_info *)kmalloc(sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
     263    if(pElemInfo == NULL) {
     264      DebugInt3();
     265      goto failure;
     266    }
     267
     268    pElemInfo->value.enumerated.items = 1;
     269    for(i=0;i<pElemInfo->value.enumerated.items;i++)
     270    {
     271      pElemInfo->value.enumerated.item = i;
     272      pElemInfo->id.numid = pHandle->pids[idx].numid;
     273      ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
     274      if(ret) {
     275        DebugInt3();
     276        break;
     277      }
     278      if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
     279        DebugInt3();
     280        break;
     281      }
     282      for(j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
     283        if(!strcmp(pElemInfo->value.enumerated.name, szRecSources[j])) {
     284          pHandle->reccaps    |= OSS32_MIX_FLAG(j);
     285          pHandle->idxRecCaps[j] = i; //save alsa index
     286          break;
     287        }
     288      }
     289    }
     290    kfree(pElemInfo);
     291  }
     292  else
     293  {//This card has no record source selection, but probably route switches for
     294  //each input source (SB mixers (also ALS4000), CMedia)
     295    pHandle->rectype = RECTYPE_SWITCH;
     296    for(j=0;j<OSS32_MIX_RECSRC_MAX;j++) {
     297      pHandle->idxRecCaps[j] = -1;
     298    }
     299    for(j=0;j<OSS_MIXER_NRDEVICES;j++)
     300    {
     301      if(pHandle->controls[j].idxCaptureSwitch != -1) {
     302        pHandle->reccaps          |= OSS32_MIX_FLAG(ossid[j].recsrc);
     303        pHandle->idxRecCaps[ossid[j].recsrc] = pHandle->controls[j].idxCaptureSwitch; //save alsa index
     304      }
     305    }
     306  }
     307
     308  pHandle->magic = MAGIC_MIXER_ALSA32;
     309  *pStreamId = (ULONG)pHandle;
     310  return OSSERR_SUCCESS;
    311311
    312312failure:
    313         if(pHandle) {
    314                 if(pHandle->pids) kfree(pHandle->pids);
    315                 kfree(pHandle);
    316         }
    317         DebugInt3();
    318         return OSSERR_OUT_OF_MEMORY;
     313  if(pHandle) {
     314    if(pHandle->pids) kfree(pHandle->pids);
     315    kfree(pHandle);
     316  }
     317  DebugInt3();
     318  return OSSERR_OUT_OF_MEMORY;
    319319}
    320320//******************************************************************************
     
    322322OSSRET OSS32_MixClose(OSSSTREAMID streamid)
    323323{
    324         mixerhandle *pHandle = (mixerhandle *)streamid;
    325         int              ret;
    326 
    327         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    328                 DebugInt3();
    329                 return OSSERR_INVALID_STREAMID;
    330         }
    331         //set operation to non-blocking
    332         pHandle->file.f_flags = O_NONBLOCK;
    333         ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
    334         kfree(pHandle->pids);  //free mixer element array
    335         kfree(pHandle);            //free handle data
    336 
    337         if(ret) {
    338                 DebugInt3();
    339                 return UNIXToOSSError(ret);
    340         }
    341         return OSSERR_SUCCESS;
     324  mixerhandle *pHandle = (mixerhandle *)streamid;
     325  int      ret;
     326
     327  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     328    DebugInt3();
     329    return OSSERR_INVALID_STREAMID;
     330  }
     331  //set operation to non-blocking
     332  pHandle->file.f_flags = O_NONBLOCK;
     333  ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
     334  kfree(pHandle->pids);  //free mixer element array
     335  kfree(pHandle);      //free handle data
     336
     337  if(ret) {
     338    DebugInt3();
     339    return UNIXToOSSError(ret);
     340  }
     341  return OSSERR_SUCCESS;
    342342}
    343343//******************************************************************************
     
    345345OSSRET OSS32_MixGetVolume(OSSSTREAMID streamid, ULONG line, ULONG *pVolume)
    346346{
    347         mixerhandle *pHandle = (mixerhandle *)streamid;
    348         //int            ret;
    349 
    350         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    351                 DebugInt3();
    352                 return OSSERR_INVALID_STREAMID;
    353         }
    354         //set operation to non-blocking
    355         pHandle->file.f_flags = O_NONBLOCK;
    356 
    357         return OSSERR_NOT_SUPPORTED;
     347  mixerhandle *pHandle = (mixerhandle *)streamid;
     348  //int      ret;
     349
     350  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     351    DebugInt3();
     352    return OSSERR_INVALID_STREAMID;
     353  }
     354  //set operation to non-blocking
     355  pHandle->file.f_flags = O_NONBLOCK;
     356
     357  return OSSERR_NOT_SUPPORTED;
    358358}
    359359//******************************************************************************
     
    361361OSSRET OSS32_MixSetVolume(OSSSTREAMID streamid, ULONG line, ULONG volume)
    362362{
    363         mixerhandle              *pHandle = (mixerhandle *)streamid;
    364         struct snd_ctl_elem_value *pElem = NULL;
    365         struct snd_ctl_elem_info  *pElemInfo;
    366         int                               ret, idx, lVol, rVol = 0, idxMute;
    367         //int cnt;
    368 
    369         //dprintf(("OSS32_MixSetVolume line=%d\n", line));
    370         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    371                 printk("Invalid handle in OSS32_MixSetVolume\n");
    372                 DebugInt3();
    373                 return OSSERR_INVALID_STREAMID;
    374         }
    375         //set operation to non-blocking
    376         pHandle->file.f_flags = O_NONBLOCK;
    377 
    378         //too big to put on the stack
    379         pElem = (struct snd_ctl_elem_value *)kmalloc(sizeof(struct snd_ctl_elem_value) + sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
    380         if(pElem == NULL) {
    381                 printk("Out of memory in OSS32_MixSetVolume\n");
    382                 DebugInt3();
    383                 return OSSERR_OUT_OF_MEMORY;
    384         }
    385         pElemInfo = (struct snd_ctl_elem_info *)(pElem+1);
    386 
    387         switch(line) {
    388         case OSS32_MIX_VOLUME_MASTER_FRONT:
    389                 idx = pHandle->controls[OSS_MIXER_VOLUME].idxVolume;
    390                 idxMute = pHandle->controls[OSS_MIXER_VOLUME].idxMute;
    391                 if (idx == -1)
    392                 {
    393                         /* HDA codecs workaround */
    394                         idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
    395                         idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
    396                 }
    397                 break;
    398         case OSS32_MIX_VOLUME_MASTER_REAR: //TODO:
    399                 idx = pHandle->controls[OSS_MIXER_VOLUME].idxVolume;
    400                 idxMute = pHandle->controls[OSS_MIXER_VOLUME].idxMute;
    401                 break;
    402         case OSS32_MIX_VOLUME_PCM:
    403                 idx = pHandle->controls[OSS_MIXER_PCM].idxVolume;
    404                 idxMute = pHandle->controls[OSS_MIXER_PCM].idxMute;
    405                 if (idx == -1)
    406                 {
    407                         /* HDA codecs workaround */
    408                         idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
    409                         idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
    410                 }
    411                 break;
    412         case OSS32_MIX_VOLUME_MIDI:
    413                 idx = pHandle->controls[OSS_MIXER_SYNTH].idxVolume;
    414                 idxMute = pHandle->controls[OSS_MIXER_SYNTH].idxMute;
    415                 break;
    416         case OSS32_MIX_VOLUME_LINEIN:
    417                 idx = pHandle->controls[OSS_MIXER_LINE].idxVolume;
    418                 idxMute = pHandle->controls[OSS_MIXER_LINE].idxMute;
    419                 break;
    420         case OSS32_MIX_VOLUME_MIC:
    421                 idx = pHandle->controls[OSS_MIXER_MIC].idxVolume;
    422                 idxMute = pHandle->controls[OSS_MIXER_MIC].idxMute;
    423                 break;
    424         case OSS32_MIX_VOLUME_CD:
    425                 idx = pHandle->controls[OSS_MIXER_CD].idxVolume;
    426                 idxMute = pHandle->controls[OSS_MIXER_CD].idxMute;
    427                 break;
    428         case OSS32_MIX_VOLUME_SPDIF:
    429                 idx = pHandle->controls[OSS_MIXER_DIGITAL1].idxVolume;
    430                 idxMute = pHandle->controls[OSS_MIXER_DIGITAL1].idxMute;
    431                 break;
    432         case OSS32_MIX_VOLUME_VIDEO:
    433                 idx = pHandle->controls[OSS_MIXER_VIDEO].idxVolume;
    434                 idxMute = pHandle->controls[OSS_MIXER_VIDEO].idxMute;
    435                 break;
    436         case OSS32_MIX_VOLUME_PCSPEAKER:
    437                 idx = pHandle->controls[OSS_MIXER_PCSPEAKER].idxVolume;
    438                 idxMute = pHandle->controls[OSS_MIXER_PCSPEAKER].idxMute;
    439                 break;
    440         case OSS32_MIX_VOLUME_PHONE:
    441                 idx = pHandle->controls[OSS_MIXER_PHONEOUT].idxVolume;
    442                 idxMute = pHandle->controls[OSS_MIXER_PHONEOUT].idxMute;
    443                 break;
    444         case OSS32_MIX_VOLUME_HEADPHONE:
    445                 idx = pHandle->controls[OSS_MIXER_HEADPHONE].idxVolume;
    446                 idxMute = pHandle->controls[OSS_MIXER_HEADPHONE].idxMute;
    447                 break;
    448         case OSS32_MIX_VOLUME_SPEAKER:
    449                 idx = pHandle->controls[OSS_MIXER_SPEAKER].idxVolume;
    450                 idxMute = pHandle->controls[OSS_MIXER_SPEAKER].idxMute;
    451                 break;
    452         case OSS32_MIX_VOLUME_AUX:
    453                 idx = pHandle->controls[OSS_MIXER_LINE1].idxVolume;
    454                 idxMute = pHandle->controls[OSS_MIXER_LINE1].idxMute;
    455                 break;
    456         case OSS32_MIX_VOLUME_CAPTURE:
    457                 idx = pHandle->controls[OSS_MIXER_IGAIN].idxVolume;
    458                 idxMute = pHandle->controls[OSS_MIXER_IGAIN].idxMute;
    459                 break;
    460 
    461         default:
    462                 DebugInt3();
    463                 ret = OSSERR_INVALID_PARAMETER;
    464                 goto fail;
    465         }
    466         if(idx == -1) {
    467                 rprintf(("Unknown control %d", line));
    468                 ret = OSSERR_INVALID_PARAMETER;
    469                 goto fail;
    470         }
    471 
    472         if(idxMute != -1 && volume != 0) {
    473                 //disable mute
    474                 pElem->id.numid = pHandle->pids[idxMute].numid;
    475                 pElem->indirect = 0;
    476 
    477                 pElem->value.integer.value[0] = TRUE;  //switch, not mute control (inversed)
    478                 pElem->value.integer.value[1] = TRUE;
    479                 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    480         }
    481         //request information about mixer control
    482         pElemInfo->id.numid = pHandle->pids[idx].numid;
    483         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
    484         if(ret) {
    485                 ret = UNIXToOSSError(ret);
    486                 DebugInt3();
    487                 goto fail;
    488         }
    489         if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
    490                 ret = OSSERR_INVALID_PARAMETER;
    491                 DebugInt3();
    492                 goto fail;
    493         }
    494         pElem->id.numid = pHandle->pids[idx].numid;
    495         pElem->indirect = 0;
    496 
    497         lVol = ConvertVolume(GET_VOLUME_L(volume), pElemInfo->value.integer.max);
    498         pElem->value.integer.value[0] = lVol;
    499 
    500         if(pElemInfo->count > 1) { //stereo
    501                 rVol = ConvertVolume(GET_VOLUME_R(volume), pElemInfo->value.integer.max);
    502                 pElem->value.integer.value[1] = rVol;
    503         }
    504 
    505         dprintf(("OSS32_MixSetVolume of %s streamid %X to (%d,%d)(%d,%d) caps %d",
    506                 pHandle->pids[idx].name, (ULONG)pHandle,
    507                 GET_VOLUME_L(volume), GET_VOLUME_R(volume), lVol, rVol, pElemInfo->value.integer.max));
     363  mixerhandle      *pHandle = (mixerhandle *)streamid;
     364  struct snd_ctl_elem_value *pElem = NULL;
     365  struct snd_ctl_elem_info  *pElemInfo;
     366  int           ret, idx, lVol, rVol = 0, idxMute;
     367  //int cnt;
     368
     369  //dprintf(("OSS32_MixSetVolume line=%d\n", line));
     370  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     371    printk("Invalid handle in OSS32_MixSetVolume\n");
     372    DebugInt3();
     373    return OSSERR_INVALID_STREAMID;
     374  }
     375  //set operation to non-blocking
     376  pHandle->file.f_flags = O_NONBLOCK;
     377
     378  //too big to put on the stack
     379  pElem = (struct snd_ctl_elem_value *)kmalloc(sizeof(struct snd_ctl_elem_value) + sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
     380  if(pElem == NULL) {
     381    printk("Out of memory in OSS32_MixSetVolume\n");
     382    DebugInt3();
     383    return OSSERR_OUT_OF_MEMORY;
     384  }
     385  pElemInfo = (struct snd_ctl_elem_info *)(pElem+1);
     386
     387  switch(line) {
     388  case OSS32_MIX_VOLUME_MASTER_FRONT:
     389    idx = pHandle->controls[OSS_MIXER_VOLUME].idxVolume;
     390    idxMute = pHandle->controls[OSS_MIXER_VOLUME].idxMute;
     391    if (idx == -1)
     392    {
     393      /* HDA codecs workaround */
     394      idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
     395      idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
     396    }
     397    break;
     398  case OSS32_MIX_VOLUME_MASTER_REAR: //TODO:
     399    idx = pHandle->controls[OSS_MIXER_VOLUME].idxVolume;
     400    idxMute = pHandle->controls[OSS_MIXER_VOLUME].idxMute;
     401    break;
     402  case OSS32_MIX_VOLUME_PCM:
     403    idx = pHandle->controls[OSS_MIXER_PCM].idxVolume;
     404    idxMute = pHandle->controls[OSS_MIXER_PCM].idxMute;
     405    if (idx == -1)
     406    {
     407      /* HDA codecs workaround */
     408      idx = pHandle->controls[OSS_MIXER_FRONT].idxVolume;
     409      idxMute = pHandle->controls[OSS_MIXER_FRONT].idxMute;
     410    }
     411    /* HDA codecs workaround from Andy */
     412    if (idx == -1)
     413    {
     414      idx = pHandle->controls[OSS_MIXER_SPEAKER].idxVolume;
     415      idxMute = pHandle->controls[OSS_MIXER_SPEAKER].idxMute;
     416    }
     417    /* HDA codecs workaround from Andy */
     418    break;
     419  case OSS32_MIX_VOLUME_MIDI:
     420    idx = pHandle->controls[OSS_MIXER_SYNTH].idxVolume;
     421    idxMute = pHandle->controls[OSS_MIXER_SYNTH].idxMute;
     422    break;
     423  case OSS32_MIX_VOLUME_LINEIN:
     424    idx = pHandle->controls[OSS_MIXER_LINE].idxVolume;
     425    idxMute = pHandle->controls[OSS_MIXER_LINE].idxMute;
     426    break;
     427  case OSS32_MIX_VOLUME_MIC:
     428    idx = pHandle->controls[OSS_MIXER_MIC].idxVolume;
     429    idxMute = pHandle->controls[OSS_MIXER_MIC].idxMute;
     430    break;
     431  case OSS32_MIX_VOLUME_CD:
     432    idx = pHandle->controls[OSS_MIXER_CD].idxVolume;
     433    idxMute = pHandle->controls[OSS_MIXER_CD].idxMute;
     434    break;
     435  case OSS32_MIX_VOLUME_SPDIF:
     436    idx = pHandle->controls[OSS_MIXER_DIGITAL1].idxVolume;
     437    idxMute = pHandle->controls[OSS_MIXER_DIGITAL1].idxMute;
     438    break;
     439  case OSS32_MIX_VOLUME_VIDEO:
     440    idx = pHandle->controls[OSS_MIXER_VIDEO].idxVolume;
     441    idxMute = pHandle->controls[OSS_MIXER_VIDEO].idxMute;
     442    break;
     443  case OSS32_MIX_VOLUME_PCSPEAKER:
     444    idx = pHandle->controls[OSS_MIXER_PCSPEAKER].idxVolume;
     445    idxMute = pHandle->controls[OSS_MIXER_PCSPEAKER].idxMute;
     446    break;
     447  case OSS32_MIX_VOLUME_PHONE:
     448    idx = pHandle->controls[OSS_MIXER_PHONEOUT].idxVolume;
     449    idxMute = pHandle->controls[OSS_MIXER_PHONEOUT].idxMute;
     450    break;
     451  case OSS32_MIX_VOLUME_HEADPHONE:
     452    idx = pHandle->controls[OSS_MIXER_HEADPHONE].idxVolume;
     453    idxMute = pHandle->controls[OSS_MIXER_HEADPHONE].idxMute;
     454    break;
     455  case OSS32_MIX_VOLUME_SPEAKER:
     456    idx = pHandle->controls[OSS_MIXER_SPEAKER].idxVolume;
     457    idxMute = pHandle->controls[OSS_MIXER_SPEAKER].idxMute;
     458    break;
     459  case OSS32_MIX_VOLUME_AUX:
     460    idx = pHandle->controls[OSS_MIXER_LINE1].idxVolume;
     461    idxMute = pHandle->controls[OSS_MIXER_LINE1].idxMute;
     462    break;
     463  case OSS32_MIX_VOLUME_CAPTURE:
     464    idx = pHandle->controls[OSS_MIXER_IGAIN].idxVolume;
     465    idxMute = pHandle->controls[OSS_MIXER_IGAIN].idxMute;
     466    break;
     467
     468  default:
     469    DebugInt3();
     470    ret = OSSERR_INVALID_PARAMETER;
     471    goto fail;
     472  }
     473  if(idx == -1) {
     474    rprintf(("Unknown control %d", line));
     475    ret = OSSERR_INVALID_PARAMETER;
     476    goto fail;
     477  }
     478
     479  if(idxMute != -1 && volume != 0) {
     480    //disable mute
     481    pElem->id.numid = pHandle->pids[idxMute].numid;
     482    pElem->indirect = 0;
     483
     484    pElem->value.integer.value[0] = TRUE;  //switch, not mute control (inversed)
     485    pElem->value.integer.value[1] = TRUE;
     486    ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     487  }
     488  //request information about mixer control
     489  pElemInfo->id.numid = pHandle->pids[idx].numid;
     490  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
     491  if(ret) {
     492    ret = UNIXToOSSError(ret);
     493    DebugInt3();
     494    goto fail;
     495  }
     496  if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
     497    ret = OSSERR_INVALID_PARAMETER;
     498    DebugInt3();
     499    goto fail;
     500  }
     501  pElem->id.numid = pHandle->pids[idx].numid;
     502  pElem->indirect = 0;
     503
     504  lVol = ConvertVolume(GET_VOLUME_L(volume), pElemInfo->value.integer.max);
     505  pElem->value.integer.value[0] = lVol;
     506
     507  if(pElemInfo->count > 1) { //stereo
     508    rVol = ConvertVolume(GET_VOLUME_R(volume), pElemInfo->value.integer.max);
     509    pElem->value.integer.value[1] = rVol;
     510  }
     511
     512  dprintf(("OSS32_MixSetVolume of %s streamid %X to (%d,%d)(%d,%d) caps %d",
     513    pHandle->pids[idx].name, (ULONG)pHandle,
     514    GET_VOLUME_L(volume), GET_VOLUME_R(volume), lVol, rVol, pElemInfo->value.integer.max));
    508515
    509516#if 1
    510         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     517  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    511518#else
    512         // looking for more, then one opened streams to prevent of muting active stream
    513         cnt = 0;
    514         for (idx=0; idx < 8*256; idx++)
    515                 if (opened_handles[idx].handle != 0)
    516                         cnt++;
    517 
    518         dprintf(("OSS32_MixSetVolume old cnt=%X line=%x lVol=%x rVol=%x", cnt, line, lVol, rVol));
    519         //        if (((cnt == 1 && (lVol==0 && rVol==0)) || (lVol>0 && rVol>0)) ||
    520         if (cnt == 1 || line != OSS32_MIX_VOLUME_PCM)
    521         {
    522                 dprintf(("OSS32_MixSetVolume Ioctl"));
    523                 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    524 
    525                 if(idxMute != -1 && volume == 0) {
    526                         //enable mute
    527                         pElem->id.numid = pHandle->pids[idxMute].numid;
    528                         pElem->indirect = 0;
    529 
    530                         pElem->value.integer.value[0] = FALSE;  //switch, not mute control (inversed)
    531                         pElem->value.integer.value[1] = FALSE;
    532                         dprintf(("OSS32_MixSetVolume Ioctl mute"));
    533                         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    534                 }
    535         }
     519  // looking for more, then one opened streams to prevent of muting active stream
     520  cnt = 0;
     521  for (idx=0; idx < 8*256; idx++)
     522    if (opened_handles[idx].handle != 0)
     523      cnt++;
     524
     525  dprintf(("OSS32_MixSetVolume old cnt=%X line=%x lVol=%x rVol=%x", cnt, line, lVol, rVol));
     526  //    if (((cnt == 1 && (lVol==0 && rVol==0)) || (lVol>0 && rVol>0)) ||
     527  if (cnt == 1 || line != OSS32_MIX_VOLUME_PCM)
     528  {
     529    dprintf(("OSS32_MixSetVolume Ioctl"));
     530    ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     531
     532    if(idxMute != -1 && volume == 0) {
     533      //enable mute
     534      pElem->id.numid = pHandle->pids[idxMute].numid;
     535      pElem->indirect = 0;
     536
     537      pElem->value.integer.value[0] = FALSE;  //switch, not mute control (inversed)
     538      pElem->value.integer.value[1] = FALSE;
     539      dprintf(("OSS32_MixSetVolume Ioctl mute"));
     540      ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     541    }
     542  }
    536543#endif
    537544
    538         kfree(pElem);
    539         pElem = NULL;
    540         if(ret) {
    541                 rprintf(("OSS32_MixSetVolume ret=%x", ret));
    542                 DebugInt3();
    543                 return UNIXToOSSError(ret);
    544         }
    545         return OSSERR_SUCCESS;
     545  kfree(pElem);
     546  pElem = NULL;
     547  if(ret) {
     548    rprintf(("OSS32_MixSetVolume ret=%x", ret));
     549    DebugInt3();
     550    return UNIXToOSSError(ret);
     551  }
     552  return OSSERR_SUCCESS;
    546553
    547554fail:
    548         if(pElem) kfree(pElem);
    549         return ret;
     555  if(pElem) kfree(pElem);
     556  return ret;
    550557}
    551558//******************************************************************************
     
    553560OSSRET OSS32_MixSetProperty(OSSSTREAMID streamid, ULONG ulLine, ULONG ulValue)
    554561{
    555         mixerhandle              *pHandle = (mixerhandle *)streamid;
    556         struct snd_ctl_elem_value *pElem = NULL;
    557         struct snd_ctl_elem_info  *pElemInfo;
    558         int                               ret, idx = -1, lVol, rVol = 0, j, i;
    559 
    560         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    561                 DebugInt3();
    562                 return OSSERR_INVALID_STREAMID;
    563         }
    564         //set operation to non-blocking
    565         pHandle->file.f_flags = O_NONBLOCK;
    566 
    567         //too big to put on the stack
    568         pElem = (struct snd_ctl_elem_value *)kmalloc(sizeof(struct snd_ctl_elem_value) + sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
    569         if(pElem == NULL) {
    570                 DebugInt3();
    571                 return OSSERR_OUT_OF_MEMORY;
    572         }
    573         pElemInfo = (struct snd_ctl_elem_info *)(pElem+1);
    574 
    575         switch(ulLine) {
    576         case OSS32_MIX_INPUTSRC:
    577                 idx = pHandle->controls[OSS_MIXER_IGAIN].idxCustom;
    578                 //is this capture source supported by the hardware??
    579                 if(!(pHandle->reccaps & OSS32_MIX_FLAG(ulValue))) {
    580                         DebugInt3();
    581                         ret = OSSERR_INVALID_PARAMETER;
    582                         goto fail;
    583                 }
    584                 if(pHandle->rectype == RECTYPE_SELECTOR) {//input source selector
    585                         //set left and right capture source
    586                         pElem->value.enumerated.item[0] = pHandle->idxRecCaps[ulValue];
    587                         pElem->value.enumerated.item[1] = pHandle->idxRecCaps[ulValue];
    588                 }
    589                 else {//capture switch for each input source
    590                         //first turn off all capture switches...
    591                         for(j=0;j<OSS32_MIX_RECSRC_MAX;j++)
    592                         {
    593                                 if(pHandle->idxRecCaps[j] != -1) {
    594                                         idx                                               = pHandle->idxRecCaps[j];
    595 
    596                                         //request information about mixer control
    597                                         pElemInfo->id.numid               = pHandle->pids[idx].numid;
    598                                         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
    599                                         if(ret) {
    600                                                 ret = UNIXToOSSError(ret);
    601                                                 DebugInt3();
    602                                                 goto fail;
    603                                         }
    604                                         if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN) {
    605                                                 ret = OSSERR_INVALID_PARAMETER;
    606                                                 DebugInt3();
    607                                                 goto fail;
    608                                         }
    609 
    610                                         pElem->id.numid                           = pHandle->pids[idx].numid;
    611                                         pElem->indirect                           = 0;
    612                                         for(i=0;i<pElemInfo->count;i++) {
    613                                                 pElem->value.integer.value[i] = 0;
    614                                         }
    615 
    616                                         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    617                                         if(ret) {
    618                                                 ret = UNIXToOSSError(ret);
    619                                                 DebugInt3();
    620                                                 goto fail;
    621                                         }
    622                                 }
    623                         }
    624                         //request information about mixer control
    625                         pElemInfo->id.numid = pHandle->pids[idx].numid;
    626                         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
    627                         if(ret) {
    628                                 ret = UNIXToOSSError(ret);
    629                                 DebugInt3();
    630                                 goto fail;
    631                         }
    632 
    633                         //and enable the capture switch for the selected input source
    634                         idx = pHandle->idxRecCaps[ulValue];
    635                         for(i=0;i<pElemInfo->count;i++) {
    636                                 pElem->value.integer.value[i] = 1;
    637                         }
    638                 }
    639 
    640                 break;
    641 
    642         case OSS32_MIX_SWITCH_MICBOOST:
    643                 idx = pHandle->controls[OSS_MIXER_MIC].idxCustom;
    644                 if(idx == -1) {
    645                         DebugInt3();
    646                         ret = OSSERR_INVALID_PARAMETER;
    647                         goto fail;
    648                 }
    649                 //set mic switch value (on/off)
    650                 pElem->value.integer.value[0] = ulValue;
    651                 break;
    652 
    653         case OSS32_MIX_LEVEL_BASS:
    654                 idx = pHandle->controls[OSS_MIXER_BASS].idxVolume;
    655                 goto levelcontinue;
    656         case OSS32_MIX_LEVEL_TREBLE:
    657                 idx = pHandle->controls[OSS_MIXER_TREBLE].idxVolume;
    658                 goto levelcontinue;
    659         case OSS32_MIX_LEVEL_3DCENTER:
    660                 idx = pHandle->controls[OSS_MIXER_3DCENTER].idxVolume;
    661                 goto levelcontinue;
    662         case OSS32_MIX_LEVEL_3DDEPTH:
    663                 idx = pHandle->controls[OSS_MIXER_3DDEPTH].idxVolume;
     562  mixerhandle      *pHandle = (mixerhandle *)streamid;
     563  struct snd_ctl_elem_value *pElem = NULL;
     564  struct snd_ctl_elem_info  *pElemInfo;
     565  int           ret, idx = -1, lVol, rVol = 0, j, i;
     566
     567  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     568    DebugInt3();
     569    return OSSERR_INVALID_STREAMID;
     570  }
     571  //set operation to non-blocking
     572  pHandle->file.f_flags = O_NONBLOCK;
     573
     574  //too big to put on the stack
     575  pElem = (struct snd_ctl_elem_value *)kmalloc(sizeof(struct snd_ctl_elem_value) + sizeof(struct snd_ctl_elem_info), GFP_KERNEL);
     576  if(pElem == NULL) {
     577    DebugInt3();
     578    return OSSERR_OUT_OF_MEMORY;
     579  }
     580  pElemInfo = (struct snd_ctl_elem_info *)(pElem+1);
     581
     582  switch(ulLine) {
     583  case OSS32_MIX_INPUTSRC:
     584    idx = pHandle->controls[OSS_MIXER_IGAIN].idxCustom;
     585    //is this capture source supported by the hardware??
     586    if(!(pHandle->reccaps & OSS32_MIX_FLAG(ulValue))) {
     587      DebugInt3();
     588      ret = OSSERR_INVALID_PARAMETER;
     589      goto fail;
     590    }
     591    if(pHandle->rectype == RECTYPE_SELECTOR) {//input source selector
     592      //set left and right capture source
     593      pElem->value.enumerated.item[0] = pHandle->idxRecCaps[ulValue];
     594      pElem->value.enumerated.item[1] = pHandle->idxRecCaps[ulValue];
     595    }
     596    else {//capture switch for each input source
     597      //first turn off all capture switches...
     598      for(j=0;j<OSS32_MIX_RECSRC_MAX;j++)
     599      {
     600        if(pHandle->idxRecCaps[j] != -1) {
     601          idx               = pHandle->idxRecCaps[j];
     602
     603          //request information about mixer control
     604          pElemInfo->id.numid       = pHandle->pids[idx].numid;
     605          ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
     606          if(ret) {
     607            ret = UNIXToOSSError(ret);
     608            DebugInt3();
     609            goto fail;
     610          }
     611          if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN) {
     612            ret = OSSERR_INVALID_PARAMETER;
     613            DebugInt3();
     614            goto fail;
     615          }
     616
     617          pElem->id.numid         = pHandle->pids[idx].numid;
     618          pElem->indirect         = 0;
     619          for(i=0;i<pElemInfo->count;i++) {
     620            pElem->value.integer.value[i] = 0;
     621          }
     622
     623          ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     624          if(ret) {
     625            ret = UNIXToOSSError(ret);
     626            DebugInt3();
     627            goto fail;
     628          }
     629        }
     630      }
     631      //request information about mixer control
     632      pElemInfo->id.numid = pHandle->pids[idx].numid;
     633      ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
     634      if(ret) {
     635        ret = UNIXToOSSError(ret);
     636        DebugInt3();
     637        goto fail;
     638      }
     639
     640      //and enable the capture switch for the selected input source
     641      idx = pHandle->idxRecCaps[ulValue];
     642      for(i=0;i<pElemInfo->count;i++) {
     643        pElem->value.integer.value[i] = 1;
     644      }
     645    }
     646
     647    break;
     648
     649  case OSS32_MIX_SWITCH_MICBOOST:
     650    idx = pHandle->controls[OSS_MIXER_MIC].idxCustom;
     651    if(idx == -1) {
     652      DebugInt3();
     653      ret = OSSERR_INVALID_PARAMETER;
     654      goto fail;
     655    }
     656    //set mic switch value (on/off)
     657    pElem->value.integer.value[0] = ulValue;
     658    break;
     659
     660  case OSS32_MIX_LEVEL_BASS:
     661    idx = pHandle->controls[OSS_MIXER_BASS].idxVolume;
     662    goto levelcontinue;
     663  case OSS32_MIX_LEVEL_TREBLE:
     664    idx = pHandle->controls[OSS_MIXER_TREBLE].idxVolume;
     665    goto levelcontinue;
     666  case OSS32_MIX_LEVEL_3DCENTER:
     667    idx = pHandle->controls[OSS_MIXER_3DCENTER].idxVolume;
     668    goto levelcontinue;
     669  case OSS32_MIX_LEVEL_3DDEPTH:
     670    idx = pHandle->controls[OSS_MIXER_3DDEPTH].idxVolume;
    664671levelcontinue:
    665672
    666                 if(idx == -1) {//supported?
    667                         DebugInt3();
    668                         ret = OSSERR_INVALID_PARAMETER;
    669                         goto fail;
    670                 }
    671                 //request information about mixer control
    672                 pElemInfo->id.numid = pHandle->pids[idx].numid;
    673                 ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
    674                 if(ret) {
    675                         ret = UNIXToOSSError(ret);
    676                         DebugInt3();
    677                         goto fail;
    678                 }
    679                 if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
    680                         ret = OSSERR_INVALID_PARAMETER;
    681                         DebugInt3();
    682                         goto fail;
    683                 }
    684                 lVol = ConvertVolume(GET_VOLUME_L(ulValue), pElemInfo->value.integer.max);
    685                 pElem->value.integer.value[0] = lVol;
    686 
    687                 if(pElemInfo->count > 1) { //stereo
    688                         rVol = ConvertVolume(GET_VOLUME_R(ulValue), pElemInfo->value.integer.max);
    689                         pElem->value.integer.value[1] = rVol;
    690                 }
    691                 break;
    692 
    693         default:
    694                 DebugInt3();
    695                 ret = OSSERR_INVALID_PARAMETER;
    696                 goto fail;
    697         }
    698         pElem->id.numid = pHandle->pids[idx].numid;
    699         pElem->indirect = 0;
    700 
    701         dprintf(("OSS32_MixSetProperty of %s to %x", pHandle->pids[idx].name, ulValue));
    702         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
    703 
    704         kfree(pElem);
    705         pElem = NULL;
    706         if(ret) {
    707                 DebugInt3();
    708                 return UNIXToOSSError(ret);
    709         }
    710         return OSSERR_SUCCESS;
     673    if(idx == -1) {//supported?
     674      DebugInt3();
     675      ret = OSSERR_INVALID_PARAMETER;
     676      goto fail;
     677    }
     678    //request information about mixer control
     679    pElemInfo->id.numid = pHandle->pids[idx].numid;
     680    ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_INFO, (ULONG)pElemInfo);
     681    if(ret) {
     682      ret = UNIXToOSSError(ret);
     683      DebugInt3();
     684      goto fail;
     685    }
     686    if(pElemInfo->type != SNDRV_CTL_ELEM_TYPE_INTEGER) {
     687      ret = OSSERR_INVALID_PARAMETER;
     688      DebugInt3();
     689      goto fail;
     690    }
     691    lVol = ConvertVolume(GET_VOLUME_L(ulValue), pElemInfo->value.integer.max);
     692    pElem->value.integer.value[0] = lVol;
     693
     694    if(pElemInfo->count > 1) { //stereo
     695      rVol = ConvertVolume(GET_VOLUME_R(ulValue), pElemInfo->value.integer.max);
     696      pElem->value.integer.value[1] = rVol;
     697    }
     698    break;
     699
     700  default:
     701    DebugInt3();
     702    ret = OSSERR_INVALID_PARAMETER;
     703    goto fail;
     704  }
     705  pElem->id.numid = pHandle->pids[idx].numid;
     706  pElem->indirect = 0;
     707
     708  dprintf(("OSS32_MixSetProperty of %s to %x", pHandle->pids[idx].name, ulValue));
     709  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file, SNDRV_CTL_IOCTL_ELEM_WRITE, (ULONG)pElem);
     710
     711  kfree(pElem);
     712  pElem = NULL;
     713  if(ret) {
     714    DebugInt3();
     715    return UNIXToOSSError(ret);
     716  }
     717  return OSSERR_SUCCESS;
    711718
    712719fail:
    713         if(pElem) kfree(pElem);
    714         return ret;
     720  if(pElem) kfree(pElem);
     721  return ret;
    715722}
    716723//******************************************************************************
     
    718725OSSRET OSS32_MixGetProperty(OSSSTREAMID streamid, ULONG line, ULONG *pValue)
    719726{
    720         mixerhandle *pHandle = (mixerhandle *)streamid;
    721         //int            ret;
    722 
    723         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    724                 DebugInt3();
    725                 return OSSERR_INVALID_STREAMID;
    726         }
    727         //set operation to non-blocking
    728         pHandle->file.f_flags = O_NONBLOCK;
    729 
    730         return OSSERR_NOT_SUPPORTED;
     727  mixerhandle *pHandle = (mixerhandle *)streamid;
     728  //int      ret;
     729
     730  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     731    DebugInt3();
     732    return OSSERR_INVALID_STREAMID;
     733  }
     734  //set operation to non-blocking
     735  pHandle->file.f_flags = O_NONBLOCK;
     736
     737  return OSSERR_NOT_SUPPORTED;
    731738}
    732739//******************************************************************************
     
    734741ULONG OSSToALSAVolume(ULONG OSSVolIdx)
    735742{
    736         switch(OSSVolIdx) {
    737         case OSS_MIXER_VOLUME:
    738                 return OSS32_MIX_VOLUME_MASTER_FRONT;
     743  switch(OSSVolIdx) {
     744  case OSS_MIXER_VOLUME:
     745    return OSS32_MIX_VOLUME_MASTER_FRONT;
    739746#if 0
    740         case OSS_MIXER_VOLUME: //TODO:
    741                 return OSS32_MIX_VOLUME_MASTER_REAR;
     747  case OSS_MIXER_VOLUME: //TODO:
     748    return OSS32_MIX_VOLUME_MASTER_REAR;
    742749#endif
    743         case OSS_MIXER_PCM:
    744                 return OSS32_MIX_VOLUME_PCM;
    745         case OSS_MIXER_SYNTH:
    746                 return OSS32_MIX_VOLUME_MIDI;
    747         case OSS_MIXER_LINE:
    748                 return OSS32_MIX_VOLUME_LINEIN;
    749         case OSS_MIXER_MIC:
    750                 return OSS32_MIX_VOLUME_MIC;
    751         case OSS_MIXER_CD:
    752                 return OSS32_MIX_VOLUME_CD;
    753         case OSS_MIXER_DIGITAL1:
    754                 return OSS32_MIX_VOLUME_SPDIF;
    755         case OSS_MIXER_VIDEO:
    756                 return OSS32_MIX_VOLUME_VIDEO;
    757         case OSS_MIXER_PCSPEAKER:
    758                 return OSS32_MIX_VOLUME_PCSPEAKER;
    759         case OSS_MIXER_PHONEOUT:
    760                 return OSS32_MIX_VOLUME_PHONE;
    761         case OSS_MIXER_IGAIN:
    762                 return OSS32_MIX_VOLUME_CAPTURE;
    763         case OSS_MIXER_TREBLE:
    764                 return OSS32_MIX_LEVEL_TREBLE;
    765         case OSS_MIXER_BASS:
    766                 return OSS32_MIX_LEVEL_BASS;
    767         case OSS_MIXER_HEADPHONE:
    768                 return OSS32_MIX_VOLUME_HEADPHONE;
    769         case OSS_MIXER_SPEAKER:
    770                 return OSS32_MIX_VOLUME_SPEAKER;
    771         case OSS_MIXER_LINE1:
    772                 return OSS32_MIX_VOLUME_AUX;
    773         }
    774         return -1;
     750  case OSS_MIXER_PCM:
     751    return OSS32_MIX_VOLUME_PCM;
     752  case OSS_MIXER_SYNTH:
     753    return OSS32_MIX_VOLUME_MIDI;
     754  case OSS_MIXER_LINE:
     755    return OSS32_MIX_VOLUME_LINEIN;
     756  case OSS_MIXER_MIC:
     757    return OSS32_MIX_VOLUME_MIC;
     758  case OSS_MIXER_CD:
     759    return OSS32_MIX_VOLUME_CD;
     760  case OSS_MIXER_DIGITAL1:
     761    return OSS32_MIX_VOLUME_SPDIF;
     762  case OSS_MIXER_VIDEO:
     763    return OSS32_MIX_VOLUME_VIDEO;
     764  case OSS_MIXER_PCSPEAKER:
     765    return OSS32_MIX_VOLUME_PCSPEAKER;
     766  case OSS_MIXER_PHONEOUT:
     767    return OSS32_MIX_VOLUME_PHONE;
     768  case OSS_MIXER_IGAIN:
     769    return OSS32_MIX_VOLUME_CAPTURE;
     770  case OSS_MIXER_TREBLE:
     771    return OSS32_MIX_LEVEL_TREBLE;
     772  case OSS_MIXER_BASS:
     773    return OSS32_MIX_LEVEL_BASS;
     774  case OSS_MIXER_HEADPHONE:
     775    return OSS32_MIX_VOLUME_HEADPHONE;
     776  case OSS_MIXER_SPEAKER:
     777    return OSS32_MIX_VOLUME_SPEAKER;
     778  case OSS_MIXER_LINE1:
     779    return OSS32_MIX_VOLUME_AUX;
     780  }
     781  return -1;
    775782}
    776783//******************************************************************************
     
    778785OSSRET OSS32_MixQueryCaps(OSSSTREAMID streamid, POSS32_MIXCAPS pCaps)
    779786{
    780         mixerhandle *pHandle = (mixerhandle *)streamid;
    781         int i;
    782 
    783         if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
    784                 DebugInt3();
    785                 return OSSERR_INVALID_STREAMID;
    786         }
    787 
    788         strncpy(pCaps->name, pHandle->info.mixername, sizeof(pCaps->name));
    789         pCaps->fuCtrlCaps = 0;
    790         pCaps->fuRecCaps  = 0;
    791 
    792         for(i=0;i<OSS_MIXER_NRDEVICES;i++)
    793         {
    794                 if(pHandle->controls[i].idxVolume != -1) {
    795                         ULONG volidx = OSSToALSAVolume(i);
    796                         if(volidx != -1)
    797                                 pCaps->fuCtrlCaps |= OSS32_MIX_FLAG(volidx);
    798                 }
    799         }
    800 
    801         //if it has a capture source control or the card has capture route switches,
    802         //then we support intput source selection
    803         if(pHandle->controls[OSS_MIXER_IGAIN].idxCustom != -1 ||
    804            pHandle->rectype == RECTYPE_SWITCH)
    805         {
    806                 pCaps->fuCtrlCaps |= OSS32_MIX_FLAG(OSS32_MIX_INPUTSRC);
    807                 pCaps->fuRecCaps   = pHandle->reccaps;
    808         }
    809         return OSSERR_SUCCESS;
     787  mixerhandle *pHandle = (mixerhandle *)streamid;
     788  int i;
     789
     790  if(pHandle == NULL || pHandle->magic != MAGIC_MIXER_ALSA32) {
     791    DebugInt3();
     792    return OSSERR_INVALID_STREAMID;
     793  }
     794
     795  strncpy(pCaps->name, pHandle->info.mixername, sizeof(pCaps->name));
     796  pCaps->fuCtrlCaps = 0;
     797  pCaps->fuRecCaps  = 0;
     798
     799  for(i=0;i<OSS_MIXER_NRDEVICES;i++)
     800  {
     801    if(pHandle->controls[i].idxVolume != -1) {
     802      ULONG volidx = OSSToALSAVolume(i);
     803      if(volidx != -1)
     804        pCaps->fuCtrlCaps |= OSS32_MIX_FLAG(volidx);
     805    }
     806  }
     807
     808  //if it has a capture source control or the card has capture route switches,
     809  //then we support intput source selection
     810  if(pHandle->controls[OSS_MIXER_IGAIN].idxCustom != -1 ||
     811     pHandle->rectype == RECTYPE_SWITCH)
     812  {
     813    pCaps->fuCtrlCaps |= OSS32_MIX_FLAG(OSS32_MIX_INPUTSRC);
     814    pCaps->fuRecCaps   = pHandle->reccaps;
     815  }
     816  return OSSERR_SUCCESS;
    810817}
    811818//******************************************************************************
     
    813820OSSRET OSS32_MixQueryName(ULONG deviceid, char *pszMixerName, ULONG cbMixerName)
    814821{
    815         mixerhandle *pHandle = NULL;
    816         int              ret;
    817         //int i, j;
    818 
    819         if(alsa_fops == NULL)
    820                 return OSSERR_NO_DEVICE_AVAILABLE;
    821 
    822         pHandle = kmalloc(sizeof(mixerhandle), GFP_KERNEL);
    823         if(pHandle == NULL) {
    824                 ret = OSSERR_OUT_OF_MEMORY;
    825                 goto failure;
    826         }
    827         memset(pHandle, 0, sizeof(mixerhandle));
    828 
    829         //set operation to non-blocking
    830         pHandle->file.f_flags = O_NONBLOCK;
    831 
    832         //setup pointers in file structure (used internally by ALSA)
    833         pHandle->file.f_dentry                  = &pHandle->d_entry;
    834         pHandle->file.f_dentry->d_inode = &pHandle->inode;
    835 
    836         pHandle->file.f_mode  = FMODE_WRITE;
    837         pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
    838 
    839         ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
    840         if(ret) {
    841                 goto failure;
    842         }
    843         //retrieve mixer information
    844         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
    845                                                                         SNDRV_CTL_IOCTL_CARD_INFO,
    846                                                                         (ULONG)&pHandle->info);
    847         if(ret) {
    848                 goto failure;
    849         }
    850 
    851         strncpy(pszMixerName, pHandle->info.mixername, cbMixerName);
    852 
    853         pHandle->file.f_flags = O_NONBLOCK;
    854         ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
    855         if(ret) {
    856                 goto failure;
    857         }
    858         kfree(pHandle);
    859         return OSSERR_SUCCESS;
     822  mixerhandle *pHandle = NULL;
     823  int      ret;
     824  //int i, j;
     825
     826  if(alsa_fops == NULL)
     827    return OSSERR_NO_DEVICE_AVAILABLE;
     828
     829  pHandle = kmalloc(sizeof(mixerhandle), GFP_KERNEL);
     830  if(pHandle == NULL) {
     831    ret = OSSERR_OUT_OF_MEMORY;
     832    goto failure;
     833  }
     834  memset(pHandle, 0, sizeof(mixerhandle));
     835
     836  //set operation to non-blocking
     837  pHandle->file.f_flags = O_NONBLOCK;
     838
     839  //setup pointers in file structure (used internally by ALSA)
     840  pHandle->file.f_dentry      = &pHandle->d_entry;
     841  pHandle->file.f_dentry->d_inode = &pHandle->inode;
     842
     843  pHandle->file.f_mode  = FMODE_WRITE;
     844  pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
     845
     846  ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
     847  if(ret) {
     848    goto failure;
     849  }
     850  //retrieve mixer information
     851  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
     852                  SNDRV_CTL_IOCTL_CARD_INFO,
     853                  (ULONG)&pHandle->info);
     854  if(ret) {
     855    goto failure;
     856  }
     857
     858  strncpy(pszMixerName, pHandle->info.mixername, cbMixerName);
     859
     860  pHandle->file.f_flags = O_NONBLOCK;
     861  ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
     862  if(ret) {
     863    goto failure;
     864  }
     865  kfree(pHandle);
     866  return OSSERR_SUCCESS;
    860867
    861868failure:
    862         if(pHandle) {
    863                 kfree(pHandle);
    864         }
    865         DebugInt3();
    866         return OSSERR_OUT_OF_MEMORY;
     869  if(pHandle) {
     870    kfree(pHandle);
     871  }
     872  DebugInt3();
     873  return OSSERR_OUT_OF_MEMORY;
    867874}
    868875//******************************************************************************
    869876//******************************************************************************
    870877OSSRET OSS32_QueryNames(ULONG deviceid, char *pszDeviceName, ULONG cbDeviceName,
    871                                                 char *pszMixerName, ULONG cbMixerName, BOOL fLongName)
    872 {
    873         mixerhandle *pHandle = NULL;
    874         int              ret;
    875         //int i, j;
    876 
    877         if(alsa_fops == NULL) {
    878                 ret = OSSERR_NO_DEVICE_AVAILABLE;
    879                 printk("ret = OSSERR_NO_DEVICE_AVAILABLE\n");
    880                 goto failure;
    881         }
    882 
    883         pHandle = kmalloc(sizeof(mixerhandle), GFP_KERNEL);
    884         if(pHandle == NULL) {
    885                 ret = OSSERR_OUT_OF_MEMORY;
    886                 goto failure;
    887         }
    888         memset(pHandle, 0, sizeof(mixerhandle));
    889 
    890         //set operation to non-blocking
    891         pHandle->file.f_flags = O_NONBLOCK;
    892 
    893         //setup pointers in file structure (used internally by ALSA)
    894         pHandle->file.f_dentry                  = &pHandle->d_entry;
    895         pHandle->file.f_dentry->d_inode = &pHandle->inode;
    896 
    897         pHandle->file.f_mode  = FMODE_WRITE;
    898         pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
    899 
    900         ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
    901         if(ret) {
    902                 printk("open ret = %i\n", ret);
    903                 goto failure;
    904         }
    905         //retrieve mixer information
    906         ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
    907                                                                         SNDRV_CTL_IOCTL_CARD_INFO,
    908                                                                         (ULONG)&pHandle->info);
    909         if(ret) {
    910                 printk("ioctl ret = %i\n", ret);
    911                 goto failure;
    912         }
    913 
    914         if(pszDeviceName) {
    915                 if(fLongName == TRUE) {
    916                         strncpy(pszDeviceName, pHandle->info.longname, cbDeviceName);
    917                 }
    918                 else strncpy(pszDeviceName, pHandle->info.name, cbDeviceName);
    919         }
    920         if(pszMixerName) {
    921                 strncpy(pszMixerName, pHandle->info.mixername, cbMixerName);
    922         }
    923 
    924 //        printk("Card: %s with mixer %s\n",pszDeviceName, pszMixerName);
    925 
    926         pHandle->file.f_flags = O_NONBLOCK;
    927         ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
    928         if(ret) {
    929                 printk("release ret = %i\n", ret);
    930                 goto failure;
    931         }
    932         kfree(pHandle);
    933         return OSSERR_SUCCESS;
     878            char *pszMixerName, ULONG cbMixerName, BOOL fLongName)
     879{
     880  mixerhandle *pHandle = NULL;
     881  int      ret;
     882  //int i, j;
     883
     884  if(alsa_fops == NULL) {
     885    ret = OSSERR_NO_DEVICE_AVAILABLE;
     886    printk("ret = OSSERR_NO_DEVICE_AVAILABLE\n");
     887    goto failure;
     888  }
     889
     890  pHandle = kmalloc(sizeof(mixerhandle), GFP_KERNEL);
     891  if(pHandle == NULL) {
     892    ret = OSSERR_OUT_OF_MEMORY;
     893    goto failure;
     894  }
     895  memset(pHandle, 0, sizeof(mixerhandle));
     896
     897  //set operation to non-blocking
     898  pHandle->file.f_flags = O_NONBLOCK;
     899
     900  //setup pointers in file structure (used internally by ALSA)
     901  pHandle->file.f_dentry      = &pHandle->d_entry;
     902  pHandle->file.f_dentry->d_inode = &pHandle->inode;
     903
     904  pHandle->file.f_mode  = FMODE_WRITE;
     905  pHandle->inode.i_rdev = SNDRV_MINOR(deviceid, SNDRV_MINOR_CONTROL);
     906
     907  ret = alsa_fops->open(&pHandle->inode, &pHandle->file);
     908  if(ret) {
     909    printk("open ret = %i\n", ret);
     910    goto failure;
     911  }
     912  //retrieve mixer information
     913  ret = pHandle->file.f_op->ioctl(&pHandle->inode, &pHandle->file,
     914                  SNDRV_CTL_IOCTL_CARD_INFO,
     915                  (ULONG)&pHandle->info);
     916  if(ret) {
     917    printk("ioctl ret = %i\n", ret);
     918    goto failure;
     919  }
     920
     921  if(pszDeviceName) {
     922    if(fLongName == TRUE) {
     923      strncpy(pszDeviceName, pHandle->info.longname, cbDeviceName);
     924    }
     925    else strncpy(pszDeviceName, pHandle->info.name, cbDeviceName);
     926  }
     927  if(pszMixerName) {
     928    strncpy(pszMixerName, pHandle->info.mixername, cbMixerName);
     929  }
     930
     931//    printk("Card: %s with mixer %s\n",pszDeviceName, pszMixerName);
     932
     933  pHandle->file.f_flags = O_NONBLOCK;
     934  ret = pHandle->file.f_op->release(&pHandle->inode, &pHandle->file);
     935  if(ret) {
     936    printk("release ret = %i\n", ret);
     937    goto failure;
     938  }
     939  kfree(pHandle);
     940  return OSSERR_SUCCESS;
    934941
    935942failure:
    936         if(pHandle) {
    937                 kfree(pHandle);
    938         }
    939         DebugInt3();
    940         printk("OSS32_QueryNames() ret = %i\n", ret);
    941         return OSSERR_OUT_OF_MEMORY;
    942 }
    943 //******************************************************************************
    944 //******************************************************************************
    945 
     943  if(pHandle) {
     944    kfree(pHandle);
     945  }
     946  DebugInt3();
     947  printk("OSS32_QueryNames() ret = %i\n", ret);
     948  return OSSERR_OUT_OF_MEMORY;
     949}
     950//******************************************************************************
     951//******************************************************************************
     952
  • GPL/trunk/uniaud.inc

    r602 r604  
    22
    33# Product name
    4 PRODUCTNAME = Universal Audio Driver for OS/2 and eComStation
     4PRODUCTNAME = Universal Audio Driver for OS/2
    55
    66# Full UNIAUD build version
    77# BUILDVERSION must be 3 parts, and only numbers like 5.44.108
    88# The second and third numbers must be 2 digits
    9 BUILDVERSION = 2.02.03
     9BUILDVERSION = 2.02.04
    1010
    1111# Fixpack version
Note: See TracChangeset for help on using the changeset viewer.