Debian Codegraph @

sound/isa/sb/emu8000_synth.c

raw
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) by Jaroslav Kysela <[email protected]>
4 * and (c) 1999 Steve Ratcliffe <[email protected]>
5 * Copyright (C) 1999-2000 Takashi Iwai <[email protected]>
6 *
7 * Emu8000 synth plug-in routine
8 */
9
10 #include "emu8000_local.h"
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <sound/initval.h>
14
15 MODULE_AUTHOR("Takashi Iwai, Steve Ratcliffe");
16 MODULE_DESCRIPTION("Emu8000 synth plug-in routine");
17 MODULE_LICENSE("GPL");
18
19 /*----------------------------------------------------------------*/
20
21 /*
22 * create a new hardware dependent device for Emu8000
23 */
24 static int snd_emu8000_probe(struct snd_seq_device *dev)
25 {
26 struct snd_emu8000 *hw;
27 struct snd_emux *emu;
28
29 hw = *(struct snd_emu8000**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
30 if (hw == NULL)
31 return -EINVAL;
32
33 if (hw->emu)
34 return -EBUSY; /* already exists..? */
35
36 if (snd_emux_new(&emu) < 0)
37 return -ENOMEM;
38
39 hw->emu = emu;
40 snd_emu8000_ops_setup(hw);
41
42 emu->hw = hw;
43 emu->max_voices = EMU8000_DRAM_VOICES;
44 emu->num_ports = hw->seq_ports;
45
46 if (hw->memhdr) {
47 dev_err(hw->card->dev, "memhdr is already initialized!?\n");
48 snd_util_memhdr_free(hw->memhdr);
49 }
50 hw->memhdr = snd_util_memhdr_new(hw->mem_size);
51 if (hw->memhdr == NULL) {
52 snd_emux_free(emu);
53 hw->emu = NULL;
54 return -ENOMEM;
55 }
56
57 emu->memhdr = hw->memhdr;
58 emu->midi_ports = hw->seq_ports < 2 ? hw->seq_ports : 2; /* number of virmidi ports */
59 emu->midi_devidx = 1;
60 emu->linear_panning = 1;
61 emu->hwdep_idx = 2; /* FIXED */
62
63 if (snd_emux_register(emu, dev->card, hw->index, "Emu8000") < 0) {
64 snd_emux_free(emu);
65 snd_util_memhdr_free(hw->memhdr);
66 hw->emu = NULL;
67 hw->memhdr = NULL;
68 return -ENOMEM;
69 }
70
71 if (hw->mem_size > 0)
72 snd_emu8000_pcm_new(dev->card, hw, 1);
73
74 dev->driver_data = hw;
75
76 return 0;
77 }
78
79
80 /*
81 * free all resources
82 */
83 static void snd_emu8000_remove(struct snd_seq_device *dev)
84 {
85 struct snd_emu8000 *hw;
86
87 if (dev->driver_data == NULL)
88 return; /* no synth was allocated actually */
89
90 hw = dev->driver_data;
91 if (hw->pcm)
92 snd_device_free(dev->card, hw->pcm);
93 snd_emux_free(hw->emu);
94 snd_util_memhdr_free(hw->memhdr);
95 hw->emu = NULL;
96 hw->memhdr = NULL;
97 }
98
99 /*
100 * INIT part
101 */
102
103 static struct snd_seq_driver emu8000_driver = {
104 .probe = snd_emu8000_probe,
105 .remove = snd_emu8000_remove,
106 .driver = {
107 .name = KBUILD_MODNAME,
108 },
109 .id = SNDRV_SEQ_DEV_ID_EMU8000,
110 .argsize = sizeof(struct snd_emu8000 *),
111 };
112
113 module_snd_seq_driver(emu8000_driver);