GNU Linux-libre 5.19-rc6-gnu
[releases.git] / sound / drivers / vx / vx_hwdep.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Driver for Digigram VX soundcards
4  *
5  * DSP firmware management
6  *
7  * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8  */
9
10 #include <linux/device.h>
11 #include <linux/firmware.h>
12 #include <linux/slab.h>
13 #include <linux/vmalloc.h>
14 #include <linux/module.h>
15 #include <sound/core.h>
16 #include <sound/hwdep.h>
17 #include <sound/vx_core.h>
18
19 /*(DEBLOBBED)*/
20
21 int snd_vx_setup_firmware(struct vx_core *chip)
22 {
23         static const char * const fw_files[VX_TYPE_NUMS][4] = {
24                 [VX_TYPE_BOARD] = {
25                         NULL, "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
26                 },
27                 [VX_TYPE_V2] = {
28                         NULL, "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
29                 },
30                 [VX_TYPE_MIC] = {
31                         NULL, "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/",
32                 },
33                 [VX_TYPE_VXPOCKET] = {
34                         "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/"
35                 },
36                 [VX_TYPE_VXP440] = {
37                         "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/", "/*(DEBLOBBED)*/"
38                 },
39         };
40
41         int i, err;
42
43         for (i = 0; i < 4; i++) {
44                 char path[32];
45                 const struct firmware *fw;
46                 if (! fw_files[chip->type][i])
47                         continue;
48                 sprintf(path, "vx/%s", fw_files[chip->type][i]);
49                 if (reject_firmware(&fw, path, chip->dev)) {
50                         snd_printk(KERN_ERR "vx: can't load firmware %s\n", path);
51                         return -ENOENT;
52                 }
53                 err = chip->ops->load_dsp(chip, i, fw);
54                 if (err < 0) {
55                         release_firmware(fw);
56                         return err;
57                 }
58                 if (i == 1)
59                         chip->chip_status |= VX_STAT_XILINX_LOADED;
60 #ifdef CONFIG_PM
61                 chip->firmware[i] = fw;
62 #else
63                 release_firmware(fw);
64 #endif
65         }
66
67         /* ok, we reached to the last one */
68         /* create the devices if not built yet */
69         err = snd_vx_pcm_new(chip);
70         if (err < 0)
71                 return err;
72
73         err = snd_vx_mixer_new(chip);
74         if (err < 0)
75                 return err;
76
77         if (chip->ops->add_controls) {
78                 err = chip->ops->add_controls(chip);
79                 if (err < 0)
80                         return err;
81         }
82
83         chip->chip_status |= VX_STAT_DEVICE_INIT;
84         chip->chip_status |= VX_STAT_CHIP_INIT;
85
86         return snd_card_register(chip->card);
87 }
88
89 /* exported */
90 void snd_vx_free_firmware(struct vx_core *chip)
91 {
92 #ifdef CONFIG_PM
93         int i;
94         for (i = 0; i < 4; i++)
95                 release_firmware(chip->firmware[i]);
96 #endif
97 }
98
99 EXPORT_SYMBOL(snd_vx_setup_firmware);
100 EXPORT_SYMBOL(snd_vx_free_firmware);