diff options
author | Dylan Reid <dgreid@chromium.org> | 2014-02-28 18:41:30 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-03-01 05:23:33 -0500 |
commit | 154867cf4ea8307d7acac2dcf7952873105ceb1c (patch) | |
tree | ef938cf82c67f893c710e7eb7b225cea23ac11fb /sound/pci | |
parent | f0b1df88713a3537e056658d860f6631653ec5c6 (diff) |
ALSA: hda - Move codec create to hda_controller
Codec creation and stream initialization can be shared between
hda_intel and hda platform drivers. Move it and the static functions
it depends on to hda_controller.c.
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/hda/hda_controller.c | 239 | ||||
-rw-r--r-- | sound/pci/hda/hda_controller.h | 26 | ||||
-rw-r--r-- | sound/pci/hda/hda_intel.c | 218 |
3 files changed, 235 insertions, 248 deletions
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 43b99b495347..6156d0a2c0f9 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/pm_runtime.h> | ||
28 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
29 | #include <sound/core.h> | 30 | #include <sound/core.h> |
30 | #include <sound/initval.h> | 31 | #include <sound/initval.h> |
@@ -1022,7 +1023,6 @@ int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | |||
1022 | pcm->dev = &codec->dev; | 1023 | pcm->dev = &codec->dev; |
1023 | return 0; | 1024 | return 0; |
1024 | } | 1025 | } |
1025 | EXPORT_SYMBOL_GPL(azx_attach_pcm_stream); | ||
1026 | 1026 | ||
1027 | /* | 1027 | /* |
1028 | * CORB / RIRB interface | 1028 | * CORB / RIRB interface |
@@ -1380,7 +1380,7 @@ static unsigned int azx_single_get_response(struct hda_bus *bus, | |||
1380 | */ | 1380 | */ |
1381 | 1381 | ||
1382 | /* send a command */ | 1382 | /* send a command */ |
1383 | int azx_send_cmd(struct hda_bus *bus, unsigned int val) | 1383 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) |
1384 | { | 1384 | { |
1385 | struct azx *chip = bus->private_data; | 1385 | struct azx *chip = bus->private_data; |
1386 | 1386 | ||
@@ -1395,7 +1395,7 @@ int azx_send_cmd(struct hda_bus *bus, unsigned int val) | |||
1395 | EXPORT_SYMBOL_GPL(azx_send_cmd); | 1395 | EXPORT_SYMBOL_GPL(azx_send_cmd); |
1396 | 1396 | ||
1397 | /* get a response */ | 1397 | /* get a response */ |
1398 | unsigned int azx_get_response(struct hda_bus *bus, | 1398 | static unsigned int azx_get_response(struct hda_bus *bus, |
1399 | unsigned int addr) | 1399 | unsigned int addr) |
1400 | { | 1400 | { |
1401 | struct azx *chip = bus->private_data; | 1401 | struct azx *chip = bus->private_data; |
@@ -1420,9 +1420,9 @@ azx_get_dsp_loader_dev(struct azx *chip) | |||
1420 | return &chip->azx_dev[chip->playback_index_offset]; | 1420 | return &chip->azx_dev[chip->playback_index_offset]; |
1421 | } | 1421 | } |
1422 | 1422 | ||
1423 | int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, | 1423 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, |
1424 | unsigned int byte_size, | 1424 | unsigned int byte_size, |
1425 | struct snd_dma_buffer *bufp) | 1425 | struct snd_dma_buffer *bufp) |
1426 | { | 1426 | { |
1427 | u32 *bdl; | 1427 | u32 *bdl; |
1428 | struct azx *chip = bus->private_data; | 1428 | struct azx *chip = bus->private_data; |
@@ -1480,9 +1480,8 @@ int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, | |||
1480 | dsp_unlock(azx_dev); | 1480 | dsp_unlock(azx_dev); |
1481 | return err; | 1481 | return err; |
1482 | } | 1482 | } |
1483 | EXPORT_SYMBOL_GPL(azx_load_dsp_prepare); | ||
1484 | 1483 | ||
1485 | void azx_load_dsp_trigger(struct hda_bus *bus, bool start) | 1484 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start) |
1486 | { | 1485 | { |
1487 | struct azx *chip = bus->private_data; | 1486 | struct azx *chip = bus->private_data; |
1488 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); | 1487 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
@@ -1493,10 +1492,9 @@ void azx_load_dsp_trigger(struct hda_bus *bus, bool start) | |||
1493 | azx_stream_stop(chip, azx_dev); | 1492 | azx_stream_stop(chip, azx_dev); |
1494 | azx_dev->running = start; | 1493 | azx_dev->running = start; |
1495 | } | 1494 | } |
1496 | EXPORT_SYMBOL_GPL(azx_load_dsp_trigger); | ||
1497 | 1495 | ||
1498 | void azx_load_dsp_cleanup(struct hda_bus *bus, | 1496 | static void azx_load_dsp_cleanup(struct hda_bus *bus, |
1499 | struct snd_dma_buffer *dmab) | 1497 | struct snd_dma_buffer *dmab) |
1500 | { | 1498 | { |
1501 | struct azx *chip = bus->private_data; | 1499 | struct azx *chip = bus->private_data; |
1502 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); | 1500 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
@@ -1523,7 +1521,6 @@ void azx_load_dsp_cleanup(struct hda_bus *bus, | |||
1523 | spin_unlock_irq(&chip->reg_lock); | 1521 | spin_unlock_irq(&chip->reg_lock); |
1524 | dsp_unlock(azx_dev); | 1522 | dsp_unlock(azx_dev); |
1525 | } | 1523 | } |
1526 | EXPORT_SYMBOL_GPL(azx_load_dsp_cleanup); | ||
1527 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ | 1524 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
1528 | 1525 | ||
1529 | int azx_alloc_stream_pages(struct azx *chip) | 1526 | int azx_alloc_stream_pages(struct azx *chip) |
@@ -1746,6 +1743,7 @@ void azx_stop_chip(struct azx *chip) | |||
1746 | 1743 | ||
1747 | chip->initialized = 0; | 1744 | chip->initialized = 0; |
1748 | } | 1745 | } |
1746 | EXPORT_SYMBOL_GPL(azx_stop_chip); | ||
1749 | 1747 | ||
1750 | /* | 1748 | /* |
1751 | * interrupt handler | 1749 | * interrupt handler |
@@ -1812,5 +1810,222 @@ irqreturn_t azx_interrupt(int irq, void *dev_id) | |||
1812 | } | 1810 | } |
1813 | EXPORT_SYMBOL_GPL(azx_interrupt); | 1811 | EXPORT_SYMBOL_GPL(azx_interrupt); |
1814 | 1812 | ||
1813 | /* | ||
1814 | * Codec initerface | ||
1815 | */ | ||
1816 | |||
1817 | /* | ||
1818 | * Probe the given codec address | ||
1819 | */ | ||
1820 | static int probe_codec(struct azx *chip, int addr) | ||
1821 | { | ||
1822 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | | ||
1823 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | ||
1824 | unsigned int res; | ||
1825 | |||
1826 | mutex_lock(&chip->bus->cmd_mutex); | ||
1827 | chip->probing = 1; | ||
1828 | azx_send_cmd(chip->bus, cmd); | ||
1829 | res = azx_get_response(chip->bus, addr); | ||
1830 | chip->probing = 0; | ||
1831 | mutex_unlock(&chip->bus->cmd_mutex); | ||
1832 | if (res == -1) | ||
1833 | return -EIO; | ||
1834 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); | ||
1835 | return 0; | ||
1836 | } | ||
1837 | |||
1838 | static void azx_bus_reset(struct hda_bus *bus) | ||
1839 | { | ||
1840 | struct azx *chip = bus->private_data; | ||
1841 | |||
1842 | bus->in_reset = 1; | ||
1843 | azx_stop_chip(chip); | ||
1844 | azx_init_chip(chip, 1); | ||
1845 | #ifdef CONFIG_PM | ||
1846 | if (chip->initialized) { | ||
1847 | struct azx_pcm *p; | ||
1848 | list_for_each_entry(p, &chip->pcm_list, list) | ||
1849 | snd_pcm_suspend_all(p->pcm); | ||
1850 | snd_hda_suspend(chip->bus); | ||
1851 | snd_hda_resume(chip->bus); | ||
1852 | } | ||
1853 | #endif | ||
1854 | bus->in_reset = 0; | ||
1855 | } | ||
1856 | |||
1857 | #ifdef CONFIG_PM | ||
1858 | /* power-up/down the controller */ | ||
1859 | static void azx_power_notify(struct hda_bus *bus, bool power_up) | ||
1860 | { | ||
1861 | struct azx *chip = bus->private_data; | ||
1862 | |||
1863 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) | ||
1864 | return; | ||
1865 | |||
1866 | if (power_up) | ||
1867 | pm_runtime_get_sync(chip->card->dev); | ||
1868 | else | ||
1869 | pm_runtime_put_sync(chip->card->dev); | ||
1870 | } | ||
1871 | #endif | ||
1872 | |||
1873 | static int get_jackpoll_interval(struct azx *chip) | ||
1874 | { | ||
1875 | int i; | ||
1876 | unsigned int j; | ||
1877 | |||
1878 | if (!chip->jackpoll_ms) | ||
1879 | return 0; | ||
1880 | |||
1881 | i = chip->jackpoll_ms[chip->dev_index]; | ||
1882 | if (i == 0) | ||
1883 | return 0; | ||
1884 | if (i < 50 || i > 60000) | ||
1885 | j = 0; | ||
1886 | else | ||
1887 | j = msecs_to_jiffies(i); | ||
1888 | if (j == 0) | ||
1889 | dev_warn(chip->card->dev, | ||
1890 | "jackpoll_ms value out of range: %d\n", i); | ||
1891 | return j; | ||
1892 | } | ||
1893 | |||
1894 | /* Codec initialization */ | ||
1895 | int azx_codec_create(struct azx *chip, const char *model, | ||
1896 | unsigned int max_slots, | ||
1897 | int *power_save_to) | ||
1898 | { | ||
1899 | struct hda_bus_template bus_temp; | ||
1900 | int c, codecs, err; | ||
1901 | |||
1902 | memset(&bus_temp, 0, sizeof(bus_temp)); | ||
1903 | bus_temp.private_data = chip; | ||
1904 | bus_temp.modelname = model; | ||
1905 | bus_temp.pci = chip->pci; | ||
1906 | bus_temp.ops.command = azx_send_cmd; | ||
1907 | bus_temp.ops.get_response = azx_get_response; | ||
1908 | bus_temp.ops.attach_pcm = azx_attach_pcm_stream; | ||
1909 | bus_temp.ops.bus_reset = azx_bus_reset; | ||
1910 | #ifdef CONFIG_PM | ||
1911 | bus_temp.power_save = power_save_to; | ||
1912 | bus_temp.ops.pm_notify = azx_power_notify; | ||
1913 | #endif | ||
1914 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
1915 | bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; | ||
1916 | bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; | ||
1917 | bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; | ||
1918 | #endif | ||
1919 | |||
1920 | err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); | ||
1921 | if (err < 0) | ||
1922 | return err; | ||
1923 | |||
1924 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { | ||
1925 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); | ||
1926 | chip->bus->needs_damn_long_delay = 1; | ||
1927 | } | ||
1928 | |||
1929 | codecs = 0; | ||
1930 | if (!max_slots) | ||
1931 | max_slots = AZX_DEFAULT_CODECS; | ||
1932 | |||
1933 | /* First try to probe all given codec slots */ | ||
1934 | for (c = 0; c < max_slots; c++) { | ||
1935 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | ||
1936 | if (probe_codec(chip, c) < 0) { | ||
1937 | /* Some BIOSen give you wrong codec addresses | ||
1938 | * that don't exist | ||
1939 | */ | ||
1940 | dev_warn(chip->card->dev, | ||
1941 | "Codec #%d probe error; disabling it...\n", c); | ||
1942 | chip->codec_mask &= ~(1 << c); | ||
1943 | /* More badly, accessing to a non-existing | ||
1944 | * codec often screws up the controller chip, | ||
1945 | * and disturbs the further communications. | ||
1946 | * Thus if an error occurs during probing, | ||
1947 | * better to reset the controller chip to | ||
1948 | * get back to the sanity state. | ||
1949 | */ | ||
1950 | azx_stop_chip(chip); | ||
1951 | azx_init_chip(chip, 1); | ||
1952 | } | ||
1953 | } | ||
1954 | } | ||
1955 | |||
1956 | /* AMD chipsets often cause the communication stalls upon certain | ||
1957 | * sequence like the pin-detection. It seems that forcing the synced | ||
1958 | * access works around the stall. Grrr... | ||
1959 | */ | ||
1960 | if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { | ||
1961 | dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); | ||
1962 | chip->bus->sync_write = 1; | ||
1963 | chip->bus->allow_bus_reset = 1; | ||
1964 | } | ||
1965 | |||
1966 | /* Then create codec instances */ | ||
1967 | for (c = 0; c < max_slots; c++) { | ||
1968 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | ||
1969 | struct hda_codec *codec; | ||
1970 | err = snd_hda_codec_new(chip->bus, c, &codec); | ||
1971 | if (err < 0) | ||
1972 | continue; | ||
1973 | codec->jackpoll_interval = get_jackpoll_interval(chip); | ||
1974 | codec->beep_mode = chip->beep_mode; | ||
1975 | codecs++; | ||
1976 | } | ||
1977 | } | ||
1978 | if (!codecs) { | ||
1979 | dev_err(chip->card->dev, "no codecs initialized\n"); | ||
1980 | return -ENXIO; | ||
1981 | } | ||
1982 | return 0; | ||
1983 | } | ||
1984 | EXPORT_SYMBOL_GPL(azx_codec_create); | ||
1985 | |||
1986 | /* configure each codec instance */ | ||
1987 | int azx_codec_configure(struct azx *chip) | ||
1988 | { | ||
1989 | struct hda_codec *codec; | ||
1990 | list_for_each_entry(codec, &chip->bus->codec_list, list) { | ||
1991 | snd_hda_codec_configure(codec); | ||
1992 | } | ||
1993 | return 0; | ||
1994 | } | ||
1995 | EXPORT_SYMBOL_GPL(azx_codec_configure); | ||
1996 | |||
1997 | /* mixer creation - all stuff is implemented in hda module */ | ||
1998 | int azx_mixer_create(struct azx *chip) | ||
1999 | { | ||
2000 | return snd_hda_build_controls(chip->bus); | ||
2001 | } | ||
2002 | EXPORT_SYMBOL_GPL(azx_mixer_create); | ||
2003 | |||
2004 | |||
2005 | /* initialize SD streams */ | ||
2006 | int azx_init_stream(struct azx *chip) | ||
2007 | { | ||
2008 | int i; | ||
2009 | |||
2010 | /* initialize each stream (aka device) | ||
2011 | * assign the starting bdl address to each stream (device) | ||
2012 | * and initialize | ||
2013 | */ | ||
2014 | for (i = 0; i < chip->num_streams; i++) { | ||
2015 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | ||
2016 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); | ||
2017 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | ||
2018 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); | ||
2019 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ | ||
2020 | azx_dev->sd_int_sta_mask = 1 << i; | ||
2021 | /* stream tag: must be non-zero and unique */ | ||
2022 | azx_dev->index = i; | ||
2023 | azx_dev->stream_tag = i + 1; | ||
2024 | } | ||
2025 | |||
2026 | return 0; | ||
2027 | } | ||
2028 | EXPORT_SYMBOL_GPL(azx_init_stream); | ||
2029 | |||
1815 | MODULE_LICENSE("GPL"); | 2030 | MODULE_LICENSE("GPL"); |
1816 | MODULE_DESCRIPTION("Common HDA driver funcitons"); | 2031 | MODULE_DESCRIPTION("Common HDA driver funcitons"); |
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index fac929948f19..1d2e3be2bae6 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h | |||
@@ -21,8 +21,6 @@ | |||
21 | #include "hda_priv.h" | 21 | #include "hda_priv.h" |
22 | 22 | ||
23 | /* PCM setup */ | 23 | /* PCM setup */ |
24 | int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, | ||
25 | struct hda_pcm *cpcm); | ||
26 | static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) | 24 | static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream) |
27 | { | 25 | { |
28 | return substream->runtime->private_data; | 26 | return substream->runtime->private_data; |
@@ -34,30 +32,22 @@ unsigned int azx_get_position(struct azx *chip, | |||
34 | /* Stream control. */ | 32 | /* Stream control. */ |
35 | void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev); | 33 | void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev); |
36 | 34 | ||
37 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
38 | int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, | ||
39 | unsigned int byte_size, | ||
40 | struct snd_dma_buffer *bufp); | ||
41 | void azx_load_dsp_trigger(struct hda_bus *bus, bool start); | ||
42 | void azx_load_dsp_cleanup(struct hda_bus *bus, | ||
43 | struct snd_dma_buffer *dmab); | ||
44 | #endif | ||
45 | |||
46 | /* Allocation functions. */ | 35 | /* Allocation functions. */ |
47 | int azx_alloc_stream_pages(struct azx *chip); | 36 | int azx_alloc_stream_pages(struct azx *chip); |
48 | void azx_free_stream_pages(struct azx *chip); | 37 | void azx_free_stream_pages(struct azx *chip); |
49 | 38 | ||
50 | /* | ||
51 | * CORB / RIRB interface | ||
52 | */ | ||
53 | int azx_send_cmd(struct hda_bus *bus, unsigned int val); | ||
54 | unsigned int azx_get_response(struct hda_bus *bus, | ||
55 | unsigned int addr); | ||
56 | |||
57 | /* Low level azx interface */ | 39 | /* Low level azx interface */ |
58 | void azx_init_chip(struct azx *chip, int full_reset); | 40 | void azx_init_chip(struct azx *chip, int full_reset); |
59 | void azx_stop_chip(struct azx *chip); | 41 | void azx_stop_chip(struct azx *chip); |
60 | void azx_enter_link_reset(struct azx *chip); | 42 | void azx_enter_link_reset(struct azx *chip); |
61 | irqreturn_t azx_interrupt(int irq, void *dev_id); | 43 | irqreturn_t azx_interrupt(int irq, void *dev_id); |
62 | 44 | ||
45 | /* Codec interface */ | ||
46 | int azx_codec_create(struct azx *chip, const char *model, | ||
47 | unsigned int max_slots, | ||
48 | int *power_save_to); | ||
49 | int azx_codec_configure(struct azx *chip); | ||
50 | int azx_mixer_create(struct azx *chip); | ||
51 | int azx_init_stream(struct azx *chip); | ||
52 | |||
63 | #endif /* __SOUND_HDA_CONTROLLER_H */ | 53 | #endif /* __SOUND_HDA_CONTROLLER_H */ |
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 96c22a3a2dc0..b26eff3edfc1 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -336,10 +336,6 @@ static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev, | |||
336 | 336 | ||
337 | static int azx_acquire_irq(struct azx *chip, int do_disconnect); | 337 | static int azx_acquire_irq(struct azx *chip, int do_disconnect); |
338 | 338 | ||
339 | #ifdef CONFIG_PM | ||
340 | static void azx_power_notify(struct hda_bus *bus, bool power_up); | ||
341 | #endif | ||
342 | |||
343 | /* | 339 | /* |
344 | * initialize the PCI registers | 340 | * initialize the PCI registers |
345 | */ | 341 | */ |
@@ -433,171 +429,6 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev) | |||
433 | } | 429 | } |
434 | 430 | ||
435 | /* | 431 | /* |
436 | * Probe the given codec address | ||
437 | */ | ||
438 | static int probe_codec(struct azx *chip, int addr) | ||
439 | { | ||
440 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | | ||
441 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | ||
442 | unsigned int res; | ||
443 | |||
444 | mutex_lock(&chip->bus->cmd_mutex); | ||
445 | chip->probing = 1; | ||
446 | azx_send_cmd(chip->bus, cmd); | ||
447 | res = azx_get_response(chip->bus, addr); | ||
448 | chip->probing = 0; | ||
449 | mutex_unlock(&chip->bus->cmd_mutex); | ||
450 | if (res == -1) | ||
451 | return -EIO; | ||
452 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | static void azx_bus_reset(struct hda_bus *bus) | ||
457 | { | ||
458 | struct azx *chip = bus->private_data; | ||
459 | |||
460 | bus->in_reset = 1; | ||
461 | azx_stop_chip(chip); | ||
462 | azx_init_chip(chip, 1); | ||
463 | #ifdef CONFIG_PM | ||
464 | if (chip->initialized) { | ||
465 | struct azx_pcm *p; | ||
466 | list_for_each_entry(p, &chip->pcm_list, list) | ||
467 | snd_pcm_suspend_all(p->pcm); | ||
468 | snd_hda_suspend(chip->bus); | ||
469 | snd_hda_resume(chip->bus); | ||
470 | } | ||
471 | #endif | ||
472 | bus->in_reset = 0; | ||
473 | } | ||
474 | |||
475 | static int get_jackpoll_interval(struct azx *chip) | ||
476 | { | ||
477 | int i; | ||
478 | unsigned int j; | ||
479 | |||
480 | if (!chip->jackpoll_ms) | ||
481 | return 0; | ||
482 | |||
483 | i = chip->jackpoll_ms[chip->dev_index]; | ||
484 | if (i == 0) | ||
485 | return 0; | ||
486 | if (i < 50 || i > 60000) | ||
487 | j = 0; | ||
488 | else | ||
489 | j = msecs_to_jiffies(i); | ||
490 | if (j == 0) | ||
491 | dev_warn(chip->card->dev, | ||
492 | "jackpoll_ms value out of range: %d\n", i); | ||
493 | return j; | ||
494 | } | ||
495 | |||
496 | /* | ||
497 | * Codec initialization | ||
498 | */ | ||
499 | |||
500 | static int azx_codec_create(struct azx *chip, const char *model, | ||
501 | unsigned int max_slots, | ||
502 | int *power_save_to) | ||
503 | { | ||
504 | struct hda_bus_template bus_temp; | ||
505 | int c, codecs, err; | ||
506 | |||
507 | memset(&bus_temp, 0, sizeof(bus_temp)); | ||
508 | bus_temp.private_data = chip; | ||
509 | bus_temp.modelname = model; | ||
510 | bus_temp.pci = chip->pci; | ||
511 | bus_temp.ops.command = azx_send_cmd; | ||
512 | bus_temp.ops.get_response = azx_get_response; | ||
513 | bus_temp.ops.attach_pcm = azx_attach_pcm_stream; | ||
514 | bus_temp.ops.bus_reset = azx_bus_reset; | ||
515 | #ifdef CONFIG_PM | ||
516 | bus_temp.power_save = power_save_to; | ||
517 | bus_temp.ops.pm_notify = azx_power_notify; | ||
518 | #endif | ||
519 | #ifdef CONFIG_SND_HDA_DSP_LOADER | ||
520 | bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; | ||
521 | bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; | ||
522 | bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; | ||
523 | #endif | ||
524 | |||
525 | err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); | ||
526 | if (err < 0) | ||
527 | return err; | ||
528 | |||
529 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { | ||
530 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); | ||
531 | chip->bus->needs_damn_long_delay = 1; | ||
532 | } | ||
533 | |||
534 | codecs = 0; | ||
535 | if (!max_slots) | ||
536 | max_slots = AZX_DEFAULT_CODECS; | ||
537 | |||
538 | /* First try to probe all given codec slots */ | ||
539 | for (c = 0; c < max_slots; c++) { | ||
540 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | ||
541 | if (probe_codec(chip, c) < 0) { | ||
542 | /* Some BIOSen give you wrong codec addresses | ||
543 | * that don't exist | ||
544 | */ | ||
545 | dev_warn(chip->card->dev, | ||
546 | "Codec #%d probe error; disabling it...\n", c); | ||
547 | chip->codec_mask &= ~(1 << c); | ||
548 | /* More badly, accessing to a non-existing | ||
549 | * codec often screws up the controller chip, | ||
550 | * and disturbs the further communications. | ||
551 | * Thus if an error occurs during probing, | ||
552 | * better to reset the controller chip to | ||
553 | * get back to the sanity state. | ||
554 | */ | ||
555 | azx_stop_chip(chip); | ||
556 | azx_init_chip(chip, 1); | ||
557 | } | ||
558 | } | ||
559 | } | ||
560 | |||
561 | /* AMD chipsets often cause the communication stalls upon certain | ||
562 | * sequence like the pin-detection. It seems that forcing the synced | ||
563 | * access works around the stall. Grrr... | ||
564 | */ | ||
565 | if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { | ||
566 | dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); | ||
567 | chip->bus->sync_write = 1; | ||
568 | chip->bus->allow_bus_reset = 1; | ||
569 | } | ||
570 | |||
571 | /* Then create codec instances */ | ||
572 | for (c = 0; c < max_slots; c++) { | ||
573 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { | ||
574 | struct hda_codec *codec; | ||
575 | err = snd_hda_codec_new(chip->bus, c, &codec); | ||
576 | if (err < 0) | ||
577 | continue; | ||
578 | codec->jackpoll_interval = get_jackpoll_interval(chip); | ||
579 | codec->beep_mode = chip->beep_mode; | ||
580 | codecs++; | ||
581 | } | ||
582 | } | ||
583 | if (!codecs) { | ||
584 | dev_err(chip->card->dev, "no codecs initialized\n"); | ||
585 | return -ENXIO; | ||
586 | } | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | /* configure each codec instance */ | ||
591 | static int azx_codec_configure(struct azx *chip) | ||
592 | { | ||
593 | struct hda_codec *codec; | ||
594 | list_for_each_entry(codec, &chip->bus->codec_list, list) { | ||
595 | snd_hda_codec_configure(codec); | ||
596 | } | ||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | /* | ||
601 | * Check whether the current DMA position is acceptable for updating | 432 | * Check whether the current DMA position is acceptable for updating |
602 | * periods. Returns non-zero if it's OK. | 433 | * periods. Returns non-zero if it's OK. |
603 | * | 434 | * |
@@ -681,41 +512,6 @@ static void azx_clear_irq_pending(struct azx *chip) | |||
681 | spin_unlock_irq(&chip->reg_lock); | 512 | spin_unlock_irq(&chip->reg_lock); |
682 | } | 513 | } |
683 | 514 | ||
684 | /* | ||
685 | * mixer creation - all stuff is implemented in hda module | ||
686 | */ | ||
687 | static int azx_mixer_create(struct azx *chip) | ||
688 | { | ||
689 | return snd_hda_build_controls(chip->bus); | ||
690 | } | ||
691 | |||
692 | |||
693 | /* | ||
694 | * initialize SD streams | ||
695 | */ | ||
696 | static int azx_init_stream(struct azx *chip) | ||
697 | { | ||
698 | int i; | ||
699 | |||
700 | /* initialize each stream (aka device) | ||
701 | * assign the starting bdl address to each stream (device) | ||
702 | * and initialize | ||
703 | */ | ||
704 | for (i = 0; i < chip->num_streams; i++) { | ||
705 | struct azx_dev *azx_dev = &chip->azx_dev[i]; | ||
706 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); | ||
707 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ | ||
708 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); | ||
709 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ | ||
710 | azx_dev->sd_int_sta_mask = 1 << i; | ||
711 | /* stream tag: must be non-zero and unique */ | ||
712 | azx_dev->index = i; | ||
713 | azx_dev->stream_tag = i + 1; | ||
714 | } | ||
715 | |||
716 | return 0; | ||
717 | } | ||
718 | |||
719 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) | 515 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) |
720 | { | 516 | { |
721 | if (request_irq(chip->pci->irq, azx_interrupt, | 517 | if (request_irq(chip->pci->irq, azx_interrupt, |
@@ -734,20 +530,6 @@ static int azx_acquire_irq(struct azx *chip, int do_disconnect) | |||
734 | } | 530 | } |
735 | 531 | ||
736 | #ifdef CONFIG_PM | 532 | #ifdef CONFIG_PM |
737 | /* power-up/down the controller */ | ||
738 | static void azx_power_notify(struct hda_bus *bus, bool power_up) | ||
739 | { | ||
740 | struct azx *chip = bus->private_data; | ||
741 | |||
742 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) | ||
743 | return; | ||
744 | |||
745 | if (power_up) | ||
746 | pm_runtime_get_sync(chip->card->dev); | ||
747 | else | ||
748 | pm_runtime_put_sync(chip->card->dev); | ||
749 | } | ||
750 | |||
751 | static DEFINE_MUTEX(card_list_lock); | 533 | static DEFINE_MUTEX(card_list_lock); |
752 | static LIST_HEAD(card_list); | 534 | static LIST_HEAD(card_list); |
753 | 535 | ||