2 * Driver for Digigram VX soundcards
4 * DSP firmware management
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
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.
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.
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
23 #include <linux/device.h>
24 #include <linux/firmware.h>
25 #include <linux/vmalloc.h>
26 #include <sound/core.h>
27 #include <sound/hwdep.h>
28 #include <sound/vx_core.h>
30 #ifdef SND_VX_FW_LOADER
32 MODULE_FIRMWARE("vx/bx_1_vxp.b56");
33 MODULE_FIRMWARE("vx/bx_1_vp4.b56");
34 MODULE_FIRMWARE("vx/x1_1_vx2.xlx");
35 MODULE_FIRMWARE("vx/x1_2_v22.xlx");
36 MODULE_FIRMWARE("vx/x1_1_vxp.xlx");
37 MODULE_FIRMWARE("vx/x1_1_vp4.xlx");
38 MODULE_FIRMWARE("vx/bd56002.boot");
39 MODULE_FIRMWARE("vx/bd563v2.boot");
40 MODULE_FIRMWARE("vx/bd563s3.boot");
41 MODULE_FIRMWARE("vx/l_1_vx2.d56");
42 MODULE_FIRMWARE("vx/l_1_v22.d56");
43 MODULE_FIRMWARE("vx/l_1_vxp.d56");
44 MODULE_FIRMWARE("vx/l_1_vp4.d56");
46 int snd_vx_setup_firmware(struct vx_core *chip)
48 static char *fw_files[VX_TYPE_NUMS][4] = {
50 NULL, "x1_1_vx2.xlx", "bd56002.boot", "l_1_vx2.d56",
53 NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
56 NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
58 [VX_TYPE_VXPOCKET] = {
59 "bx_1_vxp.b56", "x1_1_vxp.xlx", "bd563s3.boot", "l_1_vxp.d56"
62 "bx_1_vp4.b56", "x1_1_vp4.xlx", "bd563s3.boot", "l_1_vp4.d56"
68 for (i = 0; i < 4; i++) {
70 const struct firmware *fw;
71 if (! fw_files[chip->type][i])
73 sprintf(path, "vx/%s", fw_files[chip->type][i]);
74 if (request_firmware(&fw, path, chip->dev)) {
75 snd_printk(KERN_ERR "vx: can't load firmware %s\n", path);
78 err = chip->ops->load_dsp(chip, i, fw);
84 chip->chip_status |= VX_STAT_XILINX_LOADED;
86 chip->firmware[i] = fw;
92 /* ok, we reached to the last one */
93 /* create the devices if not built yet */
94 if ((err = snd_vx_pcm_new(chip)) < 0)
97 if ((err = snd_vx_mixer_new(chip)) < 0)
100 if (chip->ops->add_controls)
101 if ((err = chip->ops->add_controls(chip)) < 0)
104 chip->chip_status |= VX_STAT_DEVICE_INIT;
105 chip->chip_status |= VX_STAT_CHIP_INIT;
107 return snd_card_register(chip->card);
111 void snd_vx_free_firmware(struct vx_core *chip)
115 for (i = 0; i < 4; i++)
116 release_firmware(chip->firmware[i]);
120 #else /* old style firmware loading */
122 static int vx_hwdep_open(struct snd_hwdep *hw, struct file *file)
127 static int vx_hwdep_release(struct snd_hwdep *hw, struct file *file)
132 static int vx_hwdep_dsp_status(struct snd_hwdep *hw,
133 struct snd_hwdep_dsp_status *info)
135 static char *type_ids[VX_TYPE_NUMS] = {
136 [VX_TYPE_BOARD] = "vxboard",
137 [VX_TYPE_V2] = "vx222",
138 [VX_TYPE_MIC] = "vx222",
139 [VX_TYPE_VXPOCKET] = "vxpocket",
140 [VX_TYPE_VXP440] = "vxp440",
142 struct vx_core *vx = hw->private_data;
144 if (snd_BUG_ON(!type_ids[vx->type]))
146 strcpy(info->id, type_ids[vx->type]);
147 if (vx_is_pcmcia(vx))
151 if (vx->chip_status & VX_STAT_CHIP_INIT)
152 info->chip_ready = 1;
153 info->version = VX_DRIVER_VERSION;
157 static void free_fw(const struct firmware *fw)
165 static int vx_hwdep_dsp_load(struct snd_hwdep *hw,
166 struct snd_hwdep_dsp_image *dsp)
168 struct vx_core *vx = hw->private_data;
172 if (snd_BUG_ON(!vx->ops->load_dsp))
175 fw = kmalloc(sizeof(*fw), GFP_KERNEL);
177 snd_printk(KERN_ERR "cannot allocate firmware\n");
180 fw->size = dsp->length;
181 fw->data = vmalloc(fw->size);
183 snd_printk(KERN_ERR "cannot allocate firmware image (length=%d)\n",
188 if (copy_from_user((void *)fw->data, dsp->image, dsp->length)) {
194 if (! vx_is_pcmcia(vx))
196 err = vx->ops->load_dsp(vx, index, fw);
202 vx->firmware[index] = fw;
208 vx->chip_status |= VX_STAT_XILINX_LOADED;
212 /* ok, we reached to the last one */
213 /* create the devices if not built yet */
214 if (! (vx->chip_status & VX_STAT_DEVICE_INIT)) {
215 if ((err = snd_vx_pcm_new(vx)) < 0)
218 if ((err = snd_vx_mixer_new(vx)) < 0)
221 if (vx->ops->add_controls)
222 if ((err = vx->ops->add_controls(vx)) < 0)
225 if ((err = snd_card_register(vx->card)) < 0)
228 vx->chip_status |= VX_STAT_DEVICE_INIT;
230 vx->chip_status |= VX_STAT_CHIP_INIT;
236 int snd_vx_setup_firmware(struct vx_core *chip)
239 struct snd_hwdep *hw;
241 if ((err = snd_hwdep_new(chip->card, SND_VX_HWDEP_ID, 0, &hw)) < 0)
244 hw->iface = SNDRV_HWDEP_IFACE_VX;
245 hw->private_data = chip;
246 hw->ops.open = vx_hwdep_open;
247 hw->ops.release = vx_hwdep_release;
248 hw->ops.dsp_status = vx_hwdep_dsp_status;
249 hw->ops.dsp_load = vx_hwdep_dsp_load;
251 sprintf(hw->name, "VX Loader (%s)", chip->card->driver);
254 return snd_card_register(chip->card);
258 void snd_vx_free_firmware(struct vx_core *chip)
262 for (i = 0; i < 4; i++)
263 free_fw(chip->firmware[i]);
267 #endif /* SND_VX_FW_LOADER */
269 EXPORT_SYMBOL(snd_vx_setup_firmware);
270 EXPORT_SYMBOL(snd_vx_free_firmware);