diff options
Diffstat (limited to 'sound/pci/echoaudio/echoaudio.c')
-rw-r--r-- | sound/pci/echoaudio/echoaudio.c | 201 |
1 files changed, 182 insertions, 19 deletions
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index 641d7f07392c..8dab82d7d19d 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c | |||
@@ -36,22 +36,61 @@ MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard."); | |||
36 | static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999}; | 36 | static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999}; |
37 | static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1); | 37 | static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1); |
38 | 38 | ||
39 | |||
40 | |||
39 | static int get_firmware(const struct firmware **fw_entry, | 41 | static int get_firmware(const struct firmware **fw_entry, |
40 | const struct firmware *frm, struct echoaudio *chip) | 42 | struct echoaudio *chip, const short fw_index) |
41 | { | 43 | { |
42 | int err; | 44 | int err; |
43 | char name[30]; | 45 | char name[30]; |
44 | DE_ACT(("firmware requested: %s\n", frm->data)); | 46 | |
45 | snprintf(name, sizeof(name), "ea/%s", frm->data); | 47 | #ifdef CONFIG_PM |
46 | if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0) | 48 | if (chip->fw_cache[fw_index]) { |
49 | DE_ACT(("firmware requested: %s is cached\n", card_fw[fw_index].data)); | ||
50 | *fw_entry = chip->fw_cache[fw_index]; | ||
51 | return 0; | ||
52 | } | ||
53 | #endif | ||
54 | |||
55 | DE_ACT(("firmware requested: %s\n", card_fw[fw_index].data)); | ||
56 | snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data); | ||
57 | err = request_firmware(fw_entry, name, pci_device(chip)); | ||
58 | if (err < 0) | ||
47 | snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err); | 59 | snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err); |
60 | #ifdef CONFIG_PM | ||
61 | else | ||
62 | chip->fw_cache[fw_index] = *fw_entry; | ||
63 | #endif | ||
48 | return err; | 64 | return err; |
49 | } | 65 | } |
50 | 66 | ||
67 | |||
68 | |||
51 | static void free_firmware(const struct firmware *fw_entry) | 69 | static void free_firmware(const struct firmware *fw_entry) |
52 | { | 70 | { |
71 | #ifdef CONFIG_PM | ||
72 | DE_ACT(("firmware not released (kept in cache)\n")); | ||
73 | #else | ||
53 | release_firmware(fw_entry); | 74 | release_firmware(fw_entry); |
54 | DE_ACT(("firmware released\n")); | 75 | DE_ACT(("firmware released\n")); |
76 | #endif | ||
77 | } | ||
78 | |||
79 | |||
80 | |||
81 | static void free_firmware_cache(struct echoaudio *chip) | ||
82 | { | ||
83 | #ifdef CONFIG_PM | ||
84 | int i; | ||
85 | |||
86 | for (i = 0; i < 8 ; i++) | ||
87 | if (chip->fw_cache[i]) { | ||
88 | release_firmware(chip->fw_cache[i]); | ||
89 | DE_ACT(("release_firmware(%d)\n", i)); | ||
90 | } | ||
91 | |||
92 | DE_ACT(("firmware_cache released\n")); | ||
93 | #endif | ||
55 | } | 94 | } |
56 | 95 | ||
57 | 96 | ||
@@ -714,6 +753,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
714 | 753 | ||
715 | spin_lock(&chip->lock); | 754 | spin_lock(&chip->lock); |
716 | switch (cmd) { | 755 | switch (cmd) { |
756 | case SNDRV_PCM_TRIGGER_RESUME: | ||
757 | DE_ACT(("pcm_trigger resume\n")); | ||
717 | case SNDRV_PCM_TRIGGER_START: | 758 | case SNDRV_PCM_TRIGGER_START: |
718 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 759 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
719 | DE_ACT(("pcm_trigger start\n")); | 760 | DE_ACT(("pcm_trigger start\n")); |
@@ -737,6 +778,8 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) | |||
737 | err = start_transport(chip, channelmask, | 778 | err = start_transport(chip, channelmask, |
738 | chip->pipe_cyclic_mask); | 779 | chip->pipe_cyclic_mask); |
739 | break; | 780 | break; |
781 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
782 | DE_ACT(("pcm_trigger suspend\n")); | ||
740 | case SNDRV_PCM_TRIGGER_STOP: | 783 | case SNDRV_PCM_TRIGGER_STOP: |
741 | DE_ACT(("pcm_trigger stop\n")); | 784 | DE_ACT(("pcm_trigger stop\n")); |
742 | for (i = 0; i < DSP_MAXPIPES; i++) { | 785 | for (i = 0; i < DSP_MAXPIPES; i++) { |
@@ -1876,6 +1919,7 @@ static int snd_echo_free(struct echoaudio *chip) | |||
1876 | pci_disable_device(chip->pci); | 1919 | pci_disable_device(chip->pci); |
1877 | 1920 | ||
1878 | /* release chip data */ | 1921 | /* release chip data */ |
1922 | free_firmware_cache(chip); | ||
1879 | kfree(chip); | 1923 | kfree(chip); |
1880 | DE_INIT(("Chip freed.\n")); | 1924 | DE_INIT(("Chip freed.\n")); |
1881 | return 0; | 1925 | return 0; |
@@ -1913,18 +1957,27 @@ static __devinit int snd_echo_create(struct snd_card *card, | |||
1913 | return err; | 1957 | return err; |
1914 | pci_set_master(pci); | 1958 | pci_set_master(pci); |
1915 | 1959 | ||
1916 | /* allocate a chip-specific data */ | 1960 | /* Allocate chip if needed */ |
1917 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 1961 | if (!*rchip) { |
1918 | if (!chip) { | 1962 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
1919 | pci_disable_device(pci); | 1963 | if (!chip) { |
1920 | return -ENOMEM; | 1964 | pci_disable_device(pci); |
1965 | return -ENOMEM; | ||
1966 | } | ||
1967 | DE_INIT(("chip=%p\n", chip)); | ||
1968 | spin_lock_init(&chip->lock); | ||
1969 | chip->card = card; | ||
1970 | chip->pci = pci; | ||
1971 | chip->irq = -1; | ||
1972 | atomic_set(&chip->opencount, 0); | ||
1973 | mutex_init(&chip->mode_mutex); | ||
1974 | chip->can_set_rate = 1; | ||
1975 | } else { | ||
1976 | /* If this was called from the resume function, chip is | ||
1977 | * already allocated and it contains current card settings. | ||
1978 | */ | ||
1979 | chip = *rchip; | ||
1921 | } | 1980 | } |
1922 | DE_INIT(("chip=%p\n", chip)); | ||
1923 | |||
1924 | spin_lock_init(&chip->lock); | ||
1925 | chip->card = card; | ||
1926 | chip->pci = pci; | ||
1927 | chip->irq = -1; | ||
1928 | 1981 | ||
1929 | /* PCI resource allocation */ | 1982 | /* PCI resource allocation */ |
1930 | chip->dsp_registers_phys = pci_resource_start(pci, 0); | 1983 | chip->dsp_registers_phys = pci_resource_start(pci, 0); |
@@ -1964,7 +2017,9 @@ static __devinit int snd_echo_create(struct snd_card *card, | |||
1964 | chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; | 2017 | chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; |
1965 | 2018 | ||
1966 | err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); | 2019 | err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); |
1967 | if (err) { | 2020 | if (err >= 0) |
2021 | err = set_mixer_defaults(chip); | ||
2022 | if (err < 0) { | ||
1968 | DE_INIT(("init_hw err=%d\n", err)); | 2023 | DE_INIT(("init_hw err=%d\n", err)); |
1969 | snd_echo_free(chip); | 2024 | snd_echo_free(chip); |
1970 | return err; | 2025 | return err; |
@@ -1975,9 +2030,6 @@ static __devinit int snd_echo_create(struct snd_card *card, | |||
1975 | snd_echo_free(chip); | 2030 | snd_echo_free(chip); |
1976 | return err; | 2031 | return err; |
1977 | } | 2032 | } |
1978 | atomic_set(&chip->opencount, 0); | ||
1979 | mutex_init(&chip->mode_mutex); | ||
1980 | chip->can_set_rate = 1; | ||
1981 | *rchip = chip; | 2033 | *rchip = chip; |
1982 | /* Init done ! */ | 2034 | /* Init done ! */ |
1983 | return 0; | 2035 | return 0; |
@@ -2010,6 +2062,7 @@ static int __devinit snd_echo_probe(struct pci_dev *pci, | |||
2010 | 2062 | ||
2011 | snd_card_set_dev(card, &pci->dev); | 2063 | snd_card_set_dev(card, &pci->dev); |
2012 | 2064 | ||
2065 | chip = NULL; /* Tells snd_echo_create to allocate chip */ | ||
2013 | if ((err = snd_echo_create(card, pci, &chip)) < 0) { | 2066 | if ((err = snd_echo_create(card, pci, &chip)) < 0) { |
2014 | snd_card_free(card); | 2067 | snd_card_free(card); |
2015 | return err; | 2068 | return err; |
@@ -2149,6 +2202,112 @@ ctl_error: | |||
2149 | 2202 | ||
2150 | 2203 | ||
2151 | 2204 | ||
2205 | #if defined(CONFIG_PM) | ||
2206 | |||
2207 | static int snd_echo_suspend(struct pci_dev *pci, pm_message_t state) | ||
2208 | { | ||
2209 | struct echoaudio *chip = pci_get_drvdata(pci); | ||
2210 | |||
2211 | DE_INIT(("suspend start\n")); | ||
2212 | snd_pcm_suspend_all(chip->analog_pcm); | ||
2213 | snd_pcm_suspend_all(chip->digital_pcm); | ||
2214 | |||
2215 | #ifdef ECHOCARD_HAS_MIDI | ||
2216 | /* This call can sleep */ | ||
2217 | if (chip->midi_out) | ||
2218 | snd_echo_midi_output_trigger(chip->midi_out, 0); | ||
2219 | #endif | ||
2220 | spin_lock_irq(&chip->lock); | ||
2221 | if (wait_handshake(chip)) { | ||
2222 | spin_unlock_irq(&chip->lock); | ||
2223 | return -EIO; | ||
2224 | } | ||
2225 | clear_handshake(chip); | ||
2226 | if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) { | ||
2227 | spin_unlock_irq(&chip->lock); | ||
2228 | return -EIO; | ||
2229 | } | ||
2230 | spin_unlock_irq(&chip->lock); | ||
2231 | |||
2232 | chip->dsp_code = NULL; | ||
2233 | free_irq(chip->irq, chip); | ||
2234 | chip->irq = -1; | ||
2235 | pci_save_state(pci); | ||
2236 | pci_disable_device(pci); | ||
2237 | |||
2238 | DE_INIT(("suspend done\n")); | ||
2239 | return 0; | ||
2240 | } | ||
2241 | |||
2242 | |||
2243 | |||
2244 | static int snd_echo_resume(struct pci_dev *pci) | ||
2245 | { | ||
2246 | struct echoaudio *chip = pci_get_drvdata(pci); | ||
2247 | struct comm_page *commpage, *commpage_bak; | ||
2248 | u32 pipe_alloc_mask; | ||
2249 | int err; | ||
2250 | |||
2251 | DE_INIT(("resume start\n")); | ||
2252 | pci_restore_state(pci); | ||
2253 | commpage_bak = kmalloc(sizeof(struct echoaudio), GFP_KERNEL); | ||
2254 | commpage = chip->comm_page; | ||
2255 | memcpy(commpage_bak, commpage, sizeof(struct comm_page)); | ||
2256 | |||
2257 | err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); | ||
2258 | if (err < 0) { | ||
2259 | kfree(commpage_bak); | ||
2260 | DE_INIT(("resume init_hw err=%d\n", err)); | ||
2261 | snd_echo_free(chip); | ||
2262 | return err; | ||
2263 | } | ||
2264 | DE_INIT(("resume init OK\n")); | ||
2265 | |||
2266 | /* Temporarily set chip->pipe_alloc_mask=0 otherwise | ||
2267 | * restore_dsp_settings() fails. | ||
2268 | */ | ||
2269 | pipe_alloc_mask = chip->pipe_alloc_mask; | ||
2270 | chip->pipe_alloc_mask = 0; | ||
2271 | err = restore_dsp_rettings(chip); | ||
2272 | chip->pipe_alloc_mask = pipe_alloc_mask; | ||
2273 | if (err < 0) { | ||
2274 | kfree(commpage_bak); | ||
2275 | return err; | ||
2276 | } | ||
2277 | DE_INIT(("resume restore OK\n")); | ||
2278 | |||
2279 | memcpy(&commpage->audio_format, &commpage_bak->audio_format, | ||
2280 | sizeof(commpage->audio_format)); | ||
2281 | memcpy(&commpage->sglist_addr, &commpage_bak->sglist_addr, | ||
2282 | sizeof(commpage->sglist_addr)); | ||
2283 | memcpy(&commpage->midi_output, &commpage_bak->midi_output, | ||
2284 | sizeof(commpage->midi_output)); | ||
2285 | kfree(commpage_bak); | ||
2286 | |||
2287 | if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, | ||
2288 | ECHOCARD_NAME, chip)) { | ||
2289 | snd_echo_free(chip); | ||
2290 | snd_printk(KERN_ERR "cannot grab irq\n"); | ||
2291 | return -EBUSY; | ||
2292 | } | ||
2293 | chip->irq = pci->irq; | ||
2294 | DE_INIT(("resume irq=%d\n", chip->irq)); | ||
2295 | |||
2296 | #ifdef ECHOCARD_HAS_MIDI | ||
2297 | if (chip->midi_input_enabled) | ||
2298 | enable_midi_input(chip, TRUE); | ||
2299 | if (chip->midi_out) | ||
2300 | snd_echo_midi_output_trigger(chip->midi_out, 1); | ||
2301 | #endif | ||
2302 | |||
2303 | DE_INIT(("resume done\n")); | ||
2304 | return 0; | ||
2305 | } | ||
2306 | |||
2307 | #endif /* CONFIG_PM */ | ||
2308 | |||
2309 | |||
2310 | |||
2152 | static void __devexit snd_echo_remove(struct pci_dev *pci) | 2311 | static void __devexit snd_echo_remove(struct pci_dev *pci) |
2153 | { | 2312 | { |
2154 | struct echoaudio *chip; | 2313 | struct echoaudio *chip; |
@@ -2171,6 +2330,10 @@ static struct pci_driver driver = { | |||
2171 | .id_table = snd_echo_ids, | 2330 | .id_table = snd_echo_ids, |
2172 | .probe = snd_echo_probe, | 2331 | .probe = snd_echo_probe, |
2173 | .remove = __devexit_p(snd_echo_remove), | 2332 | .remove = __devexit_p(snd_echo_remove), |
2333 | #ifdef CONFIG_PM | ||
2334 | .suspend = snd_echo_suspend, | ||
2335 | .resume = snd_echo_resume, | ||
2336 | #endif /* CONFIG_PM */ | ||
2174 | }; | 2337 | }; |
2175 | 2338 | ||
2176 | 2339 | ||