26 #include <linux/pci.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
42 static int index = -2;
44 static int ac97_clock = 48000;
61 #define ATI_REG_ISR 0x00
62 #define ATI_REG_ISR_MODEM_IN_XRUN (1U<<0)
63 #define ATI_REG_ISR_MODEM_IN_STATUS (1U<<1)
64 #define ATI_REG_ISR_MODEM_OUT1_XRUN (1U<<2)
65 #define ATI_REG_ISR_MODEM_OUT1_STATUS (1U<<3)
66 #define ATI_REG_ISR_MODEM_OUT2_XRUN (1U<<4)
67 #define ATI_REG_ISR_MODEM_OUT2_STATUS (1U<<5)
68 #define ATI_REG_ISR_MODEM_OUT3_XRUN (1U<<6)
69 #define ATI_REG_ISR_MODEM_OUT3_STATUS (1U<<7)
70 #define ATI_REG_ISR_PHYS_INTR (1U<<8)
71 #define ATI_REG_ISR_PHYS_MISMATCH (1U<<9)
72 #define ATI_REG_ISR_CODEC0_NOT_READY (1U<<10)
73 #define ATI_REG_ISR_CODEC1_NOT_READY (1U<<11)
74 #define ATI_REG_ISR_CODEC2_NOT_READY (1U<<12)
75 #define ATI_REG_ISR_NEW_FRAME (1U<<13)
76 #define ATI_REG_ISR_MODEM_GPIO_DATA (1U<<14)
78 #define ATI_REG_IER 0x04
79 #define ATI_REG_IER_MODEM_IN_XRUN_EN (1U<<0)
80 #define ATI_REG_IER_MODEM_STATUS_EN (1U<<1)
81 #define ATI_REG_IER_MODEM_OUT1_XRUN_EN (1U<<2)
82 #define ATI_REG_IER_MODEM_OUT2_XRUN_EN (1U<<4)
83 #define ATI_REG_IER_MODEM_OUT3_XRUN_EN (1U<<6)
84 #define ATI_REG_IER_PHYS_INTR_EN (1U<<8)
85 #define ATI_REG_IER_PHYS_MISMATCH_EN (1U<<9)
86 #define ATI_REG_IER_CODEC0_INTR_EN (1U<<10)
87 #define ATI_REG_IER_CODEC1_INTR_EN (1U<<11)
88 #define ATI_REG_IER_CODEC2_INTR_EN (1U<<12)
89 #define ATI_REG_IER_NEW_FRAME_EN (1U<<13)
90 #define ATI_REG_IER_MODEM_GPIO_DATA_EN (1U<<14)
91 #define ATI_REG_IER_MODEM_SET_BUS_BUSY (1U<<15)
93 #define ATI_REG_CMD 0x08
94 #define ATI_REG_CMD_POWERDOWN (1U<<0)
95 #define ATI_REG_CMD_MODEM_RECEIVE_EN (1U<<1)
96 #define ATI_REG_CMD_MODEM_SEND1_EN (1U<<2)
97 #define ATI_REG_CMD_MODEM_SEND2_EN (1U<<3)
98 #define ATI_REG_CMD_MODEM_SEND3_EN (1U<<4)
99 #define ATI_REG_CMD_MODEM_STATUS_MEM (1U<<5)
100 #define ATI_REG_CMD_MODEM_IN_DMA_EN (1U<<8)
101 #define ATI_REG_CMD_MODEM_OUT_DMA1_EN (1U<<9)
102 #define ATI_REG_CMD_MODEM_OUT_DMA2_EN (1U<<10)
103 #define ATI_REG_CMD_MODEM_OUT_DMA3_EN (1U<<11)
104 #define ATI_REG_CMD_AUDIO_PRESENT (1U<<20)
105 #define ATI_REG_CMD_MODEM_GPIO_THRU_DMA (1U<<22)
106 #define ATI_REG_CMD_LOOPBACK_EN (1U<<23)
107 #define ATI_REG_CMD_PACKED_DIS (1U<<24)
108 #define ATI_REG_CMD_BURST_EN (1U<<25)
109 #define ATI_REG_CMD_PANIC_EN (1U<<26)
110 #define ATI_REG_CMD_MODEM_PRESENT (1U<<27)
111 #define ATI_REG_CMD_ACLINK_ACTIVE (1U<<28)
112 #define ATI_REG_CMD_AC_SOFT_RESET (1U<<29)
113 #define ATI_REG_CMD_AC_SYNC (1U<<30)
114 #define ATI_REG_CMD_AC_RESET (1U<<31)
116 #define ATI_REG_PHYS_OUT_ADDR 0x0c
117 #define ATI_REG_PHYS_OUT_CODEC_MASK (3U<<0)
118 #define ATI_REG_PHYS_OUT_RW (1U<<2)
119 #define ATI_REG_PHYS_OUT_ADDR_EN (1U<<8)
120 #define ATI_REG_PHYS_OUT_ADDR_SHIFT 9
121 #define ATI_REG_PHYS_OUT_DATA_SHIFT 16
123 #define ATI_REG_PHYS_IN_ADDR 0x10
124 #define ATI_REG_PHYS_IN_READ_FLAG (1U<<8)
125 #define ATI_REG_PHYS_IN_ADDR_SHIFT 9
126 #define ATI_REG_PHYS_IN_DATA_SHIFT 16
128 #define ATI_REG_SLOTREQ 0x14
130 #define ATI_REG_COUNTER 0x18
131 #define ATI_REG_COUNTER_SLOT (3U<<0)
132 #define ATI_REG_COUNTER_BITCLOCK (31U<<8)
134 #define ATI_REG_IN_FIFO_THRESHOLD 0x1c
136 #define ATI_REG_MODEM_IN_DMA_LINKPTR 0x20
137 #define ATI_REG_MODEM_IN_DMA_DT_START 0x24
138 #define ATI_REG_MODEM_IN_DMA_DT_NEXT 0x28
139 #define ATI_REG_MODEM_IN_DMA_DT_CUR 0x2c
140 #define ATI_REG_MODEM_IN_DMA_DT_SIZE 0x30
141 #define ATI_REG_MODEM_OUT_FIFO 0x34
142 #define ATI_REG_MODEM_OUT1_DMA_THRESHOLD_MASK (0xf<<16)
143 #define ATI_REG_MODEM_OUT1_DMA_THRESHOLD_SHIFT 16
144 #define ATI_REG_MODEM_OUT_DMA1_LINKPTR 0x38
145 #define ATI_REG_MODEM_OUT_DMA2_LINKPTR 0x3c
146 #define ATI_REG_MODEM_OUT_DMA3_LINKPTR 0x40
147 #define ATI_REG_MODEM_OUT_DMA1_DT_START 0x44
148 #define ATI_REG_MODEM_OUT_DMA1_DT_NEXT 0x48
149 #define ATI_REG_MODEM_OUT_DMA1_DT_CUR 0x4c
150 #define ATI_REG_MODEM_OUT_DMA2_DT_START 0x50
151 #define ATI_REG_MODEM_OUT_DMA2_DT_NEXT 0x54
152 #define ATI_REG_MODEM_OUT_DMA2_DT_CUR 0x58
153 #define ATI_REG_MODEM_OUT_DMA3_DT_START 0x5c
154 #define ATI_REG_MODEM_OUT_DMA3_DT_NEXT 0x60
155 #define ATI_REG_MODEM_OUT_DMA3_DT_CUR 0x64
156 #define ATI_REG_MODEM_OUT_DMA12_DT_SIZE 0x68
157 #define ATI_REG_MODEM_OUT_DMA3_DT_SIZE 0x6c
158 #define ATI_REG_MODEM_OUT_FIFO_USED 0x70
159 #define ATI_REG_MODEM_OUT_GPIO 0x74
160 #define ATI_REG_MODEM_OUT_GPIO_EN 1
161 #define ATI_REG_MODEM_OUT_GPIO_DATA_SHIFT 5
162 #define ATI_REG_MODEM_IN_GPIO 0x78
164 #define ATI_REG_MODEM_MIRROR 0x7c
165 #define ATI_REG_AUDIO_MIRROR 0x80
167 #define ATI_REG_MODEM_FIFO_FLUSH 0x88
168 #define ATI_REG_MODEM_FIFO_OUT1_FLUSH (1U<<0)
169 #define ATI_REG_MODEM_FIFO_OUT2_FLUSH (1U<<1)
170 #define ATI_REG_MODEM_FIFO_OUT3_FLUSH (1U<<2)
171 #define ATI_REG_MODEM_FIFO_IN_FLUSH (1U<<3)
174 #define ATI_REG_LINKPTR_EN (1U<<0)
176 #define ATI_MAX_DESCRIPTORS 256
199 #define NUM_ATI_CODECS 3
285 unsigned int data, old_data;
286 old_data = data =
readl(addr);
289 if (old_data == data)
298 #define atiixp_write(chip,reg,value) \
299 writel(value, chip->remap_addr + ATI_REG_##reg)
300 #define atiixp_read(chip,reg) \
301 readl(chip->remap_addr + ATI_REG_##reg)
302 #define atiixp_update(chip,reg,mask,val) \
303 snd_atiixp_update_bits(chip, ATI_REG_##reg, mask, val)
312 #define ATI_DESC_LIST_SIZE \
313 PAGE_ALIGN(ATI_MAX_DESCRIPTORS * sizeof(struct atiixp_dma_desc))
324 static int atiixp_build_dma_packets(
struct atiixp_modem *chip,
327 unsigned int periods,
328 unsigned int period_bytes)
350 dma->
ops->enable_dma(chip, 0);
351 dma->
ops->enable_dma(chip, 1);
352 spin_unlock_irqrestore(&chip->
reg_lock, flags);
357 for (i = 0; i < periods; i++) {
362 desc->
size = period_bytes >> 2;
364 if (i == periods - 1)
368 addr += period_bytes;
383 static void atiixp_clear_dma_packets(
struct atiixp_modem *chip,
397 static int snd_atiixp_acquire_codec(
struct atiixp_modem *chip)
411 static unsigned short snd_atiixp_codec_read(
struct atiixp_modem *chip,
412 unsigned short codec,
418 if (snd_atiixp_acquire_codec(chip) < 0)
421 ATI_REG_PHYS_OUT_ADDR_EN |
425 if (snd_atiixp_acquire_codec(chip) < 0)
441 static void snd_atiixp_codec_write(
struct atiixp_modem *chip,
442 unsigned short codec,
443 unsigned short reg,
unsigned short val)
447 if (snd_atiixp_acquire_codec(chip) < 0)
451 ATI_REG_PHYS_OUT_ADDR_EN |
codec;
456 static unsigned short snd_atiixp_ac97_read(
struct snd_ac97 *ac97,
460 return snd_atiixp_codec_read(chip, ac97->
num, reg);
464 static void snd_atiixp_ac97_write(
struct snd_ac97 *
ac97,
unsigned short reg,
473 snd_atiixp_codec_write(chip, ac97->
num, reg, val);
479 static int snd_atiixp_aclink_reset(
struct atiixp_modem *chip)
514 #ifdef CONFIG_PM_SLEEP
515 static int snd_atiixp_aclink_down(
struct atiixp_modem *chip)
534 #define ALL_CODEC_NOT_READY \
535 (ATI_REG_ISR_CODEC0_NOT_READY |\
536 ATI_REG_ISR_CODEC1_NOT_READY |\
537 ATI_REG_ISR_CODEC2_NOT_READY)
538 #define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME)
540 static int snd_atiixp_codec_detect(
struct atiixp_modem *chip)
548 while (timeout-- > 0) {
566 static int snd_atiixp_chip_start(
struct atiixp_modem *chip)
591 static int snd_atiixp_chip_stop(
struct atiixp_modem *chip)
625 return bytes_to_frames(runtime, curptr);
627 snd_printd(
"atiixp-modem: invalid DMA pointer read 0x%x (buf=%x)\n",
635 static void snd_atiixp_xrun_dma(
struct atiixp_modem *chip,
640 snd_printdd(
"atiixp-modem: XRUN detected (DMA %d)\n", dma->
ops->type);
647 static void snd_atiixp_update_dma(
struct atiixp_modem *chip,
657 static void snd_atiixp_check_bus_busy(
struct atiixp_modem *chip)
659 unsigned int bus_busy;
678 !dma->
ops->flush_dma))
684 dma->
ops->enable_transfer(chip, 1);
688 dma->
ops->enable_transfer(chip, 0);
696 snd_atiixp_check_bus_busy(chip);
698 dma->
ops->flush_dma(chip);
699 snd_atiixp_check_bus_busy(chip);
714 static void atiixp_out_flush_dma(
struct atiixp_modem *chip)
720 static void atiixp_out_enable_dma(
struct atiixp_modem *chip,
int on)
727 atiixp_out_flush_dma(chip);
735 static void atiixp_out_enable_transfer(
struct atiixp_modem *chip,
int on)
742 static void atiixp_in_enable_dma(
struct atiixp_modem *chip,
int on)
749 static void atiixp_in_enable_transfer(
struct atiixp_modem *chip,
int on)
762 static void atiixp_in_flush_dma(
struct atiixp_modem *chip)
806 err = atiixp_build_dma_packets(chip, dma, substream,
808 params_period_bytes(hw_params));
828 atiixp_clear_dma_packets(chip, dma, substream);
850 .buffer_bytes_max = 256 * 1024,
851 .period_bytes_min = 32,
852 .period_bytes_max = 128 * 1024,
863 static unsigned int rates[] = { 8000, 9600, 12000, 16000 };
876 runtime->
hw = snd_atiixp_pcm_hw;
880 &hw_constraints_rates)) < 0)
889 dma->
ops->enable_dma(chip, 1);
904 dma->
ops->enable_dma(chip, 0);
950 static struct snd_pcm_ops snd_atiixp_playback_ops = {
951 .open = snd_atiixp_playback_open,
952 .close = snd_atiixp_playback_close,
954 .hw_params = snd_atiixp_pcm_hw_params,
955 .hw_free = snd_atiixp_pcm_hw_free,
956 .prepare = snd_atiixp_playback_prepare,
957 .trigger = snd_atiixp_pcm_trigger,
958 .pointer = snd_atiixp_pcm_pointer,
962 static struct snd_pcm_ops snd_atiixp_capture_ops = {
963 .open = snd_atiixp_capture_open,
964 .close = snd_atiixp_capture_close,
966 .hw_params = snd_atiixp_pcm_hw_params,
967 .hw_free = snd_atiixp_pcm_hw_free,
968 .prepare = snd_atiixp_capture_prepare,
969 .trigger = snd_atiixp_pcm_trigger,
970 .pointer = snd_atiixp_pcm_pointer,
977 .enable_dma = atiixp_out_enable_dma,
978 .enable_transfer = atiixp_out_enable_transfer,
979 .flush_dma = atiixp_out_flush_dma,
986 .enable_dma = atiixp_in_enable_dma,
987 .enable_transfer = atiixp_in_enable_transfer,
988 .flush_dma = atiixp_in_flush_dma,
1045 unsigned int detected;
1071 .write = snd_atiixp_ac97_write,
1072 .read = snd_atiixp_ac97_read,
1080 if (snd_atiixp_codec_detect(chip) < 0)
1092 memset(&ac97, 0,
sizeof(ac97));
1099 snd_printdd(
"atiixp-modem: codec %d not available for modem\n", i);
1105 if (! codec_count) {
1116 #ifdef CONFIG_PM_SLEEP
1120 static int snd_atiixp_suspend(
struct device *
dev)
1129 snd_pcm_suspend_all(chip->
pcmdevs[i]);
1131 snd_ac97_suspend(chip->
ac97[i]);
1132 snd_atiixp_aclink_down(chip);
1133 snd_atiixp_chip_stop(chip);
1141 static int snd_atiixp_resume(
struct device *dev)
1152 "disabling device\n");
1158 snd_atiixp_aclink_reset(chip);
1159 snd_atiixp_chip_start(chip);
1162 snd_ac97_resume(chip->
ac97[i]);
1169 #define SND_ATIIXP_PM_OPS &snd_atiixp_pm
1171 #define SND_ATIIXP_PM_OPS NULL
1174 #ifdef CONFIG_PROC_FS
1185 for (i = 0; i < 256; i += 4)
1193 if (! snd_card_proc_new(chip->
card,
"atiixp-modem", &entry))
1194 snd_info_set_text_ops(entry, chip, snd_atiixp_proc_read);
1197 #define snd_atiixp_proc_init(chip)
1209 snd_atiixp_chip_stop(chip);
1225 return snd_atiixp_free(chip);
1236 .dev_free = snd_atiixp_dev_free,
1264 snd_atiixp_free(chip);
1269 KBUILD_MODNAME, chip)) {
1271 snd_atiixp_free(chip);
1279 snd_atiixp_free(chip);
1303 if ((err = snd_atiixp_create(card, pci, &chip)) < 0)
1307 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1310 if ((err = snd_atiixp_mixer_new(chip, ac97_clock)) < 0)
1313 if ((err = snd_atiixp_pcm_new(chip)) < 0)
1318 snd_atiixp_chip_start(chip);
1326 pci_set_drvdata(pci, card);
1337 pci_set_drvdata(pci,
NULL);
1340 static struct pci_driver atiixp_modem_driver = {
1341 .name = KBUILD_MODNAME,
1342 .id_table = snd_atiixp_ids,
1343 .probe = snd_atiixp_probe,