39 #include <linux/kernel.h>
40 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/pci.h>
47 #include <linux/reboot.h>
52 #include <asm/pgtable.h>
53 #include <asm/cacheflush.h>
71 static bool single_cmd;
72 static int enable_msi = -1;
73 #ifdef CONFIG_SND_HDA_PATCH_LOADER
76 #ifdef CONFIG_SND_HDA_INPUT_BEEP
78 CONFIG_SND_HDA_INPUT_BEEP_MODE};
91 "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO).");
99 MODULE_PARM_DESC(single_cmd,
"Use single command to communicate with codecs "
100 "(for debugging only).");
103 #ifdef CONFIG_SND_HDA_PATCH_LOADER
107 #ifdef CONFIG_SND_HDA_INPUT_BEEP
110 "(0=off, 1=on) (default=1).");
114 static int param_set_xint(
const char *
val,
const struct kernel_param *kp);
116 .
set = param_set_xint,
119 #define param_check_xint param_check_int
121 static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
124 "(in second, 0 = disable).");
130 static bool power_save_controller = 1;
132 MODULE_PARM_DESC(power_save_controller,
"Reset controller in power save mode.");
135 static int align_buffer_size = -1;
138 "Force buffer and period sizes to be multiple of 128 bytes.");
144 #define azx_snoop(chip) (chip)->snoop
146 #define hda_snoop true
147 #define azx_snoop(chip) true
185 #ifdef CONFIG_SND_VERBOSE_PRINTK
188 #define SFX "hda-intel: "
191 #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
192 #ifdef CONFIG_SND_HDA_CODEC_HDMI
193 #define SUPPORT_VGA_SWITCHEROO
201 #define ICH6_REG_GCAP 0x00
202 #define ICH6_GCAP_64OK (1 << 0)
203 #define ICH6_GCAP_NSDO (3 << 1)
204 #define ICH6_GCAP_BSS (31 << 3)
205 #define ICH6_GCAP_ISS (15 << 8)
206 #define ICH6_GCAP_OSS (15 << 12)
207 #define ICH6_REG_VMIN 0x02
208 #define ICH6_REG_VMAJ 0x03
209 #define ICH6_REG_OUTPAY 0x04
210 #define ICH6_REG_INPAY 0x06
211 #define ICH6_REG_GCTL 0x08
212 #define ICH6_GCTL_RESET (1 << 0)
213 #define ICH6_GCTL_FCNTRL (1 << 1)
214 #define ICH6_GCTL_UNSOL (1 << 8)
215 #define ICH6_REG_WAKEEN 0x0c
216 #define ICH6_REG_STATESTS 0x0e
217 #define ICH6_REG_GSTS 0x10
218 #define ICH6_GSTS_FSTS (1 << 1)
219 #define ICH6_REG_INTCTL 0x20
220 #define ICH6_REG_INTSTS 0x24
221 #define ICH6_REG_WALLCLK 0x30
222 #define ICH6_REG_OLD_SSYNC 0x34
223 #define ICH6_REG_SSYNC 0x38
224 #define ICH6_REG_CORBLBASE 0x40
225 #define ICH6_REG_CORBUBASE 0x44
226 #define ICH6_REG_CORBWP 0x48
227 #define ICH6_REG_CORBRP 0x4a
228 #define ICH6_CORBRP_RST (1 << 15)
229 #define ICH6_REG_CORBCTL 0x4c
230 #define ICH6_CORBCTL_RUN (1 << 1)
231 #define ICH6_CORBCTL_CMEIE (1 << 0)
232 #define ICH6_REG_CORBSTS 0x4d
233 #define ICH6_CORBSTS_CMEI (1 << 0)
234 #define ICH6_REG_CORBSIZE 0x4e
236 #define ICH6_REG_RIRBLBASE 0x50
237 #define ICH6_REG_RIRBUBASE 0x54
238 #define ICH6_REG_RIRBWP 0x58
239 #define ICH6_RIRBWP_RST (1 << 15)
240 #define ICH6_REG_RINTCNT 0x5a
241 #define ICH6_REG_RIRBCTL 0x5c
242 #define ICH6_RBCTL_IRQ_EN (1 << 0)
243 #define ICH6_RBCTL_DMA_EN (1 << 1)
244 #define ICH6_RBCTL_OVERRUN_EN (1 << 2)
245 #define ICH6_REG_RIRBSTS 0x5d
246 #define ICH6_RBSTS_IRQ (1 << 0)
247 #define ICH6_RBSTS_OVERRUN (1 << 2)
248 #define ICH6_REG_RIRBSIZE 0x5e
250 #define ICH6_REG_IC 0x60
251 #define ICH6_REG_IR 0x64
252 #define ICH6_REG_IRS 0x68
253 #define ICH6_IRS_VALID (1<<1)
254 #define ICH6_IRS_BUSY (1<<0)
256 #define ICH6_REG_DPLBASE 0x70
257 #define ICH6_REG_DPUBASE 0x74
258 #define ICH6_DPLBASE_ENABLE 0x1
264 #define ICH6_REG_SD_CTL 0x00
265 #define ICH6_REG_SD_STS 0x03
266 #define ICH6_REG_SD_LPIB 0x04
267 #define ICH6_REG_SD_CBL 0x08
268 #define ICH6_REG_SD_LVI 0x0c
269 #define ICH6_REG_SD_FIFOW 0x0e
270 #define ICH6_REG_SD_FIFOSIZE 0x10
271 #define ICH6_REG_SD_FORMAT 0x12
272 #define ICH6_REG_SD_BDLPL 0x18
273 #define ICH6_REG_SD_BDLPU 0x1c
276 #define ICH6_PCIREG_TCSEL 0x44
284 #define ICH6_NUM_CAPTURE 4
285 #define ICH6_NUM_PLAYBACK 4
288 #define ULI_NUM_CAPTURE 5
289 #define ULI_NUM_PLAYBACK 6
292 #define ATIHDMI_NUM_CAPTURE 0
293 #define ATIHDMI_NUM_PLAYBACK 1
296 #define TERA_NUM_CAPTURE 3
297 #define TERA_NUM_PLAYBACK 4
300 #define MAX_AZX_DEV 16
303 #define BDL_SIZE 4096
304 #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
305 #define AZX_MAX_FRAG 32
307 #define AZX_MAX_BUF_SIZE (1024*1024*1024)
310 #define RIRB_INT_RESPONSE 0x01
311 #define RIRB_INT_OVERRUN 0x04
312 #define RIRB_INT_MASK 0x05
315 #define AZX_MAX_CODECS 8
316 #define AZX_DEFAULT_CODECS 4
317 #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
320 #define SD_CTL_STREAM_RESET 0x01
321 #define SD_CTL_DMA_START 0x02
322 #define SD_CTL_STRIPE (3 << 16)
323 #define SD_CTL_TRAFFIC_PRIO (1 << 18)
324 #define SD_CTL_DIR (1 << 19)
325 #define SD_CTL_STREAM_TAG_MASK (0xf << 20)
326 #define SD_CTL_STREAM_TAG_SHIFT 20
329 #define SD_INT_DESC_ERR 0x10
330 #define SD_INT_FIFO_ERR 0x08
331 #define SD_INT_COMPLETE 0x04
332 #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
336 #define SD_STS_FIFO_READY 0x20
339 #define ICH6_INT_ALL_STREAM 0xff
340 #define ICH6_INT_CTRL_EN 0x40000000
341 #define ICH6_INT_GLOBAL_EN 0x80000000
344 #define ICH6_MAX_CORB_ENTRIES 256
345 #define ICH6_MAX_RIRB_ENTRIES 256
357 #define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
358 #define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
361 #define NVIDIA_HDA_TRANSREG_ADDR 0x4e
362 #define NVIDIA_HDA_ENABLE_COHBITS 0x0f
363 #define NVIDIA_HDA_ISTRM_COH 0x4d
364 #define NVIDIA_HDA_OSTRM_COH 0x4c
365 #define NVIDIA_HDA_ENABLE_COHBIT 0x01
368 #define INTEL_SCH_HDA_DEVC 0x78
369 #define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
372 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
374 #define VIA_HDAC_DEVICE_ID 0x3288
377 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
484 #ifdef CONFIG_SND_HDA_PATCH_LOADER
493 unsigned int single_cmd :1;
499 unsigned int align_buffer_size:1;
542 #define AZX_DCAPS_NO_TCSEL (1 << 8)
543 #define AZX_DCAPS_NO_MSI (1 << 9)
544 #define AZX_DCAPS_ATI_SNOOP (1 << 10)
545 #define AZX_DCAPS_NVIDIA_SNOOP (1 << 11)
546 #define AZX_DCAPS_SCH_SNOOP (1 << 12)
547 #define AZX_DCAPS_RIRB_DELAY (1 << 13)
548 #define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14)
549 #define AZX_DCAPS_CTX_WORKAROUND (1 << 15)
550 #define AZX_DCAPS_POSFIX_LPIB (1 << 16)
551 #define AZX_DCAPS_POSFIX_VIA (1 << 17)
552 #define AZX_DCAPS_NO_64BIT (1 << 18)
553 #define AZX_DCAPS_SYNC_WRITE (1 << 19)
554 #define AZX_DCAPS_OLD_SSYNC (1 << 20)
555 #define AZX_DCAPS_BUFSIZE (1 << 21)
556 #define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22)
557 #define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23)
558 #define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25)
559 #define AZX_DCAPS_PM_RUNTIME (1 << 26)
562 #define AZX_DCAPS_INTEL_PCH \
563 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \
564 AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME)
567 #define AZX_DCAPS_PRESET_ATI_SB \
568 (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \
569 AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB)
572 #define AZX_DCAPS_PRESET_ATI_HDMI \
573 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB)
576 #define AZX_DCAPS_PRESET_NVIDIA \
577 (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\
578 AZX_DCAPS_ALIGN_BUFSIZE)
580 #define AZX_DCAPS_PRESET_CTHDA \
581 (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY)
586 #ifdef SUPPORT_VGA_SWITCHEROO
587 #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo)
589 #define use_vga_switcheroo(chip) 0
592 #if defined(SUPPORT_VGA_SWITCHEROO) || defined(CONFIG_SND_HDA_PATCH_LOADER)
593 #define DELAYED_INIT_MARK
594 #define DELAYED_INITDATA_MARK
596 #define DELAYED_INIT_MARK __devinit
597 #define DELAYED_INITDATA_MARK __devinitdata
620 #define azx_writel(chip,reg,value) \
621 writel(value, (chip)->remap_addr + ICH6_REG_##reg)
622 #define azx_readl(chip,reg) \
623 readl((chip)->remap_addr + ICH6_REG_##reg)
624 #define azx_writew(chip,reg,value) \
625 writew(value, (chip)->remap_addr + ICH6_REG_##reg)
626 #define azx_readw(chip,reg) \
627 readw((chip)->remap_addr + ICH6_REG_##reg)
628 #define azx_writeb(chip,reg,value) \
629 writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
630 #define azx_readb(chip,reg) \
631 readb((chip)->remap_addr + ICH6_REG_##reg)
633 #define azx_sd_writel(dev,reg,value) \
634 writel(value, (dev)->sd_addr + ICH6_REG_##reg)
635 #define azx_sd_readl(dev,reg) \
636 readl((dev)->sd_addr + ICH6_REG_##reg)
637 #define azx_sd_writew(dev,reg,value) \
638 writew(value, (dev)->sd_addr + ICH6_REG_##reg)
639 #define azx_sd_readw(dev,reg) \
640 readw((dev)->sd_addr + ICH6_REG_##reg)
641 #define azx_sd_writeb(dev,reg,value) \
642 writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
643 #define azx_sd_readb(dev,reg) \
644 readb((dev)->sd_addr + ICH6_REG_##reg)
647 #define get_azx_dev(substream) (substream->runtime->private_data)
650 static void __mark_pages_wc(
struct azx *
chip,
void *
addr,
size_t size,
bool on)
666 __mark_pages_wc(chip, buf->
area, buf->
bytes, on);
682 static inline void mark_runtime_wc(
struct azx *chip,
struct azx_dev *azx_dev,
688 static int azx_acquire_irq(
struct azx *chip,
int do_disconnect);
689 static int azx_send_cmd(
struct hda_bus *
bus,
unsigned int val);
697 static int azx_alloc_cmd_io(
struct azx *chip)
709 mark_pages_wc(chip, &chip->
rb,
true);
713 static void azx_init_cmd_io(
struct azx *chip)
717 chip->
corb.addr = chip->
rb.addr;
732 chip->
rirb.addr = chip->
rb.addr + 2048;
733 chip->
rirb.buf = (
u32 *)(chip->
rb.area + 2048);
753 static void azx_free_cmd_io(
struct azx *chip)
762 static unsigned int azx_command_addr(
u32 cmd)
764 unsigned int addr = cmd >> 28;
774 static unsigned int azx_response_addr(
u32 res)
776 unsigned int addr = res & 0xf;
790 unsigned int addr = azx_command_addr(val);
809 #define ICH6_RIRB_EX_UNSOL_EV (1<<4)
812 static void azx_update_rirb(
struct azx *chip)
819 if (wp == chip->
rirb.wp)
823 while (chip->
rirb.rp != wp) {
827 rp = chip->
rirb.rp << 1;
830 addr = azx_response_addr(res_ex);
833 else if (chip->
rirb.cmds[addr]) {
846 static unsigned int azx_rirb_get_response(
struct hda_bus *
bus,
851 unsigned long loopcounter;
857 for (loopcounter = 0;; loopcounter++) {
860 azx_update_rirb(chip);
863 if (!chip->
rirb.cmds[addr]) {
883 "polling the codec once: last cmd=0x%08x\n",
893 "switching to polling mode: last cmd=0x%08x\n",
901 "disabling MSI: last cmd=0x%08x\n",
907 if (azx_acquire_irq(chip, 1) < 0) {
932 "switching to single_cmd mode: last cmd=0x%08x\n",
937 azx_free_cmd_io(chip);
954 static int azx_single_wait_for_response(
struct azx *chip,
unsigned int addr)
967 if (printk_ratelimit())
978 unsigned int addr = azx_command_addr(val);
991 return azx_single_wait_for_response(chip, addr);
995 if (printk_ratelimit())
1002 static unsigned int azx_single_get_response(
struct hda_bus *bus,
1017 static int azx_send_cmd(
struct hda_bus *bus,
unsigned int val)
1025 return azx_single_send_cmd(bus, val);
1027 return azx_corb_send_cmd(bus, val);
1031 static unsigned int azx_get_response(
struct hda_bus *bus,
1038 return azx_single_get_response(bus, addr);
1040 return azx_rirb_get_response(bus, addr);
1044 static void azx_power_notify(
struct hda_bus *bus,
bool power_up);
1048 static int azx_reset(
struct azx *chip,
int full_reset)
1107 static void azx_int_enable(
struct azx *chip)
1115 static void azx_int_disable(
struct azx *chip)
1121 struct azx_dev *azx_dev = &chip->
azx_dev[
i];
1135 static void azx_int_clear(
struct azx *chip)
1141 struct azx_dev *azx_dev = &chip->
azx_dev[
i];
1156 static void azx_stream_start(
struct azx *chip,
struct azx_dev *azx_dev)
1172 static void azx_stream_clear(
struct azx *chip,
struct azx_dev *azx_dev)
1180 static void azx_stream_stop(
struct azx *chip,
struct azx_dev *azx_dev)
1182 azx_stream_clear(chip, azx_dev);
1192 static void azx_init_chip(
struct azx *chip,
int full_reset)
1198 azx_reset(chip, full_reset);
1201 azx_int_clear(chip);
1202 azx_int_enable(chip);
1206 azx_init_cmd_io(chip);
1219 static void update_pci_byte(
struct pci_dev *pci,
unsigned int reg,
1220 unsigned char mask,
unsigned char val)
1224 pci_read_config_byte(pci, reg, &data);
1226 data |= (val &
mask);
1227 pci_write_config_byte(pci, reg, data);
1230 static void azx_init_pci(
struct azx *chip)
1248 update_pci_byte(chip->
pci,
1256 update_pci_byte(chip->
pci,
1259 update_pci_byte(chip->
pci,
1262 update_pci_byte(chip->
pci,
1269 unsigned short snoop;
1272 (
azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
1273 snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
1277 pci_read_config_word(chip->
pci,
1281 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
1282 ?
"Disabled" :
"Enabled");
1287 static int azx_position_ok(
struct azx *chip,
struct azx_dev *azx_dev);
1295 struct azx_dev *azx_dev;
1300 #ifdef CONFIG_PM_RUNTIME
1327 ok = azx_position_ok(chip, azx_dev);
1333 }
else if (ok == 0 && chip->
bus && chip->
bus->workq) {
1348 azx_update_rirb(chip);
1367 static int setup_bdle(
struct azx *chip,
1369 struct azx_dev *azx_dev,
u32 **bdlp,
1370 int ofs,
int size,
int with_ioc)
1381 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
1386 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
1389 u32 remain = 0x1000 - (ofs & 0xfff);
1398 bdl[3] = (size || !with_ioc) ? 0 :
cpu_to_le32(0x01);
1410 static int azx_setup_periods(
struct azx *chip,
1412 struct azx_dev *azx_dev)
1426 bdl = (
u32 *)azx_dev->
bdl.area;
1432 int pos_align = pos_adj;
1433 pos_adj = (pos_adj * runtime->
rate + 47999) / 48000;
1435 pos_adj = pos_align;
1437 pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
1439 pos_adj = frames_to_bytes(runtime, pos_adj);
1440 if (pos_adj >= period_bytes) {
1445 ofs = setup_bdle(chip, substream, azx_dev,
1446 &bdl, ofs, pos_adj,
true);
1452 for (i = 0; i <
periods; i++) {
1453 if (i == periods - 1 && pos_adj)
1454 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs,
1455 period_bytes - pos_adj, 0);
1457 ofs = setup_bdle(chip, substream, azx_dev, &bdl, ofs,
1467 azx_dev->
bufsize, period_bytes);
1472 static void azx_stream_reset(
struct azx *chip,
struct azx_dev *azx_dev)
1477 azx_stream_clear(chip, azx_dev);
1486 val &= ~SD_CTL_STREAM_RESET;
1492 while (((val =
azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
1503 static int azx_setup_controller(
struct azx *chip,
struct azx_dev *azx_dev)
1507 azx_stream_clear(chip, azx_dev);
1537 (
u32)chip->
posbuf.addr | ICH6_DPLBASE_ENABLE);
1550 static int probe_codec(
struct azx *chip,
int addr)
1552 unsigned int cmd = (addr << 28) | (
AC_NODE_ROOT << 20) |
1558 azx_send_cmd(chip->
bus, cmd);
1559 res = azx_get_response(chip->
bus, addr);
1570 static void azx_stop_chip(
struct azx *chip);
1572 static void azx_bus_reset(
struct hda_bus *bus)
1577 azx_stop_chip(chip);
1578 azx_init_chip(chip, 1);
1583 snd_pcm_suspend_all(p->
pcm);
1584 snd_hda_suspend(chip->bus);
1585 snd_hda_resume(chip->bus);
1596 static unsigned int azx_max_codecs[
AZX_NUM_DRIVERS] DELAYED_INITDATA_MARK = {
1607 memset(&bus_temp, 0,
sizeof(bus_temp));
1608 bus_temp.private_data =
chip;
1609 bus_temp.modelname = model;
1610 bus_temp.pci = chip->
pci;
1611 bus_temp.ops.command = azx_send_cmd;
1612 bus_temp.ops.get_response = azx_get_response;
1613 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1614 bus_temp.ops.bus_reset = azx_bus_reset;
1617 bus_temp.ops.pm_notify = azx_power_notify;
1626 chip->
bus->needs_damn_long_delay = 1;
1635 for (c = 0; c < max_slots; c++) {
1637 if (probe_codec(chip, c) < 0) {
1642 "Codec #%d probe error; "
1643 "disabling it...\n", c);
1652 azx_stop_chip(chip);
1653 azx_init_chip(chip, 1);
1663 snd_printd(
SFX "Enable sync_write for stable communication\n");
1664 chip->
bus->sync_write = 1;
1665 chip->
bus->allow_bus_reset = 1;
1669 for (c = 0; c < max_slots; c++) {
1687 static int __devinit azx_codec_configure(
struct azx *chip)
1702 static inline struct azx_dev *
1706 struct azx_dev *res =
NULL;
1708 int key = (substream->
pcm->device << 16) | (substream->
number << 2) |
1718 for (i = 0; i < nums; i++, dev++)
1719 if (!chip->
azx_dev[dev].opened) {
1732 static inline void azx_release_device(
struct azx_dev *azx_dev)
1765 struct azx *chip = apcm->
chip;
1766 struct azx_dev *azx_dev;
1768 unsigned long flags;
1773 azx_dev = azx_assign_device(chip, substream);
1774 if (azx_dev ==
NULL) {
1778 runtime->
hw = azx_pcm_hw;
1782 runtime->
hw.rates = hinfo->
rates;
1804 snd_hda_power_up_d3wait(apcm->
codec);
1805 err = hinfo->
ops.open(hinfo, apcm->
codec, substream);
1807 azx_release_device(azx_dev);
1808 snd_hda_power_down(apcm->
codec);
1818 azx_release_device(azx_dev);
1819 hinfo->
ops.close(hinfo, apcm->
codec, substream);
1820 snd_hda_power_down(apcm->
codec);
1827 spin_unlock_irqrestore(&chip->
reg_lock, flags);
1839 struct azx *chip = apcm->
chip;
1841 unsigned long flags;
1847 spin_unlock_irqrestore(&chip->
reg_lock, flags);
1848 azx_release_device(azx_dev);
1849 hinfo->
ops.close(hinfo, apcm->
codec, substream);
1850 snd_hda_power_down(apcm->
codec);
1859 struct azx *chip = apcm->
chip;
1864 mark_runtime_wc(chip, azx_dev, runtime,
false);
1872 mark_runtime_wc(chip, azx_dev, runtime,
true);
1880 struct azx *chip = apcm->
chip;
1894 mark_runtime_wc(chip, azx_dev, runtime,
false);
1901 struct azx *chip = apcm->
chip;
1905 unsigned int bufsize, period_bytes, format_val, stream_tag;
1909 unsigned short ctls = spdif ? spdif->
ctls : 0;
1911 azx_stream_reset(chip, azx_dev);
1919 "invalid format_val, rate=%d, ch=%d, format=%d\n",
1924 bufsize = snd_pcm_lib_buffer_bytes(substream);
1925 period_bytes = snd_pcm_lib_period_bytes(substream);
1928 bufsize, format_val);
1930 if (bufsize != azx_dev->
bufsize ||
1938 err = azx_setup_periods(chip, substream, azx_dev);
1945 runtime->
rate) * 1000);
1946 azx_setup_controller(chip, azx_dev);
1964 struct azx *chip = apcm->
chip;
1965 struct azx_dev *azx_dev;
1967 int rstart = 0,
start, nsync = 0, sbits = 0;
1987 if (s->
pcm->card != substream->
pcm->card)
1990 sbits |= 1 << azx_dev->
index;
1992 snd_pcm_trigger_done(s, substream);
2005 if (s->
pcm->card != substream->
pcm->card)
2013 azx_stream_start(chip, azx_dev);
2015 azx_stream_stop(chip, azx_dev);
2022 for (timeout = 5000; timeout; timeout--) {
2025 if (s->
pcm->card != substream->
pcm->card)
2038 for (timeout = 5000; timeout; timeout--) {
2041 if (s->
pcm->card != substream->
pcm->card)
2065 static unsigned int azx_via_get_position(
struct azx *chip,
2066 struct azx_dev *azx_dev)
2068 unsigned int link_pos, mini_pos, bound_pos;
2069 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
2092 if (link_pos <= fifo_size)
2098 if (link_pos <= fifo_size)
2106 if (mod_link_pos >= fifo_size)
2107 bound_pos = link_pos - mod_link_pos;
2108 else if (mod_dma_pos >= mod_mini_pos)
2109 bound_pos = mini_pos - mod_mini_pos;
2111 bound_pos = mini_pos - mod_mini_pos + azx_dev->
period_bytes;
2112 if (bound_pos >= azx_dev->
bufsize)
2117 return bound_pos + mod_dma_pos;
2120 static unsigned int azx_get_position(
struct azx *chip,
2121 struct azx_dev *azx_dev,
2133 pos = azx_via_get_position(chip, azx_dev);
2139 if (!pos || pos == (
u32)-1) {
2141 "hda-intel: Invalid position buffer, "
2142 "using LPIB read method instead.\n");
2158 unsigned int lpib_pos =
azx_sd_readl(azx_dev, SD_LPIB);
2161 delay = pos - lpib_pos;
2163 delay = lpib_pos -
pos;
2168 "Unstable LPIB (%d >= %d); "
2169 "disabling LPIB delay counting\n",
2175 bytes_to_frames(azx_dev->
substream->runtime, delay);
2183 struct azx *chip = apcm->
chip;
2185 return bytes_to_frames(substream->
runtime,
2186 azx_get_position(chip, azx_dev,
false));
2198 static int azx_position_ok(
struct azx *chip,
struct azx_dev *azx_dev)
2209 pos = azx_get_position(chip, azx_dev,
true);
2212 "hda-intel: zero azx_dev->period_bytes"))
2217 return bdl_pos_adj[chip->
dev_index] ? 0 : -1;
2232 "hda-intel: IRQ timing workaround is activated "
2233 "for card #%d. Suggest a bigger bdl_pos_adj.\n",
2234 chip->
card->number);
2242 struct azx_dev *azx_dev = &chip->
azx_dev[
i];
2247 ok = azx_position_ok(chip, azx_dev);
2253 }
else if (ok < 0) {
2266 static void azx_clear_irq_pending(
struct azx *chip)
2272 chip->
azx_dev[i].irq_pending = 0;
2281 struct azx *chip = apcm->
chip;
2287 #define azx_pcm_mmap NULL
2291 .open = azx_pcm_open,
2292 .close = azx_pcm_close,
2294 .hw_params = azx_pcm_hw_params,
2295 .hw_free = azx_pcm_hw_free,
2296 .prepare = azx_pcm_prepare,
2297 .trigger = azx_pcm_trigger,
2298 .pointer = azx_pcm_pointer,
2303 static void azx_pcm_free(
struct snd_pcm *pcm)
2312 #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
2326 if (apcm->
pcm->device == pcm_dev) {
2350 for (s = 0; s < 2; s++) {
2352 if (cpcm->
stream[s].substreams)
2356 size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
2368 static int __devinit azx_mixer_create(
struct azx *chip)
2386 struct azx_dev *azx_dev = &chip->
azx_dev[
i];
2400 static int azx_acquire_irq(
struct azx *chip,
int do_disconnect)
2404 KBUILD_MODNAME, chip)) {
2406 "disabling device\n", chip->
pci->irq);
2411 chip->
irq = chip->
pci->irq;
2417 static void azx_stop_chip(
struct azx *chip)
2423 azx_int_disable(chip);
2424 azx_int_clear(chip);
2427 azx_free_cmd_io(chip);
2438 static void azx_power_notify(
struct hda_bus *bus,
bool power_up)
2446 pm_runtime_get_sync(&chip->
pci->dev);
2448 pm_runtime_put_sync(&chip->
pci->dev);
2457 list_add(&chip->
list, &card_list);
2464 list_del_init(&chip->
list);
2469 static int param_set_xint(
const char *val,
const struct kernel_param *kp)
2473 int prev = power_save;
2476 if (ret || prev == power_save)
2484 snd_hda_power_sync(c);
2490 #define azx_add_card_list(chip)
2491 #define azx_del_card_list(chip)
2494 #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO)
2498 static int azx_suspend(
struct device *dev)
2506 azx_clear_irq_pending(chip);
2508 snd_pcm_suspend_all(p->
pcm);
2510 snd_hda_suspend(chip->
bus);
2511 azx_stop_chip(chip);
2512 if (chip->
irq >= 0) {
2524 static int azx_resume(
struct device *dev)
2534 "disabling device\n");
2540 if (pci_enable_msi(pci) < 0)
2542 if (azx_acquire_irq(chip, 1) < 0)
2546 azx_init_chip(chip, 1);
2548 snd_hda_resume(chip->
bus);
2554 #ifdef CONFIG_PM_RUNTIME
2555 static int azx_runtime_suspend(
struct device *dev)
2560 if (!power_save_controller ||
2564 azx_stop_chip(chip);
2565 azx_clear_irq_pending(chip);
2569 static int azx_runtime_resume(
struct device *dev)
2575 azx_init_chip(chip, 1);
2586 #define AZX_PM_OPS &azx_pm
2588 #define AZX_PM_OPS NULL
2599 azx_stop_chip(chip);
2603 static void azx_notifier_register(
struct azx *chip)
2609 static void azx_notifier_unregister(
struct azx *chip)
2618 #ifdef SUPPORT_VGA_SWITCHEROO
2621 static void azx_vs_set_state(
struct pci_dev *pci,
2624 struct snd_card *card = pci_get_drvdata(pci);
2639 "%s: Start delayed initialization\n",
2640 pci_name(chip->
pci));
2641 if (azx_first_init(chip) < 0 ||
2642 azx_probe_continue(chip) < 0) {
2644 "%s: initialization error\n",
2645 pci_name(chip->
pci));
2651 "%s %s via VGA-switcheroo\n",
2652 disabled ?
"Disabling" :
"Enabling",
2653 pci_name(chip->
pci));
2655 azx_suspend(&pci->
dev);
2659 "Cannot lock devices!\n");
2663 azx_resume(&pci->
dev);
2668 static bool azx_vs_can_switch(
struct pci_dev *pci)
2670 struct snd_card *card = pci_get_drvdata(pci);
2685 struct pci_dev *p = get_bound_vga(chip->
pci);
2688 "%s: Handle VGA-switcheroo audio client\n",
2689 pci_name(chip->
pci));
2697 .can_switch = azx_vs_can_switch,
2718 #define init_vga_switcheroo(chip)
2719 #define register_vga_switcheroo(chip) 0
2720 #define check_hdmi_disabled(pci) false
2726 static int azx_free(
struct azx *chip)
2732 azx_notifier_unregister(chip);
2742 azx_clear_irq_pending(chip);
2744 azx_stream_stop(chip, &chip->
azx_dev[i]);
2745 azx_stop_chip(chip);
2757 if (chip->
azx_dev[i].bdl.area) {
2758 mark_pages_wc(chip, &chip->
azx_dev[i].bdl,
false);
2762 if (chip->
rb.area) {
2763 mark_pages_wc(chip, &chip->
rb,
false);
2767 mark_pages_wc(chip, &chip->
posbuf,
false);
2774 #ifdef CONFIG_SND_HDA_PATCH_LOADER
2788 #ifdef SUPPORT_VGA_SWITCHEROO
2801 if (pci->
devfn == 1) {
2803 pci->
bus->number, 0);
2817 bool vga_inactive =
false;
2818 struct pci_dev *p = get_bound_vga(pci);
2822 vga_inactive =
true;
2825 return vga_inactive;
2832 static struct snd_pci_quirk position_fix_list[]
__devinitdata = {
2833 SND_PCI_QUIRK(0x1028, 0x01cc,
"Dell D820",
POS_FIX_LPIB),
2834 SND_PCI_QUIRK(0x1028, 0x01de,
"Dell Precision 390",
POS_FIX_LPIB),
2836 SND_PCI_QUIRK(0x1043, 0x813d,
"ASUS P5AD2",
POS_FIX_LPIB),
2838 SND_PCI_QUIRK(0x1043, 0x81e7,
"ASUS M2V",
POS_FIX_LPIB),
2839 SND_PCI_QUIRK(0x104d, 0x9069,
"Sony VPCS11V9E",
POS_FIX_LPIB),
2840 SND_PCI_QUIRK(0x10de, 0xcb89,
"Macbook Pro 7,1",
POS_FIX_LPIB),
2841 SND_PCI_QUIRK(0x1297, 0x3166,
"Shuttle",
POS_FIX_LPIB),
2842 SND_PCI_QUIRK(0x1458, 0xa022,
"ga-ma770-ud3",
POS_FIX_LPIB),
2843 SND_PCI_QUIRK(0x1462, 0x1002,
"MSI Wind U115",
POS_FIX_LPIB),
2844 SND_PCI_QUIRK(0x1565, 0x8218,
"Biostar Microtech",
POS_FIX_LPIB),
2845 SND_PCI_QUIRK(0x1849, 0x0888,
"775Dual-VSTA",
POS_FIX_LPIB),
2846 SND_PCI_QUIRK(0x8086, 0x2503,
"DG965OT AAD63733-203",
POS_FIX_LPIB),
2850 static int __devinit check_position_fix(
struct azx *chip,
int fix)
2852 const struct snd_pci_quirk *
q;
2863 q = snd_pci_quirk_lookup(chip->
pci, position_fix_list);
2866 "hda_intel: position_fix set to %d "
2867 "for device %04x:%04x\n",
2868 q->value, q->subvendor, q->subdevice);
2874 snd_printd(SFX
"Using VIACOMBO position fix\n");
2887 static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
2891 SND_PCI_QUIRK(0x1014, 0x05b7,
"Thinkpad Z60", 0x01),
2892 SND_PCI_QUIRK(0x17aa, 0x2010,
"Thinkpad X/T/R60", 0x01),
2893 SND_PCI_QUIRK(0x17aa, 0x20ac,
"Thinkpad X/T/R61", 0x01),
2895 SND_PCI_QUIRK(0x1028, 0x20ac,
"Dell Studio Desktop", 0x01),
2897 SND_PCI_QUIRK(0x17c0, 0x4085,
"Medion MD96630", 0x01),
2899 SND_PCI_QUIRK(0x1043, 0x1262,
"ASUS W5Fm", 0x103),
2900 SND_PCI_QUIRK(0x1046, 0x1262,
"ASUS W5F", 0x103),
2902 SND_PCI_QUIRK(0x3a21, 0x040d,
"WinFast VP200 H", 0x101),
2906 #define AZX_FORCE_CODEC_MASK 0x100
2908 static void __devinit check_probe_mask(
struct azx *chip,
int dev)
2910 const struct snd_pci_quirk *
q;
2914 q = snd_pci_quirk_lookup(chip->
pci, probe_mask_list);
2917 "hda_intel: probe_mask set to 0x%x "
2918 "for device %04x:%04x\n",
2919 q->value, q->subvendor, q->subdevice);
2936 static struct snd_pci_quirk msi_black_list[] __devinitdata = {
2937 SND_PCI_QUIRK(0x1043, 0x81f2,
"ASUS", 0),
2938 SND_PCI_QUIRK(0x1043, 0x81f6,
"ASUS", 0),
2939 SND_PCI_QUIRK(0x1043, 0x822d,
"ASUS", 0),
2940 SND_PCI_QUIRK(0x1849, 0x0888,
"ASRock", 0),
2941 SND_PCI_QUIRK(0xa0a0, 0x0575,
"Aopen MZ915-M", 0),
2947 const struct snd_pci_quirk *
q;
2949 if (enable_msi >= 0) {
2950 chip->
msi = !!enable_msi;
2954 q = snd_pci_quirk_lookup(chip->
pci, msi_black_list);
2957 "hda_intel: msi for device %04x:%04x set to %d\n",
2958 q->subvendor, q->subdevice, q->value);
2959 chip->
msi = q->value;
2971 static void __devinit azx_check_snoop_available(
struct azx *chip)
2973 bool snoop = chip->
snoop;
2982 pci_read_config_byte(chip->
pci, 0x42, &val);
2983 if (!(val & 0x80) && chip->
pci->revision == 0x30)
2993 if (snoop != chip->
snoop) {
2995 snoop ?
"snoop" :
"non-snoop");
3004 int dev,
unsigned int driver_caps,
3008 .dev_free = azx_dev_free,
3037 INIT_LIST_HEAD(&chip->
list);
3048 check_probe_mask(chip, dev);
3052 azx_check_snoop_available(chip);
3054 if (bdl_pos_adj[dev] < 0) {
3058 bdl_pos_adj[
dev] = 1;
3061 bdl_pos_adj[
dev] = 32;
3079 err = azx_first_init(chip);
3103 unsigned short gcap;
3105 #if BITS_PER_LONG != 64
3109 pci_read_config_word(pci, 0x40, &tmp3);
3110 pci_write_config_word(pci, 0x40, tmp3 | 0x10);
3128 if (pci_enable_msi(pci) < 0)
3131 if (azx_acquire_irq(chip, 0) < 0)
3138 snd_printdd(SFX
"chipset global capabilities = 0x%x\n", gcap);
3160 if (align_buffer_size >= 0)
3223 mark_pages_wc(chip, &chip->
azx_dev[i].bdl,
true);
3233 mark_pages_wc(chip, &chip->
posbuf,
true);
3235 err = azx_alloc_cmd_io(chip);
3240 azx_init_stream(chip);
3244 azx_init_chip(chip, (probe_only[dev] & 2) == 0);
3256 "%s at 0x%lx irq %i",
3262 static void power_down_all_codecs(
struct azx *chip)
3270 snd_hda_power_down(codec);
3275 #ifdef CONFIG_SND_HDA_PATCH_LOADER
3291 if (azx_probe_continue(chip))
3298 pci_set_drvdata(pci, NULL);
3326 err = azx_create(card, pci, dev, pci_id->
driver_data, &chip);
3332 #ifdef CONFIG_SND_HDA_PATCH_LOADER
3333 if (patch[dev] && *patch[dev]) {
3346 err = azx_probe_continue(chip);
3351 pci_set_drvdata(pci, card);
3354 pm_runtime_put_noidle(&pci->
dev);
3359 "Error registering VGA-switcheroo client\n");
3376 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3381 err = azx_codec_create(chip, model[dev]);
3384 #ifdef CONFIG_SND_HDA_PATCH_LOADER
3386 err = snd_hda_load_patch(chip->
bus, chip->fw->size,
3394 if ((probe_only[dev] & 1) == 0) {
3395 err = azx_codec_configure(chip);
3406 err = azx_mixer_create(chip);
3415 power_down_all_codecs(chip);
3416 azx_notifier_register(chip);
3428 struct snd_card *card = pci_get_drvdata(pci);
3431 pm_runtime_get_noresume(&pci->
dev);
3435 pci_set_drvdata(pci, NULL);
3501 .class_mask = 0xffffff,
3562 .class_mask = 0xffffff,
3575 #if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE)
3582 .class_mask = 0xffffff,
3598 .class_mask = 0xffffff,
3602 .class_mask = 0xffffff,
3610 .name = KBUILD_MODNAME,
3611 .id_table = azx_ids,