30 #include <linux/pci.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
41 "SiS 7013; NVidia MCP/2/2S/3 modems");
44 "{Intel,82901AB-ICH0},"
45 "{Intel,82801BA-ICH2},"
46 "{Intel,82801CA-ICH3},"
47 "{Intel,82801DB-ICH4},"
53 "{NVidia,NForce Modem},"
54 "{NVidia,NForce2 Modem},"
55 "{NVidia,NForce2s Modem},"
56 "{NVidia,NForce3 Modem},"
59 static int index = -2;
61 static int ac97_clock;
79 #define ICHREG(x) ICH_REG_##x
81 #define DEFINE_REGSET(name,base) \
83 ICH_REG_##name##_BDBAR = base + 0x0, \
84 ICH_REG_##name##_CIV = base + 0x04, \
85 ICH_REG_##name##_LVI = base + 0x05, \
86 ICH_REG_##name##_SR = base + 0x06, \
87 ICH_REG_##name##_PICB = base + 0x08, \
88 ICH_REG_##name##_PIV = base + 0x0a, \
89 ICH_REG_##name##_CR = base + 0x0b, \
98 #define ICH_REG_LVI_MASK 0x1f
101 #define ICH_FIFOE 0x10
102 #define ICH_BCIS 0x08
103 #define ICH_LVBCI 0x04
104 #define ICH_CELV 0x02
108 #define ICH_REG_PIV_MASK 0x1f
111 #define ICH_IOCE 0x10
112 #define ICH_FEIE 0x08
113 #define ICH_LVBIE 0x04
114 #define ICH_RESETREGS 0x02
115 #define ICH_STARTBM 0x01
119 #define ICH_REG_GLOB_CNT 0x3c
120 #define ICH_TRIE 0x00000040
121 #define ICH_SRIE 0x00000020
122 #define ICH_PRIE 0x00000010
123 #define ICH_ACLINK 0x00000008
124 #define ICH_AC97WARM 0x00000004
125 #define ICH_AC97COLD 0x00000002
126 #define ICH_GIE 0x00000001
127 #define ICH_REG_GLOB_STA 0x40
128 #define ICH_TRI 0x20000000
129 #define ICH_TCR 0x10000000
130 #define ICH_BCS 0x08000000
131 #define ICH_SPINT 0x04000000
132 #define ICH_P2INT 0x02000000
133 #define ICH_M2INT 0x01000000
134 #define ICH_SAMPLE_CAP 0x00c00000
135 #define ICH_MULTICHAN_CAP 0x00300000
136 #define ICH_MD3 0x00020000
137 #define ICH_AD3 0x00010000
138 #define ICH_RCS 0x00008000
139 #define ICH_BIT3 0x00004000
140 #define ICH_BIT2 0x00002000
141 #define ICH_BIT1 0x00001000
142 #define ICH_SRI 0x00000800
143 #define ICH_PRI 0x00000400
144 #define ICH_SCR 0x00000200
145 #define ICH_PCR 0x00000100
146 #define ICH_MCINT 0x00000080
147 #define ICH_POINT 0x00000040
148 #define ICH_PIINT 0x00000020
149 #define ICH_NVSPINT 0x00000010
150 #define ICH_MOINT 0x00000004
151 #define ICH_MIINT 0x00000002
152 #define ICH_GSCI 0x00000001
153 #define ICH_REG_ACC_SEMA 0x44
156 #define ICH_MAX_FRAGS 32
166 #define get_ichdev(substream) (substream->runtime->private_data)
306 static unsigned int codec_bit[3] = {
311 return codec_bit[
codec];
314 static int snd_intel8x0m_codec_semaphore(
struct intel8x0m *chip,
unsigned int codec)
320 codec = get_ich_codec_bit(chip, codec);
323 if ((igetdword(chip,
ICHREG(GLOB_STA)) & codec) == 0)
338 igetbyte(chip,
ICHREG(ACC_SEMA)), igetdword(chip,
ICHREG(GLOB_STA)));
344 static void snd_intel8x0m_codec_write(
struct snd_ac97 *ac97,
350 if (snd_intel8x0m_codec_semaphore(chip, ac97->
num) < 0) {
354 iaputword(chip, reg + ac97->
num * 0x80, val);
357 static unsigned short snd_intel8x0m_codec_read(
struct snd_ac97 *ac97,
364 if (snd_intel8x0m_codec_semaphore(chip, ac97->
num) < 0) {
369 res = iagetword(chip, reg + ac97->
num * 0x80);
372 iputdword(chip,
ICHREG(GLOB_STA),
394 iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->
bdbar_addr);
423 iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
428 "period_size1 = 0x%x\n",
440 static inline void snd_intel8x0m_update(
struct intel8x0m *chip,
struct ichdev *ichdev)
446 civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
447 if (civ == ichdev->
civ) {
453 step = civ - ichdev->
civ;
465 iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->
lvi);
466 for (i = 0; i <
step; i++) {
474 "prefetch = %i, all = 0x%x, 0x%x\n",
476 ichdev->
bdbar[ichdev->
lvi * 2 + 1],
inb(ICH_REG_OFF_PIV + port),
477 inl(port + 4),
inb(port + ICH_REG_OFF_CR));
479 if (--ichdev->
ack == 0) {
495 struct ichdev *ichdev;
501 if (status == 0xffffffff) {
513 ichdev = &chip->
ichd[
i];
515 snd_intel8x0m_update(chip, ichdev);
532 struct ichdev *ichdev =
get_ichdev(substream);
533 unsigned char val = 0;
554 iputbyte(chip, port + ICH_REG_OFF_CR, val);
578 struct ichdev *ichdev =
get_ichdev(substream);
587 if (ptr >= ichdev->
size)
589 return bytes_to_frames(substream->
runtime, ptr);
596 struct ichdev *ichdev =
get_ichdev(substream);
599 ichdev->
size = snd_pcm_lib_buffer_bytes(substream);
600 ichdev->
fragsize = snd_pcm_lib_period_bytes(substream);
603 snd_intel8x0m_setup_periods(chip, ichdev);
629 static int snd_intel8x0m_pcm_open(
struct snd_pcm_substream *substream,
struct ichdev *ichdev)
631 static unsigned int rates[] = { 8000, 9600, 12000, 16000 };
641 runtime->
hw = snd_intel8x0m_stream;
643 &hw_constraints_rates);
669 return snd_intel8x0m_pcm_open(substream, &chip->
ichd[
ICHD_MDMIN]);
681 static struct snd_pcm_ops snd_intel8x0m_playback_ops = {
682 .open = snd_intel8x0m_playback_open,
683 .close = snd_intel8x0m_playback_close,
685 .hw_params = snd_intel8x0m_hw_params,
686 .hw_free = snd_intel8x0m_hw_free,
687 .prepare = snd_intel8x0m_pcm_prepare,
688 .trigger = snd_intel8x0m_pcm_trigger,
689 .pointer = snd_intel8x0m_pcm_pointer,
692 static struct snd_pcm_ops snd_intel8x0m_capture_ops = {
693 .open = snd_intel8x0m_capture_open,
694 .close = snd_intel8x0m_capture_close,
696 .hw_params = snd_intel8x0m_hw_params,
697 .hw_free = snd_intel8x0m_hw_free,
698 .prepare = snd_intel8x0m_pcm_prepare,
699 .trigger = snd_intel8x0m_pcm_trigger,
700 .pointer = snd_intel8x0m_pcm_pointer,
723 strcpy(name,
"Intel ICH");
755 .playback_ops = &snd_intel8x0m_playback_ops,
756 .capture_ops = &snd_intel8x0m_capture_ops,
757 .prealloc_size = 32 * 1024,
758 .prealloc_max_size = 64 * 1024,
764 int i, tblsize, device,
err;
787 for (i = 0; i < tblsize; i++) {
794 err = snd_intel8x0m_pcm1(chip, device, rec);
809 static void snd_intel8x0m_mixer_free_ac97_bus(
struct snd_ac97_bus *
bus)
815 static void snd_intel8x0m_mixer_free_ac97(
struct snd_ac97 *ac97)
828 unsigned int glob_sta = 0;
830 .write = snd_intel8x0m_codec_write,
831 .read = snd_intel8x0m_codec_read,
836 memset(&ac97, 0,
sizeof(ac97));
841 glob_sta = igetdword(chip,
ICHREG(GLOB_STA));
846 if (ac97_clock >= 8000 && ac97_clock <= 48000)
847 pbus->
clock = ac97_clock;
870 iputdword(chip,
ICHREG(GLOB_CNT),
880 static int snd_intel8x0m_ich_chip_init(
struct intel8x0m *chip,
int probing)
882 unsigned long end_time;
888 cnt = igetdword(chip,
ICHREG(GLOB_STA));
889 iputdword(chip,
ICHREG(GLOB_STA), cnt & status);
892 cnt = igetdword(chip,
ICHREG(GLOB_CNT));
896 iputdword(chip,
ICHREG(GLOB_CNT), cnt);
905 igetdword(chip,
ICHREG(GLOB_CNT)));
916 status = igetdword(chip,
ICHREG(GLOB_STA)) &
925 igetdword(chip,
ICHREG(GLOB_STA)));
934 while (status != nstatus &&
time_after_eq(end_time, jiffies)) {
936 status |= igetdword(chip,
ICHREG(GLOB_STA)) & nstatus;
943 status |= get_ich_codec_bit(chip, chip->
ac97->num);
947 nstatus = igetdword(chip,
ICHREG(GLOB_STA)) &
949 if (status == nstatus)
957 iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
963 static int snd_intel8x0m_chip_init(
struct intel8x0m *chip,
int probing)
968 if ((err = snd_intel8x0m_ich_chip_init(chip, probing)) < 0)
974 iputbyte(chip, ICH_REG_OFF_CR + chip->
ichd[i].reg_offset, 0x00);
980 iputdword(chip, ICH_REG_OFF_BDBAR + chip->
ichd[i].reg_offset, chip->
ichd[i].bdbar_addr);
984 static int snd_intel8x0m_free(
struct intel8x0m *chip)
992 iputbyte(chip, ICH_REG_OFF_CR + chip->
ichd[i].reg_offset, 0x00);
1011 #ifdef CONFIG_PM_SLEEP
1015 static int intel8x0m_suspend(
struct device *
dev)
1023 for (i = 0; i < chip->
pcm_devs; i++)
1024 snd_pcm_suspend_all(chip->
pcm[i]);
1025 snd_ac97_suspend(chip->
ac97);
1026 if (chip->
irq >= 0) {
1036 static int intel8x0m_resume(
struct device *dev)
1046 "disabling device\n");
1054 "disabling device\n", pci->
irq);
1059 snd_intel8x0m_chip_init(chip, 0);
1060 snd_ac97_resume(chip->
ac97);
1067 #define INTEL8X0M_PM_OPS &intel8x0m_pm
1069 #define INTEL8X0M_PM_OPS NULL
1072 #ifdef CONFIG_PROC_FS
1079 snd_iprintf(buffer,
"Intel8x0m\n\n");
1082 tmp = igetdword(chip,
ICHREG(GLOB_STA));
1083 snd_iprintf(buffer,
"Global control : 0x%08x\n",
1084 igetdword(chip,
ICHREG(GLOB_CNT)));
1085 snd_iprintf(buffer,
"Global status : 0x%08x\n", tmp);
1086 snd_iprintf(buffer,
"AC'97 codecs ready :%s%s%s%s\n",
1087 tmp &
ICH_PCR ?
" primary" :
"",
1088 tmp &
ICH_SCR ?
" secondary" :
"",
1089 tmp &
ICH_TCR ?
" tertiary" :
"",
1090 (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ?
" none" :
"");
1097 if (! snd_card_proc_new(chip->
card,
"intel8x0m", &entry))
1098 snd_info_set_text_ops(entry, chip, snd_intel8x0m_proc_read);
1101 #define snd_intel8x0m_proc_init(chip)
1105 static int snd_intel8x0m_dev_free(
struct snd_device *device)
1108 return snd_intel8x0m_free(chip);
1124 unsigned int int_sta_masks;
1125 struct ichdev *ichdev;
1127 .dev_free = snd_intel8x0m_dev_free,
1135 *r_intel8x0m =
NULL;
1159 chip->
bmaddr = pci_iomap(pci, 0, 0);
1164 chip->
addr = pci_iomap(pci, 2, 0);
1166 chip->
addr = pci_iomap(pci, 0, 0);
1169 snd_intel8x0m_free(chip);
1173 chip->
bmaddr = pci_iomap(pci, 3, 0);
1175 chip->
bmaddr = pci_iomap(pci, 1, 0);
1178 snd_intel8x0m_free(chip);
1184 KBUILD_MODNAME, chip)) {
1186 snd_intel8x0m_free(chip);
1198 ichdev = &chip->
ichd[
i];
1204 ichdev->
roff_sr = ICH_REG_OFF_PICB;
1207 ichdev->
roff_sr = ICH_REG_OFF_SR;
1221 snd_intel8x0m_free(chip);
1228 ichdev = &chip->
ichd[
i];
1236 if ((err = snd_intel8x0m_chip_init(chip, 1)) < 0) {
1237 snd_intel8x0m_free(chip);
1242 snd_intel8x0m_free(chip);
1248 *r_intel8x0m =
chip;
1252 static struct shortname_table {
1255 } shortnames[] __devinitdata = {
1265 { 0x7446,
"AMD AMD768" },
1271 { 0x746e,
"AMD AMD8111" },
1273 { 0x5455,
"ALi M5455" },
1284 struct shortname_table *
name;
1292 for (name = shortnames; name->id; name++) {
1293 if (pci->
device == name->id) {
1300 if ((err = snd_intel8x0m_create(card, pci, pci_id->
driver_data, &chip)) < 0) {
1306 if ((err = snd_intel8x0m_mixer(chip, ac97_clock)) < 0) {
1310 if ((err = snd_intel8x0m_pcm(chip)) < 0) {
1324 pci_set_drvdata(pci, card);
1331 pci_set_drvdata(pci,
NULL);
1334 static struct pci_driver intel8x0m_driver = {
1335 .name = KBUILD_MODNAME,
1336 .id_table = snd_intel8x0m_ids,
1337 .probe = snd_intel8x0m_probe,