1
diff -Nru linux-2.6.0_orig/include/sound/ac97_codec.h linux-2.6.0/include/sound/ac97_codec.h
2
--- linux-2.6.0_orig/include/sound/ac97_codec.h 2003-12-28 22:18:44.000000000 +0200
3
+++ linux-2.6.0/include/sound/ac97_codec.h 2003-12-28 22:29:43.000000000 +0200
5
#define AC97_MEA_PRG 0x4000 /* HADC power down (high) */
6
#define AC97_MEA_PRH 0x8000 /* HDAC power down (high) */
8
+/* modem gpio status defines */
9
+#define AC97_GPIO_LINE1_OH 0x0001 /* Off Hook Line1 */
10
+#define AC97_GPIO_LINE1_RI 0x0002 /* Ring Detect Line1 */
11
+#define AC97_GPIO_LINE1_CID 0x0004 /* Caller ID path enable Line1 */
12
+#define AC97_GPIO_LINE1_LCS 0x0008 /* Loop Current Sense Line1 */
13
+#define AC97_GPIO_LINE1_PULSE 0x0010 /* Opt./ Pulse Dial Line1 (out) */
14
+#define AC97_GPIO_LINE1_HL1R 0x0020 /* Opt./ Handset to Line1 relay control (out) */
15
+#define AC97_GPIO_LINE1_HOHD 0x0040 /* Opt./ Handset off hook detect Line1 (in) */
16
+#define AC97_GPIO_LINE12_AC 0x0080 /* Opt./ Int.bit 1 / Line1/2 AC (out) */
17
+#define AC97_GPIO_LINE12_DC 0x0100 /* Opt./ Int.bit 2 / Line1/2 DC (out) */
18
+#define AC97_GPIO_LINE12_RS 0x0200 /* Opt./ Int.bit 3 / Line1/2 RS (out) */
19
+#define AC97_GPIO_LINE2_OH 0x0400 /* Off Hook Line2 */
20
+#define AC97_GPIO_LINE2_RI 0x0800 /* Ring Detect Line2 */
21
+#define AC97_GPIO_LINE2_CID 0x1000 /* Caller ID path enable Line2 */
22
+#define AC97_GPIO_LINE2_LCS 0x2000 /* Loop Current Sense Line2 */
23
+#define AC97_GPIO_LINE2_PULSE 0x4000 /* Opt./ Pulse Dial Line2 (out) */
24
+#define AC97_GPIO_LINE2_HL1R 0x8000 /* Opt./ Handset to Line2 relay control (out) */
26
/* specific - SigmaTel */
27
#define AC97_SIGMATEL_ANALOG 0x6c /* Analog Special */
28
#define AC97_SIGMATEL_DAC2INVERT 0x6e
29
diff -Nru linux-2.6.0_orig/sound/pci/ac97/ac97_codec.c linux-2.6.0/sound/pci/ac97/ac97_codec.c
30
--- linux-2.6.0_orig/sound/pci/ac97/ac97_codec.c 2003-12-28 22:18:44.000000000 +0200
31
+++ linux-2.6.0/sound/pci/ac97/ac97_codec.c 2003-12-28 22:29:43.000000000 +0200
33
{ 0x4e534331, 0xffffffff, "LM4549", NULL, NULL },
34
{ 0x4e534350, 0xffffffff, "LM4550", NULL, NULL },
35
{ 0x50534304, 0xffffffff, "UCB1400", NULL, NULL },
36
-{ 0x53494c20, 0xffffffe0, "Si3036/8", NULL, NULL },
37
+{ 0x53494c20, 0xffffffe0, "Si3036/8", NULL, mpatch_si3036 },
38
{ 0x54524102, 0xffffffff, "TR28022", NULL, NULL },
39
{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL },
40
{ 0x54524108, 0xffffffff, "TR28028", patch_tritech_tr28028, NULL }, // added by xin jin [07/09/99]
41
@@ -1492,6 +1492,12 @@
42
static int snd_ac97_modem_build(snd_card_t * card, ac97_t * ac97)
45
+ //printk("AC97_GPIO_CFG = %x\n",snd_ac97_read(ac97,AC97_GPIO_CFG));
46
+ snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
47
+ snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
48
+ snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
49
+ snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0);
50
+ snd_ac97_write(ac97, AC97_MISC_AFE, 0x0);
54
diff -Nru linux-2.6.0_orig/sound/pci/ac97/ac97_patch.c linux-2.6.0/sound/pci/ac97/ac97_patch.c
55
--- linux-2.6.0_orig/sound/pci/ac97/ac97_patch.c 2003-12-28 22:18:44.000000000 +0200
56
+++ linux-2.6.0/sound/pci/ac97/ac97_patch.c 2003-12-28 22:29:43.000000000 +0200
57
@@ -1099,3 +1099,14 @@
58
ac97->build_ops = &patch_vt1616_ops;
62
+/* Si3036/8 specific registers */
63
+#define AC97_SI3036_CHIP_ID 0x5a
65
+int mpatch_si3036(ac97_t * ac97)
67
+ //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
68
+ snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
69
+ snd_ac97_write_cache(ac97, 0x68, 0);
72
diff -Nru linux-2.6.0_orig/sound/pci/ac97/ac97_patch.h linux-2.6.0/sound/pci/ac97/ac97_patch.h
73
--- linux-2.6.0_orig/sound/pci/ac97/ac97_patch.h 2003-12-28 22:18:44.000000000 +0200
74
+++ linux-2.6.0/sound/pci/ac97/ac97_patch.h 2003-12-28 22:29:43.000000000 +0200
76
int patch_cm9738(ac97_t * ac97);
77
int patch_cm9739(ac97_t * ac97);
78
int patch_vt1616(ac97_t * ac97);
79
+int mpatch_si3036(ac97_t * ac97);
81
diff -Nru linux-2.6.0_orig/sound/pci/intel8x0m.c linux-2.6.0/sound/pci/intel8x0m.c
82
--- linux-2.6.0_orig/sound/pci/intel8x0m.c 1970-01-01 02:00:00.000000000 +0200
83
+++ linux-2.6.0/sound/pci/intel8x0m.c 2003-12-28 22:30:09.000000000 +0200
86
+ * ALSA modem driver for Intel ICH (i8x0) chipsets
88
+ * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
90
+ * This is modified (by Sasha Khapyorsky <sashak@smlink.com>) version
91
+ * of ALSA ICH sound driver intel8x0.c .
94
+ * This program is free software; you can redistribute it and/or modify
95
+ * it under the terms of the GNU General Public License as published by
96
+ * the Free Software Foundation; either version 2 of the License, or
97
+ * (at your option) any later version.
99
+ * This program is distributed in the hope that it will be useful,
100
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
101
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102
+ * GNU General Public License for more details.
104
+ * You should have received a copy of the GNU General Public License
105
+ * along with this program; if not, write to the Free Software
106
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
110
+#include <sound/driver.h>
112
+#include <linux/delay.h>
113
+#include <linux/interrupt.h>
114
+#include <linux/init.h>
115
+#include <linux/pci.h>
116
+#include <linux/slab.h>
117
+#include <linux/gameport.h>
118
+#include <sound/core.h>
119
+#include <sound/pcm.h>
120
+#include <sound/ac97_codec.h>
121
+#include <sound/info.h>
122
+#include <sound/mpu401.h>
123
+#define SNDRV_GET_ID
124
+#include <sound/initval.h>
126
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
127
+MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440 modem");
128
+MODULE_LICENSE("GPL");
129
+MODULE_CLASSES("{sound}");
130
+MODULE_DEVICES("{{Intel,82801AA-ICH},"
131
+ "{Intel,82901AB-ICH0},"
132
+ "{Intel,82801BA-ICH2},"
133
+ "{Intel,82801CA-ICH3},"
134
+ "{Intel,82801DB-ICH4},"
139
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
140
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
141
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
142
+static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
144
+MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
145
+MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard.");
146
+MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
147
+MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
148
+MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard.");
149
+MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
150
+MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
151
+MODULE_PARM_DESC(enable, "Enable Intel i8x0 modemcard.");
152
+MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
153
+MODULE_PARM(ac97_clock, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
154
+MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
155
+MODULE_PARM_SYNTAX(ac97_clock, SNDRV_ENABLED ",default:0");
161
+#ifndef PCI_DEVICE_ID_INTEL_82801_6
162
+#define PCI_DEVICE_ID_INTEL_82801_6 0x2416
164
+#ifndef PCI_DEVICE_ID_INTEL_82901_6
165
+#define PCI_DEVICE_ID_INTEL_82901_6 0x2426
167
+#ifndef PCI_DEVICE_ID_INTEL_82801BA_6
168
+#define PCI_DEVICE_ID_INTEL_82801BA_6 0x2446
170
+#ifndef PCI_DEVICE_ID_INTEL_440MX_6
171
+#define PCI_DEVICE_ID_INTEL_440MX_6 0x7196
173
+#ifndef PCI_DEVICE_ID_INTEL_ICH3_6
174
+#define PCI_DEVICE_ID_INTEL_ICH3_6 0x2486
176
+#ifndef PCI_DEVICE_ID_INTEL_ICH4_6
177
+#define PCI_DEVICE_ID_INTEL_ICH4_6 0x24c6
179
+#ifndef PCI_DEVICE_ID_INTEL_ICH5_6
180
+#define PCI_DEVICE_ID_INTEL_ICH5_6 0x24d6
182
+#ifndef PCI_DEVICE_ID_SI_7013
183
+#define PCI_DEVICE_ID_SI_7013 0x7013
186
+#ifndef PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
187
+#define PCI_DEVICE_ID_NVIDIA_MCP_AUDIO 0x01b1
189
+#ifndef PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
190
+#define PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO 0x006a
192
+#ifndef PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO
193
+#define PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO 0x00da
197
+enum { DEVICE_INTEL, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
199
+#define ICHREG(x) ICH_REG_##x
201
+#define DEFINE_REGSET(name,base) \
203
+ ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
204
+ ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
205
+ ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
206
+ ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
207
+ ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
208
+ ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
209
+ ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
212
+/* busmaster blocks */
213
+DEFINE_REGSET(OFF, 0); /* offset */
215
+/* values for each busmaster block */
218
+#define ICH_REG_LVI_MASK 0x1f
221
+#define ICH_FIFOE 0x10 /* FIFO error */
222
+#define ICH_BCIS 0x08 /* buffer completion interrupt status */
223
+#define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
224
+#define ICH_CELV 0x02 /* current equals last valid */
225
+#define ICH_DCH 0x01 /* DMA controller halted */
228
+#define ICH_REG_PIV_MASK 0x1f /* mask */
231
+#define ICH_IOCE 0x10 /* interrupt on completion enable */
232
+#define ICH_FEIE 0x08 /* fifo error interrupt enable */
233
+#define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
234
+#define ICH_RESETREGS 0x02 /* reset busmaster registers */
235
+#define ICH_STARTBM 0x01 /* start busmaster operation */
239
+#define ICH_REG_GLOB_CNT 0x3c /* dword - global control */
240
+#define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
241
+#define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
242
+#define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
243
+#define ICH_ACLINK 0x00000008 /* AClink shut off */
244
+#define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
245
+#define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
246
+#define ICH_GIE 0x00000001 /* GPI interrupt enable */
247
+#define ICH_REG_GLOB_STA 0x40 /* dword - global status */
248
+#define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
249
+#define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
250
+#define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
251
+#define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
252
+#define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
253
+#define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
254
+#define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
255
+#define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
256
+#define ICH_MD3 0x00020000 /* modem power down semaphore */
257
+#define ICH_AD3 0x00010000 /* audio power down semaphore */
258
+#define ICH_RCS 0x00008000 /* read completion status */
259
+#define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
260
+#define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
261
+#define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
262
+#define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
263
+#define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
264
+#define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
265
+#define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
266
+#define ICH_MCINT 0x00000080 /* MIC capture interrupt */
267
+#define ICH_POINT 0x00000040 /* playback interrupt */
268
+#define ICH_PIINT 0x00000020 /* capture interrupt */
269
+#define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
270
+#define ICH_MOINT 0x00000004 /* modem playback interrupt */
271
+#define ICH_MIINT 0x00000002 /* modem capture interrupt */
272
+#define ICH_GSCI 0x00000001 /* GPI status change interrupt */
273
+#define ICH_REG_ACC_SEMA 0x44 /* byte - codec write semaphore */
274
+#define ICH_CAS 0x01 /* codec access semaphore */
276
+#define ICH_MAX_FRAGS 32 /* max hw frags */
283
+enum { ICHD_MDMIN, ICHD_MDMOUT, ICHD_MDMLAST = ICHD_MDMOUT };
284
+enum { ALID_MDMIN, ALID_MDMOUT, ALID_MDMLAST = ALID_MDMOUT };
286
+#define get_ichdev(substream) (ichdev_t *)(substream->runtime->private_data)
289
+ unsigned int ichd; /* ich device number */
290
+ unsigned long reg_offset; /* offset to bmaddr */
291
+ u32 *bdbar; /* CPU address (32bit) */
292
+ unsigned int bdbar_addr; /* PCI bus address (32bit) */
293
+ snd_pcm_substream_t *substream;
294
+ unsigned int physbuf; /* physical address (32bit) */
296
+ unsigned int fragsize;
297
+ unsigned int fragsize1;
298
+ unsigned int position;
305
+ unsigned int ack_bit;
306
+ unsigned int roff_sr;
307
+ unsigned int roff_picb;
308
+ unsigned int int_sta_mask; /* interrupt status mask */
309
+ unsigned int ali_slot; /* ALI DMA slot */
313
+typedef struct _snd_intel8x0m intel8x0_t;
314
+#define chip_t intel8x0_t
316
+struct _snd_intel8x0m {
317
+ unsigned int device_type;
318
+ char ac97_name[64];
319
+ char ctrl_name[64];
324
+ unsigned long addr;
325
+ unsigned long remap_addr;
326
+ struct resource *res;
327
+ unsigned int bm_mmio;
328
+ unsigned long bmaddr;
329
+ unsigned long remap_bmaddr;
330
+ struct resource *res_bm;
332
+ struct pci_dev *pci;
339
+ int in_ac97_init: 1;
343
+ spinlock_t reg_lock;
344
+ spinlock_t ac97_lock;
348
+ dma_addr_t bdbars_addr;
349
+ u32 int_sta_reg; /* interrupt status register */
350
+ u32 int_sta_mask; /* interrupt status mask */
351
+ unsigned int pcm_pos_shift;
358
+static struct pci_device_id snd_intel8x0m_ids[] = {
359
+ { 0x8086, 0x2416, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */
360
+ { 0x8086, 0x2426, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */
361
+ { 0x8086, 0x2446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */
362
+ { 0x8086, 0x2486, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */
363
+ { 0x8086, 0x24c6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH4 */
364
+ { 0x8086, 0x24d6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH5 */
365
+ { 0x8086, 0x7196, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */
366
+ { 0x1022, 0x7446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
368
+ /* TODO: support needed */
369
+ { 0x1039, 0x7013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7013 */
370
+ { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */
371
+ { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */
372
+ { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */
373
+ { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
374
+ { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
379
+MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
382
+ * Lowlevel I/O - busmaster
385
+static u8 igetbyte(intel8x0_t *chip, u32 offset)
388
+ return readb(chip->remap_bmaddr + offset);
390
+ return inb(chip->bmaddr + offset);
393
+static u16 igetword(intel8x0_t *chip, u32 offset)
396
+ return readw(chip->remap_bmaddr + offset);
398
+ return inw(chip->bmaddr + offset);
401
+static u32 igetdword(intel8x0_t *chip, u32 offset)
404
+ return readl(chip->remap_bmaddr + offset);
406
+ return inl(chip->bmaddr + offset);
409
+static void iputbyte(intel8x0_t *chip, u32 offset, u8 val)
412
+ writeb(val, chip->remap_bmaddr + offset);
414
+ outb(val, chip->bmaddr + offset);
417
+static void iputdword(intel8x0_t *chip, u32 offset, u32 val)
420
+ writel(val, chip->remap_bmaddr + offset);
422
+ outl(val, chip->bmaddr + offset);
426
+ * Lowlevel I/O - AC'97 registers
429
+static u16 iagetword(intel8x0_t *chip, u32 offset)
432
+ return readw(chip->remap_addr + offset);
434
+ return inw(chip->addr + offset);
437
+static void iaputword(intel8x0_t *chip, u32 offset, u16 val)
440
+ writew(val, chip->remap_addr + offset);
442
+ outw(val, chip->addr + offset);
450
+ * access to AC97 codec via normal i/o (for ICH and SIS7013)
453
+/* return the GLOB_STA bit for the corresponding codec */
454
+static unsigned int get_ich_codec_bit(intel8x0_t *chip, unsigned int codec)
456
+ static unsigned int codec_bit[3] = {
457
+ ICH_PCR, ICH_SCR, ICH_TCR
459
+ snd_assert(codec < 3, return ICH_PCR);
460
+ return codec_bit[codec];
463
+static int snd_intel8x0m_codec_semaphore(intel8x0_t *chip, unsigned int codec)
469
+ codec = get_ich_codec_bit(chip, codec);
471
+ /* codec ready ? */
472
+ if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
475
+ /* Anyone holding a semaphore for 1 msec should be shot... */
478
+ if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
483
+ /* access to some forbidden (non existant) ac97 registers will not
484
+ * reset the semaphore. So even if you don't get the semaphore, still
485
+ * continue the access. We don't need the semaphore anyway. */
486
+ snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
487
+ igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
488
+ iagetword(chip, 0); /* clear semaphore flag */
489
+ /* I don't care about the semaphore */
493
+static void snd_intel8x0_codec_write(ac97_t *ac97,
494
+ unsigned short reg,
495
+ unsigned short val)
497
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, ac97->private_data, return);
499
+ spin_lock(&chip->ac97_lock);
500
+ if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
501
+ if (! chip->in_ac97_init)
502
+ snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
504
+ iaputword(chip, reg + ac97->num * 0x80, val);
505
+ spin_unlock(&chip->ac97_lock);
508
+static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
509
+ unsigned short reg)
511
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, ac97->private_data, return ~0);
512
+ unsigned short res;
515
+ spin_lock(&chip->ac97_lock);
516
+ if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
517
+ if (! chip->in_ac97_init)
518
+ snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
521
+ res = iagetword(chip, reg + ac97->num * 0x80);
522
+ if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) {
523
+ /* reset RCS and preserve other R/WC bits */
524
+ iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
525
+ if (! chip->in_ac97_init)
526
+ snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
530
+ spin_unlock(&chip->ac97_lock);
538
+static void snd_intel8x0_setup_periods(intel8x0_t *chip, ichdev_t *ichdev)
541
+ u32 *bdbar = ichdev->bdbar;
542
+ unsigned long port = ichdev->reg_offset;
544
+ iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
545
+ if (ichdev->size == ichdev->fragsize) {
546
+ ichdev->ack_reload = ichdev->ack = 2;
547
+ ichdev->fragsize1 = ichdev->fragsize >> 1;
548
+ for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
549
+ bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
550
+ bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
551
+ ichdev->fragsize1 >> chip->pcm_pos_shift);
552
+ bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
553
+ bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
554
+ ichdev->fragsize1 >> chip->pcm_pos_shift);
558
+ ichdev->ack_reload = ichdev->ack = 1;
559
+ ichdev->fragsize1 = ichdev->fragsize;
560
+ for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
561
+ bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
562
+ bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
563
+ ichdev->fragsize >> chip->pcm_pos_shift);
564
+ // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
566
+ ichdev->frags = ichdev->size / ichdev->fragsize;
568
+ iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
570
+ iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
571
+ ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
572
+ ichdev->position = 0;
574
+ printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
575
+ ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1);
577
+ /* clear interrupts */
578
+ iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
582
+ * Interrupt handler
585
+static inline void snd_intel8x0_update(intel8x0_t *chip, ichdev_t *ichdev)
587
+ unsigned long port = ichdev->reg_offset;
591
+ civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
592
+ if (civ == ichdev->civ) {
593
+ // snd_printd("civ same %d\n", civ);
596
+ ichdev->civ &= ICH_REG_LVI_MASK;
598
+ step = civ - ichdev->civ;
600
+ step += ICH_REG_LVI_MASK + 1;
602
+ // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
606
+ ichdev->position += step * ichdev->fragsize1;
607
+ ichdev->position %= ichdev->size;
608
+ ichdev->lvi += step;
609
+ ichdev->lvi &= ICH_REG_LVI_MASK;
610
+ iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
611
+ for (i = 0; i < step; i++) {
612
+ ichdev->lvi_frag++;
613
+ ichdev->lvi_frag %= ichdev->frags;
614
+ ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
615
+ // printk("new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n", ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), inl(port + 4), inb(port + ICH_REG_OFF_CR));
616
+ if (--ichdev->ack == 0) {
617
+ ichdev->ack = ichdev->ack_reload;
621
+ if (ack && ichdev->substream) {
622
+ spin_unlock(&chip->reg_lock);
623
+ snd_pcm_period_elapsed(ichdev->substream);
624
+ spin_lock(&chip->reg_lock);
626
+ iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
629
+static irqreturn_t snd_intel8x0_interrupt(int irq, void *dev_id, struct pt_regs *regs)
631
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, dev_id, return IRQ_NONE);
633
+ unsigned int status;
636
+ spin_lock(&chip->reg_lock);
637
+ status = igetdword(chip, chip->int_sta_reg);
638
+ if ((status & chip->int_sta_mask) == 0) {
640
+ iputdword(chip, chip->int_sta_reg, status);
641
+ spin_unlock(&chip->reg_lock);
645
+ for (i = 0; i < chip->bdbars_count; i++) {
646
+ ichdev = &chip->ichd[i];
647
+ if (status & ichdev->int_sta_mask)
648
+ snd_intel8x0_update(chip, ichdev);
652
+ iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
653
+ spin_unlock(&chip->reg_lock);
655
+ return IRQ_HANDLED;
662
+static int snd_intel8x0_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
664
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
665
+ ichdev_t *ichdev = get_ichdev(substream);
666
+ unsigned char val = 0;
667
+ unsigned long port = ichdev->reg_offset;
670
+ case SNDRV_PCM_TRIGGER_START:
671
+ case SNDRV_PCM_TRIGGER_RESUME:
672
+ val = ICH_IOCE | ICH_STARTBM;
674
+ case SNDRV_PCM_TRIGGER_STOP:
675
+ case SNDRV_PCM_TRIGGER_SUSPEND:
678
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
681
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
682
+ val = ICH_IOCE | ICH_STARTBM;
687
+ iputbyte(chip, port + ICH_REG_OFF_CR, val);
688
+ if (cmd == SNDRV_PCM_TRIGGER_STOP) {
689
+ /* wait until DMA stopped */
690
+ while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
691
+ /* reset whole DMA things */
692
+ iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
697
+static int snd_intel8x0_hw_params(snd_pcm_substream_t * substream,
698
+ snd_pcm_hw_params_t * hw_params)
700
+ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
703
+static int snd_intel8x0_hw_free(snd_pcm_substream_t * substream)
705
+ return snd_pcm_lib_free_pages(substream);
708
+static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(snd_pcm_substream_t * substream)
710
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
711
+ ichdev_t *ichdev = get_ichdev(substream);
714
+ ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << chip->pcm_pos_shift;
716
+ ptr = ichdev->fragsize1 - ptr1;
719
+ ptr += ichdev->position;
720
+ if (ptr >= ichdev->size)
722
+ return bytes_to_frames(substream->runtime, ptr);
725
+static int snd_intel8x0m_pcm_trigger(snd_pcm_substream_t *substream, int cmd)
727
+ ichdev_t *ichdev = get_ichdev(substream);
728
+ /* hook off/on on start/stop */
729
+ /* TODO: move it to ac97 controls */
731
+ case SNDRV_PCM_TRIGGER_START:
732
+ snd_ac97_update_bits(ichdev->ac97, AC97_GPIO_STATUS,
733
+ AC97_GPIO_LINE1_OH, AC97_GPIO_LINE1_OH);
735
+ case SNDRV_PCM_TRIGGER_STOP:
736
+ snd_ac97_update_bits(ichdev->ac97, AC97_GPIO_STATUS,
737
+ AC97_GPIO_LINE1_OH, ~AC97_GPIO_LINE1_OH);
742
+ return snd_intel8x0_pcm_trigger(substream,cmd);
745
+static int snd_intel8x0m_pcm_prepare(snd_pcm_substream_t * substream)
747
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
748
+ snd_pcm_runtime_t *runtime = substream->runtime;
749
+ ichdev_t *ichdev = get_ichdev(substream);
751
+ ichdev->physbuf = runtime->dma_addr;
752
+ ichdev->size = snd_pcm_lib_buffer_bytes(substream);
753
+ ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
754
+ snd_ac97_write(ichdev->ac97, AC97_LINE1_RATE, runtime->rate);
755
+ snd_ac97_write(ichdev->ac97, AC97_LINE1_LEVEL, 0);
756
+ snd_intel8x0_setup_periods(chip, ichdev);
760
+static snd_pcm_hardware_t snd_intel8x0m_stream =
762
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
763
+ SNDRV_PCM_INFO_BLOCK_TRANSFER |
764
+ SNDRV_PCM_INFO_MMAP_VALID |
765
+ SNDRV_PCM_INFO_PAUSE |
766
+ SNDRV_PCM_INFO_RESUME),
767
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
768
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_KNOT,
773
+ .buffer_bytes_max = 32 * 1024,
774
+ .period_bytes_min = 32,
775
+ .period_bytes_max = 32 * 1024,
777
+ .periods_max = 1024,
782
+static int snd_intel8x0m_pcm_open(snd_pcm_substream_t * substream, ichdev_t *ichdev)
784
+ static unsigned int rates[] = { 8000, 9600, 12000, 16000 };
785
+ static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
786
+ .count = ARRAY_SIZE(rates),
790
+ snd_pcm_runtime_t *runtime = substream->runtime;
793
+ ichdev->substream = substream;
794
+ runtime->hw = snd_intel8x0m_stream;
795
+ err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
798
+ runtime->private_data = ichdev;
802
+static int snd_intel8x0m_playback_open(snd_pcm_substream_t * substream)
804
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
806
+ return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMOUT]);
809
+static int snd_intel8x0m_playback_close(snd_pcm_substream_t * substream)
811
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
813
+ chip->ichd[ICHD_MDMOUT].substream = NULL;
817
+static int snd_intel8x0m_capture_open(snd_pcm_substream_t * substream)
819
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
821
+ return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMIN]);
824
+static int snd_intel8x0m_capture_close(snd_pcm_substream_t * substream)
826
+ intel8x0_t *chip = snd_pcm_substream_chip(substream);
828
+ chip->ichd[ICHD_MDMIN].substream = NULL;
833
+static snd_pcm_ops_t snd_intel8x0m_playback_ops = {
834
+ .open = snd_intel8x0m_playback_open,
835
+ .close = snd_intel8x0m_playback_close,
836
+ .ioctl = snd_pcm_lib_ioctl,
837
+ .hw_params = snd_intel8x0_hw_params,
838
+ .hw_free = snd_intel8x0_hw_free,
839
+ .prepare = snd_intel8x0m_pcm_prepare,
840
+ .trigger = snd_intel8x0m_pcm_trigger,
841
+ .pointer = snd_intel8x0_pcm_pointer,
844
+static snd_pcm_ops_t snd_intel8x0m_capture_ops = {
845
+ .open = snd_intel8x0m_capture_open,
846
+ .close = snd_intel8x0m_capture_close,
847
+ .ioctl = snd_pcm_lib_ioctl,
848
+ .hw_params = snd_intel8x0_hw_params,
849
+ .hw_free = snd_intel8x0_hw_free,
850
+ .prepare = snd_intel8x0m_pcm_prepare,
851
+ .trigger = snd_intel8x0m_pcm_trigger,
852
+ .pointer = snd_intel8x0_pcm_pointer,
856
+struct ich_pcm_table {
858
+ snd_pcm_ops_t *playback_ops;
859
+ snd_pcm_ops_t *capture_ops;
860
+ size_t prealloc_size;
861
+ size_t prealloc_max_size;
865
+static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_pcm_table *rec)
872
+ sprintf(name, "Intel ICH - %s", rec->suffix);
874
+ strcpy(name, "Intel ICH");
875
+ err = snd_pcm_new(chip->card, name, device,
876
+ rec->playback_ops ? 1 : 0,
877
+ rec->capture_ops ? 1 : 0, &pcm);
881
+ if (rec->playback_ops)
882
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
883
+ if (rec->capture_ops)
884
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
886
+ pcm->private_data = chip;
887
+ pcm->info_flags = 0;
889
+ sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
891
+ strcpy(pcm->name, chip->card->shortname);
892
+ chip->pcm[device] = pcm;
894
+ snd_pcm_lib_preallocate_pci_pages_for_all(chip->pci, pcm, rec->prealloc_size,
895
+ rec->prealloc_max_size);
900
+static struct ich_pcm_table intel_pcms[] __devinitdata = {
903
+ .playback_ops = &snd_intel8x0m_playback_ops,
904
+ .capture_ops = &snd_intel8x0m_capture_ops,
905
+ .prealloc_size = 4 * 1024,
906
+ .prealloc_max_size = 16 * 1024,
910
+static int __devinit snd_intel8x0_pcm(intel8x0_t *chip)
912
+ int i, tblsize, device, err;
913
+ struct ich_pcm_table *tbl, *rec;
919
+ switch (chip->device_type) {
920
+ case DEVICE_NFORCE:
922
+ tblsize = ARRAY_SIZE(nforce_pcms);
926
+ tblsize = ARRAY_SIZE(ali_pcms);
935
+ for (i = 0; i < tblsize; i++) {
937
+ if (i > 0 && rec->ac97_idx) {
938
+ /* activate PCM only when associated AC'97 codec */
939
+ if (! chip->ichd[rec->ac97_idx].ac97)
942
+ err = snd_intel8x0_pcm1(chip, device, rec);
948
+ chip->pcm_devs = device;
957
+static void snd_intel8x0_mixer_free_ac97(ac97_t *ac97)
959
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, ac97->private_data, return);
960
+ chip->ac97[ac97->num] = NULL;
964
+static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
969
+ unsigned int glob_sta = 0;
971
+ chip->in_ac97_init = 1;
972
+ memset(&ac97, 0, sizeof(ac97));
973
+ ac97.private_data = chip;
974
+ ac97.private_free = snd_intel8x0_mixer_free_ac97;
975
+ if (ac97_clock >= 8000 && ac97_clock <= 48000)
976
+ ac97.clock = ac97_clock;
978
+ ac97.clock = 48000;
980
+ glob_sta = igetdword(chip, ICHREG(GLOB_STA));
981
+ ac97.write = snd_intel8x0_codec_write;
982
+ ac97.read = snd_intel8x0_codec_read;
983
+ ac97.pci = chip->pci;
985
+ i = glob_sta & ICH_SCR ? 1 : 0;
987
+ if ((err = snd_ac97_modem(chip->card, &ac97, &x97)) < 0) {
988
+ snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
991
+ chip->ac97[i] = x97;
992
+ if(ac97_is_modem(x97)) {
993
+ chip->ichd[ICHD_MDMIN].ac97 = x97;
994
+ chip->ichd[ICHD_MDMOUT].ac97 = x97;
996
+ chip->in_ac97_init = 0;
1000
+ /* clear the cold-reset bit for the next chance */
1001
+ if (chip->device_type != DEVICE_ALI)
1002
+ iputdword(chip, ICHREG(GLOB_CNT), igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
1011
+#define do_delay(chip) do {\
1012
+ set_current_state(TASK_UNINTERRUPTIBLE);\
1013
+ schedule_timeout(1);\
1016
+static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
1018
+ unsigned long end_time;
1019
+ unsigned int cnt, status, nstatus;
1021
+ /* put logic to right state */
1022
+ /* first clear status bits */
1023
+ status = ICH_RCS | ICH_MIINT | ICH_MOINT;
1024
+ cnt = igetdword(chip, ICHREG(GLOB_STA));
1025
+ iputdword(chip, ICHREG(GLOB_STA), cnt & status);
1027
+ /* ACLink on, 2 channels */
1028
+ cnt = igetdword(chip, ICHREG(GLOB_CNT));
1029
+ cnt &= ~(ICH_ACLINK);
1030
+ /* finish cold or do warm reset */
1031
+ cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
1032
+ iputdword(chip, ICHREG(GLOB_CNT), cnt);
1033
+ end_time = (jiffies + (HZ / 4)) + 1;
1035
+ if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
1038
+ } while (time_after_eq(end_time, jiffies));
1039
+ snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
1044
+ /* wait for any codec ready status.
1045
+ * Once it becomes ready it should remain ready
1046
+ * as long as we do not disable the ac97 link.
1048
+ end_time = jiffies + HZ;
1050
+ status = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
1054
+ } while (time_after_eq(end_time, jiffies));
1056
+ /* no codec is found */
1057
+ snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", igetdword(chip, ICHREG(GLOB_STA)));
1061
+ /* up to two codecs (modem cannot be tertiary with ICH4) */
1062
+ nstatus = ICH_PCR | ICH_SCR;
1064
+ /* wait for other codecs ready status. */
1065
+ end_time = jiffies + HZ / 4;
1066
+ while (status != nstatus && time_after_eq(end_time, jiffies)) {
1068
+ status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
1072
+ /* resume phase */
1075
+ for (i = 0; i < 3; i++)
1076
+ if (chip->ac97[i])
1077
+ status |= get_ich_codec_bit(chip, i);
1078
+ /* wait until all the probed codecs are ready */
1079
+ end_time = jiffies + HZ;
1081
+ nstatus = igetdword(chip, ICHREG(GLOB_STA)) & (ICH_PCR | ICH_SCR | ICH_TCR);
1082
+ if (status == nstatus)
1085
+ } while (time_after_eq(end_time, jiffies));
1091
+static int snd_intel8x0_chip_init(intel8x0_t *chip, int probing)
1096
+ if ((err = snd_intel8x0m_ich_chip_init(chip, probing)) < 0)
1098
+ iagetword(chip, 0); /* clear semaphore flag */
1100
+ /* disable interrupts */
1101
+ for (i = 0; i < chip->bdbars_count; i++)
1102
+ iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
1103
+ /* reset channels */
1104
+ for (i = 0; i < chip->bdbars_count; i++)
1105
+ iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
1106
+ /* initialize Buffer Descriptor Lists */
1107
+ for (i = 0; i < chip->bdbars_count; i++)
1108
+ iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
1112
+static int snd_intel8x0_free(intel8x0_t *chip)
1116
+ if (chip->irq < 0)
1118
+ /* disable interrupts */
1119
+ for (i = 0; i < chip->bdbars_count; i++)
1120
+ iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
1121
+ /* reset channels */
1122
+ for (i = 0; i < chip->bdbars_count; i++)
1123
+ iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
1125
+ synchronize_irq(chip->irq);
1128
+ snd_free_pci_pages(chip->pci, chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, chip->bdbars, chip->bdbars_addr);
1129
+ if (chip->remap_addr)
1130
+ iounmap((void *) chip->remap_addr);
1131
+ if (chip->remap_bmaddr)
1132
+ iounmap((void *) chip->remap_bmaddr);
1134
+ release_resource(chip->res);
1135
+ kfree_nocheck(chip->res);
1137
+ if (chip->res_bm) {
1138
+ release_resource(chip->res_bm);
1139
+ kfree_nocheck(chip->res_bm);
1141
+ if (chip->irq >= 0)
1142
+ free_irq(chip->irq, (void *)chip);
1143
+ snd_magic_kfree(chip);
1149
+ * power management
1151
+static void intel8x0_suspend(intel8x0_t *chip)
1153
+ snd_card_t *card = chip->card;
1156
+ if (chip->in_suspend ||
1157
+ card->power_state == SNDRV_CTL_POWER_D3hot)
1160
+ chip->in_suspend = 1;
1161
+ for (i = 0; i < chip->pcm_devs; i++)
1162
+ snd_pcm_suspend_all(chip->pcm[i]);
1163
+ snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1166
+static void intel8x0_resume(intel8x0_t *chip)
1168
+ snd_card_t *card = chip->card;
1171
+ if (! chip->in_suspend ||
1172
+ card->power_state == SNDRV_CTL_POWER_D0)
1175
+ pci_enable_device(chip->pci);
1176
+ pci_set_master(chip->pci);
1177
+ snd_intel8x0_chip_init(chip, 0);
1178
+ for (i = 0; i < 3; i++)
1179
+ if (chip->ac97[i])
1180
+ snd_ac97_resume(chip->ac97[i]);
1182
+ chip->in_suspend = 0;
1183
+ snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1186
+static int snd_intel8x0m_suspend(struct pci_dev *dev, u32 state)
1188
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, pci_get_drvdata(dev), return -ENXIO);
1189
+ intel8x0_suspend(chip);
1192
+static int snd_intel8x0m_resume(struct pci_dev *dev)
1194
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, pci_get_drvdata(dev), return -ENXIO);
1195
+ intel8x0_resume(chip);
1200
+static int snd_intel8x0_set_power_state(snd_card_t *card, unsigned int power_state)
1202
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, card->power_state_private_data, return -ENXIO);
1203
+ switch (power_state) {
1204
+ case SNDRV_CTL_POWER_D0:
1205
+ case SNDRV_CTL_POWER_D1:
1206
+ case SNDRV_CTL_POWER_D2:
1207
+ intel8x0_resume(chip);
1209
+ case SNDRV_CTL_POWER_D3hot:
1210
+ case SNDRV_CTL_POWER_D3cold:
1211
+ intel8x0_suspend(chip);
1219
+#endif /* CONFIG_PM */
1221
+static void snd_intel8x0m_proc_read(snd_info_entry_t * entry,
1222
+ snd_info_buffer_t * buffer)
1224
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, entry->private_data, return);
1227
+ snd_iprintf(buffer, "Intel8x0m\n\n");
1228
+ if (chip->device_type == DEVICE_ALI)
1230
+ tmp = igetdword(chip, ICHREG(GLOB_STA));
1231
+ snd_iprintf(buffer, "Global control : 0x%08x\n", igetdword(chip, ICHREG(GLOB_CNT)));
1232
+ snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
1233
+ snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
1234
+ tmp & ICH_PCR ? " primary" : "",
1235
+ tmp & ICH_SCR ? " secondary" : "",
1236
+ tmp & ICH_TCR ? " tertiary" : "",
1237
+ (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
1240
+static void __devinit snd_intel8x0m_proc_init(intel8x0_t * chip)
1242
+ snd_info_entry_t *entry;
1244
+ if (! snd_card_proc_new(chip->card, "intel8x0m", &entry))
1245
+ snd_info_set_text_ops(entry, chip, snd_intel8x0m_proc_read);
1248
+static int snd_intel8x0_dev_free(snd_device_t *device)
1250
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, device->device_data, return -ENXIO);
1251
+ return snd_intel8x0_free(chip);
1254
+struct ich_reg_info {
1255
+ unsigned int int_sta_mask;
1256
+ unsigned int offset;
1259
+static int __devinit snd_intel8x0m_create(snd_card_t * card,
1260
+ struct pci_dev *pci,
1261
+ unsigned long device_type,
1262
+ intel8x0_t ** r_intel8x0)
1267
+ unsigned int int_sta_masks;
1269
+ static snd_device_ops_t ops = {
1270
+ .dev_free = snd_intel8x0_dev_free,
1272
+ static struct ich_reg_info intel_regs[2] = {
1274
+ { ICH_MOINT, 0x10 },
1276
+ struct ich_reg_info *tbl;
1278
+ *r_intel8x0 = NULL;
1280
+ if ((err = pci_enable_device(pci)) < 0)
1283
+ chip = snd_magic_kcalloc(intel8x0_t, 0, GFP_KERNEL);
1286
+ spin_lock_init(&chip->reg_lock);
1287
+ spin_lock_init(&chip->ac97_lock);
1288
+ chip->device_type = device_type;
1289
+ chip->card = card;
1292
+ snd_intel8x0m_proc_init(chip);
1293
+ sprintf(chip->ac97_name, "%s - AC'97", card->shortname);
1294
+ sprintf(chip->ctrl_name, "%s - Controller", card->shortname);
1295
+ if (device_type == DEVICE_ALI) {
1296
+ /* ALI5455 has no ac97 region */
1297
+ chip->bmaddr = pci_resource_start(pci, 0);
1298
+ if ((chip->res_bm = request_region(chip->bmaddr, 256, chip->ctrl_name)) == NULL) {
1299
+ snd_printk("unable to grab ports 0x%lx-0x%lx\n", chip->bmaddr, chip->bmaddr + 256 - 1);
1300
+ snd_intel8x0_free(chip);
1306
+ if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) { /* ICH4 and Nforce */
1308
+ chip->addr = pci_resource_start(pci, 2);
1309
+ if ((chip->res = request_mem_region(chip->addr, 512, chip->ac97_name)) == NULL) {
1310
+ snd_printk("unable to grab I/O memory 0x%lx-0x%lx\n", chip->addr, chip->addr + 512 - 1);
1311
+ snd_intel8x0_free(chip);
1314
+ chip->remap_addr = (unsigned long) ioremap_nocache(chip->addr, 512);
1315
+ if (chip->remap_addr == 0) {
1316
+ snd_printk("AC'97 space ioremap problem\n");
1317
+ snd_intel8x0_free(chip);
1321
+ chip->addr = pci_resource_start(pci, 0);
1322
+ if ((chip->res = request_region(chip->addr, 256, chip->ac97_name)) == NULL) {
1323
+ snd_printk("unable to grab ports 0x%lx-0x%lx\n", chip->addr, chip->addr + 256 - 1);
1324
+ snd_intel8x0_free(chip);
1328
+ if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) { /* ICH4 */
1329
+ chip->bm_mmio = 1;
1330
+ chip->bmaddr = pci_resource_start(pci, 3);
1331
+ if ((chip->res_bm = request_mem_region(chip->bmaddr, 256, chip->ctrl_name)) == NULL) {
1332
+ snd_printk("unable to grab I/O memory 0x%lx-0x%lx\n", chip->bmaddr, chip->bmaddr + 512 - 1);
1333
+ snd_intel8x0_free(chip);
1336
+ chip->remap_bmaddr = (unsigned long) ioremap_nocache(chip->bmaddr, 256);
1337
+ if (chip->remap_bmaddr == 0) {
1338
+ snd_printk("Controller space ioremap problem\n");
1339
+ snd_intel8x0_free(chip);
1343
+ chip->bmaddr = pci_resource_start(pci, 1);
1344
+ if ((chip->res_bm = request_region(chip->bmaddr, 128, chip->ctrl_name)) == NULL) {
1345
+ snd_printk("unable to grab ports 0x%lx-0x%lx\n", chip->bmaddr, chip->bmaddr + 128 - 1);
1346
+ snd_intel8x0_free(chip);
1352
+ if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1353
+ snd_printk("unable to grab IRQ %d\n", pci->irq);
1354
+ snd_intel8x0_free(chip);
1357
+ chip->irq = pci->irq;
1358
+ pci_set_master(pci);
1359
+ synchronize_irq(chip->irq);
1361
+ /* initialize offsets */
1362
+ chip->bdbars_count = 2;
1365
+ for (i = 0; i < chip->bdbars_count; i++) {
1366
+ ichdev = &chip->ichd[i];
1368
+ ichdev->reg_offset = tbl[i].offset;
1369
+ ichdev->int_sta_mask = tbl[i].int_sta_mask;
1370
+ if (device_type == DEVICE_SIS) {
1371
+ /* SiS 7013 swaps the registers */
1372
+ ichdev->roff_sr = ICH_REG_OFF_PICB;
1373
+ ichdev->roff_picb = ICH_REG_OFF_SR;
1375
+ ichdev->roff_sr = ICH_REG_OFF_SR;
1376
+ ichdev->roff_picb = ICH_REG_OFF_PICB;
1378
+ if (device_type == DEVICE_ALI)
1379
+ ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
1381
+ /* SIS7013 handles the pcm data in bytes, others are in words */
1382
+ chip->pcm_pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
1384
+ /* allocate buffer descriptor lists */
1385
+ /* the start of each lists must be aligned to 8 bytes */
1386
+ chip->bdbars = (u32 *)snd_malloc_pci_pages(pci, chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, &chip->bdbars_addr);
1387
+ if (chip->bdbars == NULL) {
1388
+ snd_intel8x0_free(chip);
1391
+ /* tables must be aligned to 8 bytes here, but the kernel pages
1392
+ are much bigger, so we don't care (on i386) */
1393
+ int_sta_masks = 0;
1394
+ for (i = 0; i < chip->bdbars_count; i++) {
1395
+ ichdev = &chip->ichd[i];
1396
+ ichdev->bdbar = chip->bdbars + (i * ICH_MAX_FRAGS * 2);
1397
+ ichdev->bdbar_addr = chip->bdbars_addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
1398
+ int_sta_masks |= ichdev->int_sta_mask;
1400
+ chip->int_sta_reg = ICH_REG_GLOB_STA;
1401
+ chip->int_sta_mask = int_sta_masks;
1403
+ if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
1404
+ snd_intel8x0_free(chip);
1409
+ card->set_power_state = snd_intel8x0_set_power_state;
1410
+ card->power_state_private_data = chip;
1413
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1414
+ snd_intel8x0_free(chip);
1418
+ *r_intel8x0 = chip;
1422
+static struct shortname_table {
1425
+} shortnames[] __devinitdata = {
1426
+ { PCI_DEVICE_ID_INTEL_82801_6, "Intel 82801AA-ICH" },
1427
+ { PCI_DEVICE_ID_INTEL_82901_6, "Intel 82901AB-ICH0" },
1428
+ { PCI_DEVICE_ID_INTEL_82801BA_6, "Intel 82801BA-ICH2" },
1429
+ { PCI_DEVICE_ID_INTEL_440MX_6, "Intel 440MX" },
1430
+ { PCI_DEVICE_ID_INTEL_ICH3_6, "Intel 82801CA-ICH3" },
1431
+ { PCI_DEVICE_ID_INTEL_ICH4_6, "Intel 82801DB-ICH4" },
1432
+ { PCI_DEVICE_ID_INTEL_ICH5_6, "Intel ICH5" },
1433
+ { 0x7446, "AMD AMD768" },
1435
+ { PCI_DEVICE_ID_SI_7013, "SiS SI7013" },
1436
+ { PCI_DEVICE_ID_NVIDIA_MCP_AUDIO, "NVidia nForce" },
1437
+ { PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia nForce2" },
1438
+ { PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO, "NVidia nForce3" },
1439
+ { 0x5455, "ALi M5455" },
1440
+ { 0x746d, "AMD AMD8111" },
1445
+static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1446
+ const struct pci_device_id *pci_id)
1452
+ struct shortname_table *name;
1454
+ if (dev >= SNDRV_CARDS)
1456
+ if (!enable[dev]) {
1461
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1465
+ switch (pci_id->driver_data) {
1466
+ case DEVICE_NFORCE:
1467
+ strcpy(card->driver, "NFORCE");
1470
+ strcpy(card->driver, "ICH");
1474
+ strcpy(card->shortname, "Intel ICH");
1475
+ for (name = shortnames; name->id; name++) {
1476
+ if (pci->device == name->id) {
1477
+ strcpy(card->shortname, name->s);
1481
+ strcat(card->shortname," Modem");
1483
+ if ((err = snd_intel8x0m_create(card, pci, pci_id->driver_data, &chip)) < 0) {
1484
+ snd_card_free(card);
1488
+ if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev])) < 0) {
1489
+ snd_card_free(card);
1492
+ if ((err = snd_intel8x0_pcm(chip)) < 0) {
1493
+ snd_card_free(card);
1497
+ sprintf(card->longname, "%s at 0x%lx, irq %i",
1498
+ card->shortname, chip->addr, chip->irq);
1500
+ if ((err = snd_card_register(card)) < 0) {
1501
+ snd_card_free(card);
1504
+ pci_set_drvdata(pci, chip);
1509
+static void __devexit snd_intel8x0m_remove(struct pci_dev *pci)
1511
+ intel8x0_t *chip = snd_magic_cast(intel8x0_t, pci_get_drvdata(pci), return);
1513
+ snd_card_free(chip->card);
1514
+ pci_set_drvdata(pci, NULL);
1517
+static struct pci_driver driver = {
1518
+ .name = "Intel ICH Modem",
1519
+ .id_table = snd_intel8x0m_ids,
1520
+ .probe = snd_intel8x0m_probe,
1521
+ .remove = __devexit_p(snd_intel8x0m_remove),
1523
+ .suspend = snd_intel8x0m_suspend,
1524
+ .resume = snd_intel8x0m_resume,
1529
+static int __init alsa_card_intel8x0m_init(void)
1533
+ if ((err = pci_module_init(&driver)) < 0) {
1535
+ printk(KERN_ERR "Intel ICH modemcard not found or device busy\n");
1543
+static void __exit alsa_card_intel8x0m_exit(void)
1545
+ pci_unregister_driver(&driver);
1548
+module_init(alsa_card_intel8x0m_init)
1549
+module_exit(alsa_card_intel8x0m_exit)
1553
+/* format is: snd-intel8x0=enable,index,id,ac97_clock,mpu_port,joystick */
1555
+static int __init alsa_card_intel8x0m_setup(char *str)
1557
+ static unsigned __initdata nr_dev = 0;
1559
+ if (nr_dev >= SNDRV_CARDS)
1561
+ (void)(get_option(&str,&enable[nr_dev]) == 2 &&
1562
+ get_option(&str,&index[nr_dev]) == 2 &&
1563
+ get_id(&str,&id[nr_dev]) == 2 &&
1564
+ get_option(&str,&ac97_clock[nr_dev]) == 2
1570
+__setup("snd-intel8x0m=", alsa_card_intel8x0m_setup);
1572
+#endif /* ifndef MODULE */
1573
diff -Nru linux-2.6.0_orig/sound/pci/Kconfig linux-2.6.0/sound/pci/Kconfig
1574
--- linux-2.6.0_orig/sound/pci/Kconfig 2003-12-28 22:18:44.000000000 +0200
1575
+++ linux-2.6.0/sound/pci/Kconfig 2003-12-28 22:29:43.000000000 +0200
1576
@@ -172,6 +172,13 @@
1577
Say 'Y' or 'M' to include support for Intel8x0 based soundcards,
1578
SiS 7012, AMD768/8111, NVidia NForce and ALi 5455 chips.
1580
+config SND_INTEL8X0M
1581
+ tristate "Intel i8x0/MX440; AMD768/8111 modems (EXPERIMENTAL)"
1582
+ depends on SND && EXPERIMENTAL
1584
+ Say 'Y' or 'M' to include support for Intel8x0 and AMD768/8111 based
1587
config SND_SONICVIBES
1588
tristate "S3 SonicVibes"
1590
diff -Nru linux-2.6.0_orig/sound/pci/Makefile linux-2.6.0/sound/pci/Makefile
1591
--- linux-2.6.0_orig/sound/pci/Makefile 2003-12-28 22:18:44.000000000 +0200
1592
+++ linux-2.6.0/sound/pci/Makefile 2003-12-28 22:29:43.000000000 +0200
1594
snd-es1968-objs := es1968.o
1595
snd-fm801-objs := fm801.o
1596
snd-intel8x0-objs := intel8x0.o
1597
+snd-intel8x0m-objs := intel8x0m.o
1598
snd-maestro3-objs := maestro3.o
1599
snd-rme32-objs := rme32.o
1600
snd-rme96-objs := rme96.o
1602
obj-$(CONFIG_SND_ES1968) += snd-es1968.o
1603
obj-$(CONFIG_SND_FM801) += snd-fm801.o
1604
obj-$(CONFIG_SND_INTEL8X0) += snd-intel8x0.o
1605
+obj-$(CONFIG_SND_INTEL8X0M) += snd-intel8x0m.o
1606
obj-$(CONFIG_SND_MAESTRO3) += snd-maestro3.o
1607
obj-$(CONFIG_SND_RME32) += snd-rme32.o
1608
obj-$(CONFIG_SND_RME96) += snd-rme96.o