diff options
Diffstat (limited to 'sound/pci/hda/hda_intel.c')
-rw-r--r-- | sound/pci/hda/hda_intel.c | 109 |
1 files changed, 63 insertions, 46 deletions
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index cec68152dcb1..170610e1d7da 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -84,7 +84,7 @@ module_param_array(bdl_pos_adj, int, NULL, 0644); | |||
84 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); | 84 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); |
85 | module_param_array(probe_mask, int, NULL, 0444); | 85 | module_param_array(probe_mask, int, NULL, 0444); |
86 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); | 86 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); |
87 | module_param_array(probe_only, bool, NULL, 0444); | 87 | module_param_array(probe_only, int, NULL, 0444); |
88 | MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); | 88 | MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); |
89 | module_param(single_cmd, bool, 0444); | 89 | module_param(single_cmd, bool, 0444); |
90 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " | 90 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " |
@@ -174,7 +174,7 @@ MODULE_DESCRIPTION("Intel HDA driver"); | |||
174 | #define ICH6_GSTS_FSTS (1 << 1) /* flush status */ | 174 | #define ICH6_GSTS_FSTS (1 << 1) /* flush status */ |
175 | #define ICH6_REG_INTCTL 0x20 | 175 | #define ICH6_REG_INTCTL 0x20 |
176 | #define ICH6_REG_INTSTS 0x24 | 176 | #define ICH6_REG_INTSTS 0x24 |
177 | #define ICH6_REG_WALCLK 0x30 | 177 | #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */ |
178 | #define ICH6_REG_SYNC 0x34 | 178 | #define ICH6_REG_SYNC 0x34 |
179 | #define ICH6_REG_CORBLBASE 0x40 | 179 | #define ICH6_REG_CORBLBASE 0x40 |
180 | #define ICH6_REG_CORBUBASE 0x44 | 180 | #define ICH6_REG_CORBUBASE 0x44 |
@@ -340,8 +340,8 @@ struct azx_dev { | |||
340 | unsigned int period_bytes; /* size of the period in bytes */ | 340 | unsigned int period_bytes; /* size of the period in bytes */ |
341 | unsigned int frags; /* number for period in the play buffer */ | 341 | unsigned int frags; /* number for period in the play buffer */ |
342 | unsigned int fifo_size; /* FIFO size */ | 342 | unsigned int fifo_size; /* FIFO size */ |
343 | unsigned long start_jiffies; /* start + minimum jiffies */ | 343 | unsigned long start_wallclk; /* start + minimum wallclk */ |
344 | unsigned long min_jiffies; /* minimum jiffies before position is valid */ | 344 | unsigned long period_wallclk; /* wallclk for period */ |
345 | 345 | ||
346 | void __iomem *sd_addr; /* stream descriptor pointer */ | 346 | void __iomem *sd_addr; /* stream descriptor pointer */ |
347 | 347 | ||
@@ -361,7 +361,6 @@ struct azx_dev { | |||
361 | unsigned int opened :1; | 361 | unsigned int opened :1; |
362 | unsigned int running :1; | 362 | unsigned int running :1; |
363 | unsigned int irq_pending :1; | 363 | unsigned int irq_pending :1; |
364 | unsigned int start_flag: 1; /* stream full start flag */ | ||
365 | /* | 364 | /* |
366 | * For VIA: | 365 | * For VIA: |
367 | * A flag to ensure DMA position is 0 | 366 | * A flag to ensure DMA position is 0 |
@@ -425,7 +424,7 @@ struct azx { | |||
425 | struct snd_dma_buffer posbuf; | 424 | struct snd_dma_buffer posbuf; |
426 | 425 | ||
427 | /* flags */ | 426 | /* flags */ |
428 | int position_fix; | 427 | int position_fix[2]; /* for both playback/capture streams */ |
429 | int poll_count; | 428 | int poll_count; |
430 | unsigned int running :1; | 429 | unsigned int running :1; |
431 | unsigned int initialized :1; | 430 | unsigned int initialized :1; |
@@ -858,10 +857,13 @@ static void azx_power_notify(struct hda_bus *bus); | |||
858 | #endif | 857 | #endif |
859 | 858 | ||
860 | /* reset codec link */ | 859 | /* reset codec link */ |
861 | static int azx_reset(struct azx *chip) | 860 | static int azx_reset(struct azx *chip, int full_reset) |
862 | { | 861 | { |
863 | int count; | 862 | int count; |
864 | 863 | ||
864 | if (!full_reset) | ||
865 | goto __skip; | ||
866 | |||
865 | /* clear STATESTS */ | 867 | /* clear STATESTS */ |
866 | azx_writeb(chip, STATESTS, STATESTS_INT_MASK); | 868 | azx_writeb(chip, STATESTS, STATESTS_INT_MASK); |
867 | 869 | ||
@@ -887,6 +889,7 @@ static int azx_reset(struct azx *chip) | |||
887 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ | 889 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ |
888 | msleep(1); | 890 | msleep(1); |
889 | 891 | ||
892 | __skip: | ||
890 | /* check to see if controller is ready */ | 893 | /* check to see if controller is ready */ |
891 | if (!azx_readb(chip, GCTL)) { | 894 | if (!azx_readb(chip, GCTL)) { |
892 | snd_printd(SFX "azx_reset: controller not ready!\n"); | 895 | snd_printd(SFX "azx_reset: controller not ready!\n"); |
@@ -998,13 +1001,13 @@ static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev) | |||
998 | /* | 1001 | /* |
999 | * reset and start the controller registers | 1002 | * reset and start the controller registers |
1000 | */ | 1003 | */ |
1001 | static void azx_init_chip(struct azx *chip) | 1004 | static void azx_init_chip(struct azx *chip, int full_reset) |
1002 | { | 1005 | { |
1003 | if (chip->initialized) | 1006 | if (chip->initialized) |
1004 | return; | 1007 | return; |
1005 | 1008 | ||
1006 | /* reset controller */ | 1009 | /* reset controller */ |
1007 | azx_reset(chip); | 1010 | azx_reset(chip, full_reset); |
1008 | 1011 | ||
1009 | /* initialize interrupts */ | 1012 | /* initialize interrupts */ |
1010 | azx_int_clear(chip); | 1013 | azx_int_clear(chip); |
@@ -1302,8 +1305,10 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) | |||
1302 | azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr)); | 1305 | azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr)); |
1303 | 1306 | ||
1304 | /* enable the position buffer */ | 1307 | /* enable the position buffer */ |
1305 | if (chip->position_fix == POS_FIX_POSBUF || | 1308 | if (chip->position_fix[0] == POS_FIX_POSBUF || |
1306 | chip->position_fix == POS_FIX_AUTO || | 1309 | chip->position_fix[0] == POS_FIX_AUTO || |
1310 | chip->position_fix[1] == POS_FIX_POSBUF || | ||
1311 | chip->position_fix[1] == POS_FIX_AUTO || | ||
1307 | chip->via_dmapos_patch) { | 1312 | chip->via_dmapos_patch) { |
1308 | if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) | 1313 | if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) |
1309 | azx_writel(chip, DPLBASE, | 1314 | azx_writel(chip, DPLBASE, |
@@ -1348,7 +1353,7 @@ static void azx_bus_reset(struct hda_bus *bus) | |||
1348 | 1353 | ||
1349 | bus->in_reset = 1; | 1354 | bus->in_reset = 1; |
1350 | azx_stop_chip(chip); | 1355 | azx_stop_chip(chip); |
1351 | azx_init_chip(chip); | 1356 | azx_init_chip(chip, 1); |
1352 | #ifdef CONFIG_PM | 1357 | #ifdef CONFIG_PM |
1353 | if (chip->initialized) { | 1358 | if (chip->initialized) { |
1354 | int i; | 1359 | int i; |
@@ -1422,7 +1427,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model) | |||
1422 | * get back to the sanity state. | 1427 | * get back to the sanity state. |
1423 | */ | 1428 | */ |
1424 | azx_stop_chip(chip); | 1429 | azx_stop_chip(chip); |
1425 | azx_init_chip(chip); | 1430 | azx_init_chip(chip, 1); |
1426 | } | 1431 | } |
1427 | } | 1432 | } |
1428 | } | 1433 | } |
@@ -1670,8 +1675,9 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream) | |||
1670 | return err; | 1675 | return err; |
1671 | } | 1676 | } |
1672 | 1677 | ||
1673 | azx_dev->min_jiffies = (runtime->period_size * HZ) / | 1678 | /* wallclk has 24Mhz clock source */ |
1674 | (runtime->rate * 2); | 1679 | azx_dev->period_wallclk = (((runtime->period_size * 24000) / |
1680 | runtime->rate) * 1000); | ||
1675 | azx_setup_controller(chip, azx_dev); | 1681 | azx_setup_controller(chip, azx_dev); |
1676 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 1682 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
1677 | azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; | 1683 | azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; |
@@ -1725,14 +1731,15 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
1725 | if (s->pcm->card != substream->pcm->card) | 1731 | if (s->pcm->card != substream->pcm->card) |
1726 | continue; | 1732 | continue; |
1727 | azx_dev = get_azx_dev(s); | 1733 | azx_dev = get_azx_dev(s); |
1728 | if (rstart) { | 1734 | if (start) { |
1729 | azx_dev->start_flag = 1; | 1735 | azx_dev->start_wallclk = azx_readl(chip, WALLCLK); |
1730 | azx_dev->start_jiffies = jiffies + azx_dev->min_jiffies; | 1736 | if (!rstart) |
1731 | } | 1737 | azx_dev->start_wallclk -= |
1732 | if (start) | 1738 | azx_dev->period_wallclk; |
1733 | azx_stream_start(chip, azx_dev); | 1739 | azx_stream_start(chip, azx_dev); |
1734 | else | 1740 | } else { |
1735 | azx_stream_stop(chip, azx_dev); | 1741 | azx_stream_stop(chip, azx_dev); |
1742 | } | ||
1736 | azx_dev->running = start; | 1743 | azx_dev->running = start; |
1737 | } | 1744 | } |
1738 | spin_unlock(&chip->reg_lock); | 1745 | spin_unlock(&chip->reg_lock); |
@@ -1843,13 +1850,16 @@ static unsigned int azx_get_position(struct azx *chip, | |||
1843 | 1850 | ||
1844 | if (chip->via_dmapos_patch) | 1851 | if (chip->via_dmapos_patch) |
1845 | pos = azx_via_get_position(chip, azx_dev); | 1852 | pos = azx_via_get_position(chip, azx_dev); |
1846 | else if (chip->position_fix == POS_FIX_POSBUF || | 1853 | else { |
1847 | chip->position_fix == POS_FIX_AUTO) { | 1854 | int stream = azx_dev->substream->stream; |
1848 | /* use the position buffer */ | 1855 | if (chip->position_fix[stream] == POS_FIX_POSBUF || |
1849 | pos = le32_to_cpu(*azx_dev->posbuf); | 1856 | chip->position_fix[stream] == POS_FIX_AUTO) { |
1850 | } else { | 1857 | /* use the position buffer */ |
1851 | /* read LPIB */ | 1858 | pos = le32_to_cpu(*azx_dev->posbuf); |
1852 | pos = azx_sd_readl(azx_dev, SD_LPIB); | 1859 | } else { |
1860 | /* read LPIB */ | ||
1861 | pos = azx_sd_readl(azx_dev, SD_LPIB); | ||
1862 | } | ||
1853 | } | 1863 | } |
1854 | if (pos >= azx_dev->bufsize) | 1864 | if (pos >= azx_dev->bufsize) |
1855 | pos = 0; | 1865 | pos = 0; |
@@ -1876,32 +1886,35 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) | |||
1876 | */ | 1886 | */ |
1877 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) | 1887 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) |
1878 | { | 1888 | { |
1889 | u32 wallclk; | ||
1879 | unsigned int pos; | 1890 | unsigned int pos; |
1891 | int stream; | ||
1880 | 1892 | ||
1881 | if (azx_dev->start_flag && | 1893 | wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk; |
1882 | time_before_eq(jiffies, azx_dev->start_jiffies)) | 1894 | if (wallclk < (azx_dev->period_wallclk * 2) / 3) |
1883 | return -1; /* bogus (too early) interrupt */ | 1895 | return -1; /* bogus (too early) interrupt */ |
1884 | azx_dev->start_flag = 0; | ||
1885 | 1896 | ||
1897 | stream = azx_dev->substream->stream; | ||
1886 | pos = azx_get_position(chip, azx_dev); | 1898 | pos = azx_get_position(chip, azx_dev); |
1887 | if (chip->position_fix == POS_FIX_AUTO) { | 1899 | if (chip->position_fix[stream] == POS_FIX_AUTO) { |
1888 | if (!pos) { | 1900 | if (!pos) { |
1889 | printk(KERN_WARNING | 1901 | printk(KERN_WARNING |
1890 | "hda-intel: Invalid position buffer, " | 1902 | "hda-intel: Invalid position buffer, " |
1891 | "using LPIB read method instead.\n"); | 1903 | "using LPIB read method instead.\n"); |
1892 | chip->position_fix = POS_FIX_LPIB; | 1904 | chip->position_fix[stream] = POS_FIX_LPIB; |
1893 | pos = azx_get_position(chip, azx_dev); | 1905 | pos = azx_get_position(chip, azx_dev); |
1894 | } else | 1906 | } else |
1895 | chip->position_fix = POS_FIX_POSBUF; | 1907 | chip->position_fix[stream] = POS_FIX_POSBUF; |
1896 | } | 1908 | } |
1897 | 1909 | ||
1898 | if (!bdl_pos_adj[chip->dev_index]) | ||
1899 | return 1; /* no delayed ack */ | ||
1900 | if (WARN_ONCE(!azx_dev->period_bytes, | 1910 | if (WARN_ONCE(!azx_dev->period_bytes, |
1901 | "hda-intel: zero azx_dev->period_bytes")) | 1911 | "hda-intel: zero azx_dev->period_bytes")) |
1902 | return 0; /* this shouldn't happen! */ | 1912 | return -1; /* this shouldn't happen! */ |
1903 | if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) | 1913 | if (wallclk <= azx_dev->period_wallclk && |
1904 | return 0; /* NG - it's below the period boundary */ | 1914 | pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) |
1915 | /* NG - it's below the first next period boundary */ | ||
1916 | return bdl_pos_adj[chip->dev_index] ? 0 : -1; | ||
1917 | azx_dev->start_wallclk = wallclk; | ||
1905 | return 1; /* OK, it's fine */ | 1918 | return 1; /* OK, it's fine */ |
1906 | } | 1919 | } |
1907 | 1920 | ||
@@ -1911,7 +1924,7 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) | |||
1911 | static void azx_irq_pending_work(struct work_struct *work) | 1924 | static void azx_irq_pending_work(struct work_struct *work) |
1912 | { | 1925 | { |
1913 | struct azx *chip = container_of(work, struct azx, irq_pending_work); | 1926 | struct azx *chip = container_of(work, struct azx, irq_pending_work); |
1914 | int i, pending; | 1927 | int i, pending, ok; |
1915 | 1928 | ||
1916 | if (!chip->irq_pending_warned) { | 1929 | if (!chip->irq_pending_warned) { |
1917 | printk(KERN_WARNING | 1930 | printk(KERN_WARNING |
@@ -1930,11 +1943,14 @@ static void azx_irq_pending_work(struct work_struct *work) | |||
1930 | !azx_dev->substream || | 1943 | !azx_dev->substream || |
1931 | !azx_dev->running) | 1944 | !azx_dev->running) |
1932 | continue; | 1945 | continue; |
1933 | if (azx_position_ok(chip, azx_dev)) { | 1946 | ok = azx_position_ok(chip, azx_dev); |
1947 | if (ok > 0) { | ||
1934 | azx_dev->irq_pending = 0; | 1948 | azx_dev->irq_pending = 0; |
1935 | spin_unlock(&chip->reg_lock); | 1949 | spin_unlock(&chip->reg_lock); |
1936 | snd_pcm_period_elapsed(azx_dev->substream); | 1950 | snd_pcm_period_elapsed(azx_dev->substream); |
1937 | spin_lock(&chip->reg_lock); | 1951 | spin_lock(&chip->reg_lock); |
1952 | } else if (ok < 0) { | ||
1953 | pending = 0; /* too early */ | ||
1938 | } else | 1954 | } else |
1939 | pending++; | 1955 | pending++; |
1940 | } | 1956 | } |
@@ -2112,7 +2128,7 @@ static void azx_power_notify(struct hda_bus *bus) | |||
2112 | } | 2128 | } |
2113 | } | 2129 | } |
2114 | if (power_on) | 2130 | if (power_on) |
2115 | azx_init_chip(chip); | 2131 | azx_init_chip(chip, 1); |
2116 | else if (chip->running && power_save_controller && | 2132 | else if (chip->running && power_save_controller && |
2117 | !bus->power_keep_link_on) | 2133 | !bus->power_keep_link_on) |
2118 | azx_stop_chip(chip); | 2134 | azx_stop_chip(chip); |
@@ -2182,7 +2198,7 @@ static int azx_resume(struct pci_dev *pci) | |||
2182 | azx_init_pci(chip); | 2198 | azx_init_pci(chip); |
2183 | 2199 | ||
2184 | if (snd_hda_codecs_inuse(chip->bus)) | 2200 | if (snd_hda_codecs_inuse(chip->bus)) |
2185 | azx_init_chip(chip); | 2201 | azx_init_chip(chip, 1); |
2186 | 2202 | ||
2187 | snd_hda_resume(chip->bus); | 2203 | snd_hda_resume(chip->bus); |
2188 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | 2204 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
@@ -2431,7 +2447,8 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2431 | chip->dev_index = dev; | 2447 | chip->dev_index = dev; |
2432 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); | 2448 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); |
2433 | 2449 | ||
2434 | chip->position_fix = check_position_fix(chip, position_fix[dev]); | 2450 | chip->position_fix[0] = chip->position_fix[1] = |
2451 | check_position_fix(chip, position_fix[dev]); | ||
2435 | check_probe_mask(chip, dev); | 2452 | check_probe_mask(chip, dev); |
2436 | 2453 | ||
2437 | chip->single_cmd = single_cmd; | 2454 | chip->single_cmd = single_cmd; |
@@ -2577,7 +2594,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2577 | 2594 | ||
2578 | /* initialize chip */ | 2595 | /* initialize chip */ |
2579 | azx_init_pci(chip); | 2596 | azx_init_pci(chip); |
2580 | azx_init_chip(chip); | 2597 | azx_init_chip(chip, (probe_only[dev] & 2) == 0); |
2581 | 2598 | ||
2582 | /* codec detection */ | 2599 | /* codec detection */ |
2583 | if (!chip->codec_mask) { | 2600 | if (!chip->codec_mask) { |
@@ -2666,7 +2683,7 @@ static int __devinit azx_probe(struct pci_dev *pci, | |||
2666 | goto out_free; | 2683 | goto out_free; |
2667 | } | 2684 | } |
2668 | #endif | 2685 | #endif |
2669 | if (!probe_only[dev]) { | 2686 | if ((probe_only[dev] & 1) == 0) { |
2670 | err = azx_codec_configure(chip); | 2687 | err = azx_codec_configure(chip); |
2671 | if (err < 0) | 2688 | if (err < 0) |
2672 | goto out_free; | 2689 | goto out_free; |