blob: 4a1fae99ac553e69bae361bce765ee39f82ebf97 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for Digigram VX soundcards
3 *
4 * DSP firmware management
5 *
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/device.h>
24#include <linux/firmware.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Andrew Morton409ef742005-11-08 21:34:26 -080026#include <linux/vmalloc.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include <sound/hwdep.h>
30#include <sound/vx_core.h>
31
32#ifdef SND_VX_FW_LOADER
33
Clemens Ladisch7e0af292007-05-03 17:59:54 +020034MODULE_FIRMWARE("vx/bx_1_vxp.b56");
35MODULE_FIRMWARE("vx/bx_1_vp4.b56");
36MODULE_FIRMWARE("vx/x1_1_vx2.xlx");
37MODULE_FIRMWARE("vx/x1_2_v22.xlx");
38MODULE_FIRMWARE("vx/x1_1_vxp.xlx");
39MODULE_FIRMWARE("vx/x1_1_vp4.xlx");
40MODULE_FIRMWARE("vx/bd56002.boot");
41MODULE_FIRMWARE("vx/bd563v2.boot");
42MODULE_FIRMWARE("vx/bd563s3.boot");
43MODULE_FIRMWARE("vx/l_1_vx2.d56");
44MODULE_FIRMWARE("vx/l_1_v22.d56");
45MODULE_FIRMWARE("vx/l_1_vxp.d56");
46MODULE_FIRMWARE("vx/l_1_vp4.d56");
47
Takashi Iwaiaf263672005-11-17 14:46:59 +010048int snd_vx_setup_firmware(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 static char *fw_files[VX_TYPE_NUMS][4] = {
51 [VX_TYPE_BOARD] = {
52 NULL, "x1_1_vx2.xlx", "bd56002.boot", "l_1_vx2.d56",
53 },
54 [VX_TYPE_V2] = {
55 NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
56 },
57 [VX_TYPE_MIC] = {
58 NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
59 },
60 [VX_TYPE_VXPOCKET] = {
61 "bx_1_vxp.b56", "x1_1_vxp.xlx", "bd563s3.boot", "l_1_vxp.d56"
62 },
63 [VX_TYPE_VXP440] = {
64 "bx_1_vp4.b56", "x1_1_vp4.xlx", "bd563s3.boot", "l_1_vp4.d56"
65 },
66 };
67
68 int i, err;
69
70 for (i = 0; i < 4; i++) {
71 char path[32];
72 const struct firmware *fw;
73 if (! fw_files[chip->type][i])
74 continue;
75 sprintf(path, "vx/%s", fw_files[chip->type][i]);
76 if (request_firmware(&fw, path, chip->dev)) {
77 snd_printk(KERN_ERR "vx: can't load firmware %s\n", path);
78 return -ENOENT;
79 }
80 err = chip->ops->load_dsp(chip, i, fw);
81 if (err < 0) {
82 release_firmware(fw);
83 return err;
84 }
85 if (i == 1)
86 chip->chip_status |= VX_STAT_XILINX_LOADED;
87#ifdef CONFIG_PM
88 chip->firmware[i] = fw;
89#else
90 release_firmware(fw);
91#endif
92 }
93
94 /* ok, we reached to the last one */
95 /* create the devices if not built yet */
96 if ((err = snd_vx_pcm_new(chip)) < 0)
97 return err;
98
99 if ((err = snd_vx_mixer_new(chip)) < 0)
100 return err;
101
102 if (chip->ops->add_controls)
103 if ((err = chip->ops->add_controls(chip)) < 0)
104 return err;
105
106 chip->chip_status |= VX_STAT_DEVICE_INIT;
107 chip->chip_status |= VX_STAT_CHIP_INIT;
108
109 return snd_card_register(chip->card);
110}
111
112/* exported */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100113void snd_vx_free_firmware(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115#ifdef CONFIG_PM
116 int i;
117 for (i = 0; i < 4; i++)
118 release_firmware(chip->firmware[i]);
119#endif
120}
121
122#else /* old style firmware loading */
123
Takashi Iwaiaf263672005-11-17 14:46:59 +0100124static int vx_hwdep_dsp_status(struct snd_hwdep *hw,
125 struct snd_hwdep_dsp_status *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 static char *type_ids[VX_TYPE_NUMS] = {
128 [VX_TYPE_BOARD] = "vxboard",
129 [VX_TYPE_V2] = "vx222",
130 [VX_TYPE_MIC] = "vx222",
131 [VX_TYPE_VXPOCKET] = "vxpocket",
132 [VX_TYPE_VXP440] = "vxp440",
133 };
Takashi Iwaiaf263672005-11-17 14:46:59 +0100134 struct vx_core *vx = hw->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Takashi Iwai5e246b82008-08-08 17:12:47 +0200136 if (snd_BUG_ON(!type_ids[vx->type]))
137 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 strcpy(info->id, type_ids[vx->type]);
139 if (vx_is_pcmcia(vx))
140 info->num_dsps = 4;
141 else
142 info->num_dsps = 3;
143 if (vx->chip_status & VX_STAT_CHIP_INIT)
144 info->chip_ready = 1;
145 info->version = VX_DRIVER_VERSION;
146 return 0;
147}
148
149static void free_fw(const struct firmware *fw)
150{
151 if (fw) {
152 vfree(fw->data);
153 kfree(fw);
154 }
155}
156
Takashi Iwaiaf263672005-11-17 14:46:59 +0100157static int vx_hwdep_dsp_load(struct snd_hwdep *hw,
158 struct snd_hwdep_dsp_image *dsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Takashi Iwaiaf263672005-11-17 14:46:59 +0100160 struct vx_core *vx = hw->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 int index, err;
162 struct firmware *fw;
163
Takashi Iwai5e246b82008-08-08 17:12:47 +0200164 if (snd_BUG_ON(!vx->ops->load_dsp))
165 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 fw = kmalloc(sizeof(*fw), GFP_KERNEL);
168 if (! fw) {
169 snd_printk(KERN_ERR "cannot allocate firmware\n");
170 return -ENOMEM;
171 }
172 fw->size = dsp->length;
173 fw->data = vmalloc(fw->size);
174 if (! fw->data) {
175 snd_printk(KERN_ERR "cannot allocate firmware image (length=%d)\n",
176 (int)fw->size);
177 kfree(fw);
178 return -ENOMEM;
179 }
David Howellsbd5d06e2008-07-08 17:30:30 +0100180 if (copy_from_user((void *)fw->data, dsp->image, dsp->length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 free_fw(fw);
182 return -EFAULT;
183 }
184
185 index = dsp->index;
186 if (! vx_is_pcmcia(vx))
187 index++;
188 err = vx->ops->load_dsp(vx, index, fw);
189 if (err < 0) {
190 free_fw(fw);
191 return err;
192 }
193#ifdef CONFIG_PM
194 vx->firmware[index] = fw;
195#else
196 free_fw(fw);
197#endif
198
199 if (index == 1)
200 vx->chip_status |= VX_STAT_XILINX_LOADED;
201 if (index < 3)
202 return 0;
203
204 /* ok, we reached to the last one */
205 /* create the devices if not built yet */
206 if (! (vx->chip_status & VX_STAT_DEVICE_INIT)) {
207 if ((err = snd_vx_pcm_new(vx)) < 0)
208 return err;
209
210 if ((err = snd_vx_mixer_new(vx)) < 0)
211 return err;
212
213 if (vx->ops->add_controls)
214 if ((err = vx->ops->add_controls(vx)) < 0)
215 return err;
216
217 if ((err = snd_card_register(vx->card)) < 0)
218 return err;
219
220 vx->chip_status |= VX_STAT_DEVICE_INIT;
221 }
222 vx->chip_status |= VX_STAT_CHIP_INIT;
223 return 0;
224}
225
226
227/* exported */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100228int snd_vx_setup_firmware(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 int err;
Takashi Iwaiaf263672005-11-17 14:46:59 +0100231 struct snd_hwdep *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 if ((err = snd_hwdep_new(chip->card, SND_VX_HWDEP_ID, 0, &hw)) < 0)
234 return err;
235
236 hw->iface = SNDRV_HWDEP_IFACE_VX;
237 hw->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 hw->ops.dsp_status = vx_hwdep_dsp_status;
239 hw->ops.dsp_load = vx_hwdep_dsp_load;
240 hw->exclusive = 1;
241 sprintf(hw->name, "VX Loader (%s)", chip->card->driver);
242 chip->hwdep = hw;
243
244 return snd_card_register(chip->card);
245}
246
247/* exported */
Takashi Iwaiaf263672005-11-17 14:46:59 +0100248void snd_vx_free_firmware(struct vx_core *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250#ifdef CONFIG_PM
251 int i;
252 for (i = 0; i < 4; i++)
253 free_fw(chip->firmware[i]);
254#endif
255}
256
257#endif /* SND_VX_FW_LOADER */
Takashi Iwaifa325eb2006-04-28 15:13:40 +0200258
259EXPORT_SYMBOL(snd_vx_setup_firmware);
260EXPORT_SYMBOL(snd_vx_free_firmware);