aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/echoaudio/echoaudio.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/echoaudio/echoaudio.c')
-rw-r--r--sound/pci/echoaudio/echoaudio.c205
1 files changed, 185 insertions, 20 deletions
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 1305f7ca02c3..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.");
36static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999}; 36static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
37static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1); 37static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);
38 38
39
40
39static int get_firmware(const struct firmware **fw_entry, 41static 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
51static void free_firmware(const struct firmware *fw_entry) 69static 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
81static 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++) {
@@ -1821,7 +1864,9 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1821 /* The hardware doesn't tell us which substream caused the irq, 1864 /* The hardware doesn't tell us which substream caused the irq,
1822 thus we have to check all running substreams. */ 1865 thus we have to check all running substreams. */
1823 for (ss = 0; ss < DSP_MAXPIPES; ss++) { 1866 for (ss = 0; ss < DSP_MAXPIPES; ss++) {
1824 if ((substream = chip->substream[ss])) { 1867 substream = chip->substream[ss];
1868 if (substream && ((struct audiopipe *)substream->runtime->
1869 private_data)->state == PIPE_STATE_STARTED) {
1825 period = pcm_pointer(substream) / 1870 period = pcm_pointer(substream) /
1826 substream->runtime->period_size; 1871 substream->runtime->period_size;
1827 if (period != chip->last_period[ss]) { 1872 if (period != chip->last_period[ss]) {
@@ -1874,6 +1919,7 @@ static int snd_echo_free(struct echoaudio *chip)
1874 pci_disable_device(chip->pci); 1919 pci_disable_device(chip->pci);
1875 1920
1876 /* release chip data */ 1921 /* release chip data */
1922 free_firmware_cache(chip);
1877 kfree(chip); 1923 kfree(chip);
1878 DE_INIT(("Chip freed.\n")); 1924 DE_INIT(("Chip freed.\n"));
1879 return 0; 1925 return 0;
@@ -1911,18 +1957,27 @@ static __devinit int snd_echo_create(struct snd_card *card,
1911 return err; 1957 return err;
1912 pci_set_master(pci); 1958 pci_set_master(pci);
1913 1959
1914 /* allocate a chip-specific data */ 1960 /* Allocate chip if needed */
1915 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1961 if (!*rchip) {
1916 if (!chip) { 1962 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1917 pci_disable_device(pci); 1963 if (!chip) {
1918 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;
1919 } 1980 }
1920 DE_INIT(("chip=%p\n", chip));
1921
1922 spin_lock_init(&chip->lock);
1923 chip->card = card;
1924 chip->pci = pci;
1925 chip->irq = -1;
1926 1981
1927 /* PCI resource allocation */ 1982 /* PCI resource allocation */
1928 chip->dsp_registers_phys = pci_resource_start(pci, 0); 1983 chip->dsp_registers_phys = pci_resource_start(pci, 0);
@@ -1962,7 +2017,9 @@ static __devinit int snd_echo_create(struct snd_card *card,
1962 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; 2017 chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area;
1963 2018
1964 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); 2019 err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
1965 if (err) { 2020 if (err >= 0)
2021 err = set_mixer_defaults(chip);
2022 if (err < 0) {
1966 DE_INIT(("init_hw err=%d\n", err)); 2023 DE_INIT(("init_hw err=%d\n", err));
1967 snd_echo_free(chip); 2024 snd_echo_free(chip);
1968 return err; 2025 return err;
@@ -1973,9 +2030,6 @@ static __devinit int snd_echo_create(struct snd_card *card,
1973 snd_echo_free(chip); 2030 snd_echo_free(chip);
1974 return err; 2031 return err;
1975 } 2032 }
1976 atomic_set(&chip->opencount, 0);
1977 mutex_init(&chip->mode_mutex);
1978 chip->can_set_rate = 1;
1979 *rchip = chip; 2033 *rchip = chip;
1980 /* Init done ! */ 2034 /* Init done ! */
1981 return 0; 2035 return 0;
@@ -2008,6 +2062,7 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2008 2062
2009 snd_card_set_dev(card, &pci->dev); 2063 snd_card_set_dev(card, &pci->dev);
2010 2064
2065 chip = NULL; /* Tells snd_echo_create to allocate chip */
2011 if ((err = snd_echo_create(card, pci, &chip)) < 0) { 2066 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2012 snd_card_free(card); 2067 snd_card_free(card);
2013 return err; 2068 return err;
@@ -2147,6 +2202,112 @@ ctl_error:
2147 2202
2148 2203
2149 2204
2205#if defined(CONFIG_PM)
2206
2207static 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
2244static 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
2150static void __devexit snd_echo_remove(struct pci_dev *pci) 2311static void __devexit snd_echo_remove(struct pci_dev *pci)
2151{ 2312{
2152 struct echoaudio *chip; 2313 struct echoaudio *chip;
@@ -2169,6 +2330,10 @@ static struct pci_driver driver = {
2169 .id_table = snd_echo_ids, 2330 .id_table = snd_echo_ids,
2170 .probe = snd_echo_probe, 2331 .probe = snd_echo_probe,
2171 .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 */
2172}; 2337};
2173 2338
2174 2339