| 1 | // SPDX-License-Identifier: GPL-2.0-or-later
|
|---|
| 2 | /*
|
|---|
| 3 | * The driver for the EMU10K1 (SB Live!) based soundcards
|
|---|
| 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
|---|
| 5 | * James Courtier-Dutton <James@superbug.co.uk>
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include <linux/init.h>
|
|---|
| 9 | #include <linux/pci.h>
|
|---|
| 10 | #include <linux/time.h>
|
|---|
| 11 | #include <linux/module.h>
|
|---|
| 12 | #include <sound/core.h>
|
|---|
| 13 | #include <sound/emu10k1.h>
|
|---|
| 14 | #include <sound/initval.h>
|
|---|
| 15 |
|
|---|
| 16 | #ifdef TARGET_OS2
|
|---|
| 17 | #define KBUILD_MODNAME "emu10k1"
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
|---|
| 21 | MODULE_DESCRIPTION("EMU10K1");
|
|---|
| 22 | MODULE_LICENSE("GPL");
|
|---|
| 23 |
|
|---|
| 24 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER)
|
|---|
| 25 | #define ENABLE_SYNTH
|
|---|
| 26 | #include <sound/emu10k1_synth.h>
|
|---|
| 27 | #endif
|
|---|
| 28 |
|
|---|
| 29 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
|---|
| 30 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
|---|
| 31 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
|
|---|
| 32 | static int extin[SNDRV_CARDS];
|
|---|
| 33 | static int extout[SNDRV_CARDS];
|
|---|
| 34 | #ifndef TARGET_OS2
|
|---|
| 35 | static int seq_ports[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
|
|---|
| 36 | static int max_synth_voices[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 64};
|
|---|
| 37 | static int max_buffer_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 128};
|
|---|
| 38 | #else
|
|---|
| 39 | static int seq_ports[SNDRV_CARDS] = {4,4,4,4,4,4,4,4};
|
|---|
| 40 | static int max_synth_voices[SNDRV_CARDS] = {64,64,64,64,64,64,64,64};
|
|---|
| 41 | static int max_buffer_size[SNDRV_CARDS] = {128,128,128,128,128,128,128,128};
|
|---|
| 42 | #endif
|
|---|
| 43 | static bool enable_ir[SNDRV_CARDS];
|
|---|
| 44 | static uint subsystem[SNDRV_CARDS]; /* Force card subsystem model */
|
|---|
| 45 |
|
|---|
| 46 | module_param_array(index, int, NULL, 0444);
|
|---|
| 47 | MODULE_PARM_DESC(index, "Index value for the EMU10K1 soundcard.");
|
|---|
| 48 | module_param_array(id, charp, NULL, 0444);
|
|---|
| 49 | MODULE_PARM_DESC(id, "ID string for the EMU10K1 soundcard.");
|
|---|
| 50 | module_param_array(enable, bool, NULL, 0444);
|
|---|
| 51 | MODULE_PARM_DESC(enable, "Enable the EMU10K1 soundcard.");
|
|---|
| 52 | module_param_array(extin, int, NULL, 0444);
|
|---|
| 53 | MODULE_PARM_DESC(extin, "Available external inputs for FX8010. Zero=default.");
|
|---|
| 54 | module_param_array(extout, int, NULL, 0444);
|
|---|
| 55 | MODULE_PARM_DESC(extout, "Available external outputs for FX8010. Zero=default.");
|
|---|
| 56 | module_param_array(seq_ports, int, NULL, 0444);
|
|---|
| 57 | MODULE_PARM_DESC(seq_ports, "Allocated sequencer ports for internal synthesizer.");
|
|---|
| 58 | module_param_array(max_synth_voices, int, NULL, 0444);
|
|---|
| 59 | MODULE_PARM_DESC(max_synth_voices, "Maximum number of voices for WaveTable.");
|
|---|
| 60 | module_param_array(max_buffer_size, int, NULL, 0444);
|
|---|
| 61 | MODULE_PARM_DESC(max_buffer_size, "Maximum sample buffer size in MB.");
|
|---|
| 62 | module_param_array(enable_ir, bool, NULL, 0444);
|
|---|
| 63 | MODULE_PARM_DESC(enable_ir, "Enable IR.");
|
|---|
| 64 | module_param_array(subsystem, uint, NULL, 0444);
|
|---|
| 65 | MODULE_PARM_DESC(subsystem, "Force card subsystem model.");
|
|---|
| 66 | /*
|
|---|
| 67 | * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400
|
|---|
| 68 | */
|
|---|
| 69 | static const struct pci_device_id snd_emu10k1_ids[] = {
|
|---|
| 70 | { PCI_VDEVICE(CREATIVE, 0x0002), 0 }, /* EMU10K1 */
|
|---|
| 71 | { PCI_VDEVICE(CREATIVE, 0x0004), 1 }, /* Audigy */
|
|---|
| 72 | { PCI_VDEVICE(CREATIVE, 0x0008), 1 }, /* Audigy 2 Value SB0400 */
|
|---|
| 73 | { 0, }
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | MODULE_DEVICE_TABLE(pci, snd_emu10k1_ids);
|
|---|
| 77 |
|
|---|
| 78 | static int snd_card_emu10k1_probe(struct pci_dev *pci,
|
|---|
| 79 | const struct pci_device_id *pci_id)
|
|---|
| 80 | {
|
|---|
| 81 | static int dev;
|
|---|
| 82 | struct snd_card *card;
|
|---|
| 83 | struct snd_emu10k1 *emu;
|
|---|
| 84 | #ifdef ENABLE_SYNTH
|
|---|
| 85 | struct snd_seq_device *wave = NULL;
|
|---|
| 86 | #endif
|
|---|
| 87 | int err;
|
|---|
| 88 |
|
|---|
| 89 | if (dev >= SNDRV_CARDS)
|
|---|
| 90 | return -ENODEV;
|
|---|
| 91 | if (!enable[dev]) {
|
|---|
| 92 | dev++;
|
|---|
| 93 | return -ENOENT;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
|---|
| 97 | sizeof(*emu), &card);
|
|---|
| 98 | if (err < 0)
|
|---|
| 99 | return err;
|
|---|
| 100 | emu = card->private_data;
|
|---|
| 101 |
|
|---|
| 102 | if (max_buffer_size[dev] < 32)
|
|---|
| 103 | max_buffer_size[dev] = 32;
|
|---|
| 104 | else if (max_buffer_size[dev] > 1024)
|
|---|
| 105 | max_buffer_size[dev] = 1024;
|
|---|
| 106 | err = snd_emu10k1_create(card, pci, extin[dev], extout[dev],
|
|---|
| 107 | (long)max_buffer_size[dev] * 1024 * 1024,
|
|---|
| 108 | enable_ir[dev], subsystem[dev]);
|
|---|
| 109 | if (err < 0)
|
|---|
| 110 | return err;
|
|---|
| 111 | err = snd_emu10k1_pcm(emu, 0);
|
|---|
| 112 | if (err < 0)
|
|---|
| 113 | return err;
|
|---|
| 114 | if (emu->card_capabilities->ac97_chip) {
|
|---|
| 115 | err = snd_emu10k1_pcm_mic(emu, 1);
|
|---|
| 116 | if (err < 0)
|
|---|
| 117 | return err;
|
|---|
| 118 | }
|
|---|
| 119 | err = snd_emu10k1_pcm_efx(emu, 2);
|
|---|
| 120 | if (err < 0)
|
|---|
| 121 | return err;
|
|---|
| 122 | /* This stores the periods table. */
|
|---|
| 123 | if (emu->card_capabilities->ca0151_chip) { /* P16V */
|
|---|
| 124 | emu->p16v_buffer =
|
|---|
| 125 | snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, 1024);
|
|---|
| 126 | if (!emu->p16v_buffer)
|
|---|
| 127 | return -ENOMEM;
|
|---|
| 128 | }
|
|---|
| 129 | err = snd_emu10k1_mixer(emu, 0, 3);
|
|---|
| 130 | if (err < 0)
|
|---|
| 131 | return err;
|
|---|
| 132 |
|
|---|
| 133 | err = snd_emu10k1_timer(emu, 0);
|
|---|
| 134 | if (err < 0)
|
|---|
| 135 | return err;
|
|---|
| 136 |
|
|---|
| 137 | err = snd_emu10k1_pcm_multi(emu, 3);
|
|---|
| 138 | if (err < 0)
|
|---|
| 139 | return err;
|
|---|
| 140 | if (emu->card_capabilities->ca0151_chip) { /* P16V */
|
|---|
| 141 | err = snd_p16v_pcm(emu, 4);
|
|---|
| 142 | if (err < 0)
|
|---|
| 143 | return err;
|
|---|
| 144 | }
|
|---|
| 145 | if (emu->audigy) {
|
|---|
| 146 | err = snd_emu10k1_audigy_midi(emu);
|
|---|
| 147 | if (err < 0)
|
|---|
| 148 | return err;
|
|---|
| 149 | } else {
|
|---|
| 150 | err = snd_emu10k1_midi(emu);
|
|---|
| 151 | if (err < 0)
|
|---|
| 152 | return err;
|
|---|
| 153 | }
|
|---|
| 154 | err = snd_emu10k1_fx8010_new(emu, 0);
|
|---|
| 155 | if (err < 0)
|
|---|
| 156 | return err;
|
|---|
| 157 | #ifdef ENABLE_SYNTH
|
|---|
| 158 | if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
|
|---|
| 159 | sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 ||
|
|---|
| 160 | wave == NULL) {
|
|---|
| 161 | dev_warn(emu->card->dev,
|
|---|
| 162 | "can't initialize Emu10k1 wavetable synth\n");
|
|---|
| 163 | } else {
|
|---|
| 164 | struct snd_emu10k1_synth_arg *arg;
|
|---|
| 165 | arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
|
|---|
| 166 | strcpy(wave->name, "Emu-10k1 Synth");
|
|---|
| 167 | arg->hwptr = emu;
|
|---|
| 168 | arg->index = 1;
|
|---|
| 169 | arg->seq_ports = seq_ports[dev];
|
|---|
| 170 | arg->max_voices = max_synth_voices[dev];
|
|---|
| 171 | }
|
|---|
| 172 | #endif
|
|---|
| 173 |
|
|---|
| 174 | strscpy(card->driver, emu->card_capabilities->driver,
|
|---|
| 175 | sizeof(card->driver));
|
|---|
| 176 | strscpy(card->shortname, emu->card_capabilities->name,
|
|---|
| 177 | sizeof(card->shortname));
|
|---|
| 178 | snprintf(card->longname, sizeof(card->longname),
|
|---|
| 179 | "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i",
|
|---|
| 180 | card->shortname, emu->revision, emu->serial, emu->port, emu->irq);
|
|---|
| 181 |
|
|---|
| 182 | err = snd_card_register(card);
|
|---|
| 183 | if (err < 0)
|
|---|
| 184 | return err;
|
|---|
| 185 |
|
|---|
| 186 | pci_set_drvdata(pci, card);
|
|---|
| 187 | dev++;
|
|---|
| 188 | return 0;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | #ifdef CONFIG_PM_SLEEP
|
|---|
| 192 | static int snd_emu10k1_suspend(struct device *dev)
|
|---|
| 193 | {
|
|---|
| 194 | struct snd_card *card = dev_get_drvdata(dev);
|
|---|
| 195 | struct snd_emu10k1 *emu = card->private_data;
|
|---|
| 196 |
|
|---|
| 197 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
|
|---|
| 198 |
|
|---|
| 199 | emu->suspend = 1;
|
|---|
| 200 |
|
|---|
| 201 | cancel_work_sync(&emu->emu1010.work);
|
|---|
| 202 |
|
|---|
| 203 | snd_ac97_suspend(emu->ac97);
|
|---|
| 204 |
|
|---|
| 205 | snd_emu10k1_efx_suspend(emu);
|
|---|
| 206 | snd_emu10k1_suspend_regs(emu);
|
|---|
| 207 | if (emu->card_capabilities->ca0151_chip)
|
|---|
| 208 | snd_p16v_suspend(emu);
|
|---|
| 209 |
|
|---|
| 210 | snd_emu10k1_done(emu);
|
|---|
| 211 | return 0;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | static int snd_emu10k1_resume(struct device *dev)
|
|---|
| 215 | {
|
|---|
| 216 | struct snd_card *card = dev_get_drvdata(dev);
|
|---|
| 217 | struct snd_emu10k1 *emu = card->private_data;
|
|---|
| 218 |
|
|---|
| 219 | snd_emu10k1_resume_init(emu);
|
|---|
| 220 | snd_emu10k1_efx_resume(emu);
|
|---|
| 221 | snd_ac97_resume(emu->ac97);
|
|---|
| 222 | snd_emu10k1_resume_regs(emu);
|
|---|
| 223 |
|
|---|
| 224 | if (emu->card_capabilities->ca0151_chip)
|
|---|
| 225 | snd_p16v_resume(emu);
|
|---|
| 226 |
|
|---|
| 227 | emu->suspend = 0;
|
|---|
| 228 |
|
|---|
| 229 | snd_power_change_state(card, SNDRV_CTL_POWER_D0);
|
|---|
| 230 |
|
|---|
| 231 | return 0;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | static SIMPLE_DEV_PM_OPS(snd_emu10k1_pm, snd_emu10k1_suspend, snd_emu10k1_resume);
|
|---|
| 235 | #define SND_EMU10K1_PM_OPS &snd_emu10k1_pm
|
|---|
| 236 | #else
|
|---|
| 237 | #define SND_EMU10K1_PM_OPS NULL
|
|---|
| 238 | #endif /* CONFIG_PM_SLEEP */
|
|---|
| 239 |
|
|---|
| 240 | static struct pci_driver emu10k1_driver = {
|
|---|
| 241 | .name = KBUILD_MODNAME,
|
|---|
| 242 | .id_table = snd_emu10k1_ids,
|
|---|
| 243 | .probe = snd_card_emu10k1_probe,
|
|---|
| 244 | .driver = {
|
|---|
| 245 | .pm = SND_EMU10K1_PM_OPS,
|
|---|
| 246 | },
|
|---|
| 247 | };
|
|---|
| 248 |
|
|---|
| 249 | module_pci_driver(emu10k1_driver);
|
|---|