Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  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
 23#include <linux/device.h>
 24#include <linux/firmware.h>
 25#include <linux/slab.h>
 26#include <linux/vmalloc.h>
 
 27#include <sound/core.h>
 28#include <sound/hwdep.h>
 29#include <sound/vx_core.h>
 30
 31#ifdef SND_VX_FW_LOADER
 32
 33MODULE_FIRMWARE("vx/bx_1_vxp.b56");
 34MODULE_FIRMWARE("vx/bx_1_vp4.b56");
 35MODULE_FIRMWARE("vx/x1_1_vx2.xlx");
 36MODULE_FIRMWARE("vx/x1_2_v22.xlx");
 37MODULE_FIRMWARE("vx/x1_1_vxp.xlx");
 38MODULE_FIRMWARE("vx/x1_1_vp4.xlx");
 39MODULE_FIRMWARE("vx/bd56002.boot");
 40MODULE_FIRMWARE("vx/bd563v2.boot");
 41MODULE_FIRMWARE("vx/bd563s3.boot");
 42MODULE_FIRMWARE("vx/l_1_vx2.d56");
 43MODULE_FIRMWARE("vx/l_1_v22.d56");
 44MODULE_FIRMWARE("vx/l_1_vxp.d56");
 45MODULE_FIRMWARE("vx/l_1_vp4.d56");
 46
 47int snd_vx_setup_firmware(struct vx_core *chip)
 48{
 49	static char *fw_files[VX_TYPE_NUMS][4] = {
 50		[VX_TYPE_BOARD] = {
 51			NULL, "x1_1_vx2.xlx", "bd56002.boot", "l_1_vx2.d56",
 52		},
 53		[VX_TYPE_V2] = {
 54			NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
 55		},
 56		[VX_TYPE_MIC] = {
 57			NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
 58		},
 59		[VX_TYPE_VXPOCKET] = {
 60			"bx_1_vxp.b56", "x1_1_vxp.xlx", "bd563s3.boot", "l_1_vxp.d56"
 61		},
 62		[VX_TYPE_VXP440] = {
 63			"bx_1_vp4.b56", "x1_1_vp4.xlx", "bd563s3.boot", "l_1_vp4.d56"
 64		},
 65	};
 66
 67	int i, err;
 68
 69	for (i = 0; i < 4; i++) {
 70		char path[32];
 71		const struct firmware *fw;
 72		if (! fw_files[chip->type][i])
 73			continue;
 74		sprintf(path, "vx/%s", fw_files[chip->type][i]);
 75		if (request_firmware(&fw, path, chip->dev)) {
 76			snd_printk(KERN_ERR "vx: can't load firmware %s\n", path);
 77			return -ENOENT;
 78		}
 79		err = chip->ops->load_dsp(chip, i, fw);
 80		if (err < 0) {
 81			release_firmware(fw);
 82			return err;
 83		}
 84		if (i == 1)
 85			chip->chip_status |= VX_STAT_XILINX_LOADED;
 86#ifdef CONFIG_PM
 87		chip->firmware[i] = fw;
 88#else
 89		release_firmware(fw);
 90#endif
 91	}
 92
 93	/* ok, we reached to the last one */
 94	/* create the devices if not built yet */
 95	if ((err = snd_vx_pcm_new(chip)) < 0)
 
 96		return err;
 97
 98	if ((err = snd_vx_mixer_new(chip)) < 0)
 
 99		return err;
100
101	if (chip->ops->add_controls)
102		if ((err = chip->ops->add_controls(chip)) < 0)
 
103			return err;
 
104
105	chip->chip_status |= VX_STAT_DEVICE_INIT;
106	chip->chip_status |= VX_STAT_CHIP_INIT;
107
108	return snd_card_register(chip->card);
109}
110
111/* exported */
112void snd_vx_free_firmware(struct vx_core *chip)
113{
114#ifdef CONFIG_PM
115	int i;
116	for (i = 0; i < 4; i++)
117		release_firmware(chip->firmware[i]);
118#endif
119}
120
121#else /* old style firmware loading */
122
123static int vx_hwdep_dsp_status(struct snd_hwdep *hw,
124			       struct snd_hwdep_dsp_status *info)
125{
126	static char *type_ids[VX_TYPE_NUMS] = {
127		[VX_TYPE_BOARD] = "vxboard",
128		[VX_TYPE_V2] = "vx222",
129		[VX_TYPE_MIC] = "vx222",
130		[VX_TYPE_VXPOCKET] = "vxpocket",
131		[VX_TYPE_VXP440] = "vxp440",
132	};
133	struct vx_core *vx = hw->private_data;
134
135	if (snd_BUG_ON(!type_ids[vx->type]))
136		return -EINVAL;
137	strcpy(info->id, type_ids[vx->type]);
138	if (vx_is_pcmcia(vx))
139		info->num_dsps = 4;
140	else
141		info->num_dsps = 3;
142	if (vx->chip_status & VX_STAT_CHIP_INIT)
143		info->chip_ready = 1;
144	info->version = VX_DRIVER_VERSION;
145	return 0;
146}
147
148static void free_fw(const struct firmware *fw)
149{
150	if (fw) {
151		vfree(fw->data);
152		kfree(fw);
153	}
154}
155
156static int vx_hwdep_dsp_load(struct snd_hwdep *hw,
157			     struct snd_hwdep_dsp_image *dsp)
158{
159	struct vx_core *vx = hw->private_data;
160	int index, err;
161	struct firmware *fw;
162
163	if (snd_BUG_ON(!vx->ops->load_dsp))
164		return -ENXIO;
165
166	fw = kmalloc(sizeof(*fw), GFP_KERNEL);
167	if (! fw) {
168		snd_printk(KERN_ERR "cannot allocate firmware\n");
169		return -ENOMEM;
170	}
171	fw->size = dsp->length;
172	fw->data = vmalloc(fw->size);
173	if (! fw->data) {
174		snd_printk(KERN_ERR "cannot allocate firmware image (length=%d)\n",
175			   (int)fw->size);
176		kfree(fw);
177		return -ENOMEM;
178	}
179	if (copy_from_user((void *)fw->data, dsp->image, dsp->length)) {
180		free_fw(fw);
181		return -EFAULT;
182	}
183
184	index = dsp->index;
185	if (! vx_is_pcmcia(vx))
186		index++;
187	err = vx->ops->load_dsp(vx, index, fw);
188	if (err < 0) {
189		free_fw(fw);
190		return err;
191	}
192#ifdef CONFIG_PM
193	vx->firmware[index] = fw;
194#else
195	free_fw(fw);
196#endif
197
198	if (index == 1)
199		vx->chip_status |= VX_STAT_XILINX_LOADED;
200	if (index < 3)
201		return 0;
202
203	/* ok, we reached to the last one */
204	/* create the devices if not built yet */
205	if (! (vx->chip_status & VX_STAT_DEVICE_INIT)) {
206		if ((err = snd_vx_pcm_new(vx)) < 0)
207			return err;
208
209		if ((err = snd_vx_mixer_new(vx)) < 0)
210			return err;
211
212		if (vx->ops->add_controls)
213			if ((err = vx->ops->add_controls(vx)) < 0)
214				return err;
215
216		if ((err = snd_card_register(vx->card)) < 0)
217			return err;
218
219		vx->chip_status |= VX_STAT_DEVICE_INIT;
220	}
221	vx->chip_status |= VX_STAT_CHIP_INIT;
222	return 0;
223}
224
225
226/* exported */
227int snd_vx_setup_firmware(struct vx_core *chip)
228{
229	int err;
230	struct snd_hwdep *hw;
231
232	if ((err = snd_hwdep_new(chip->card, SND_VX_HWDEP_ID, 0, &hw)) < 0)
233		return err;
234
235	hw->iface = SNDRV_HWDEP_IFACE_VX;
236	hw->private_data = chip;
237	hw->ops.dsp_status = vx_hwdep_dsp_status;
238	hw->ops.dsp_load = vx_hwdep_dsp_load;
239	hw->exclusive = 1;
240	sprintf(hw->name, "VX Loader (%s)", chip->card->driver);
241	chip->hwdep = hw;
242
243	return snd_card_register(chip->card);
244}
245
246/* exported */
247void snd_vx_free_firmware(struct vx_core *chip)
248{
249#ifdef CONFIG_PM
250	int i;
251	for (i = 0; i < 4; i++)
252		free_fw(chip->firmware[i]);
253#endif
254}
255
256#endif /* SND_VX_FW_LOADER */
257
258EXPORT_SYMBOL(snd_vx_setup_firmware);
259EXPORT_SYMBOL(snd_vx_free_firmware);
v6.9.4
  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
 
 
 19MODULE_FIRMWARE("vx/bx_1_vxp.b56");
 20MODULE_FIRMWARE("vx/bx_1_vp4.b56");
 21MODULE_FIRMWARE("vx/x1_1_vx2.xlx");
 22MODULE_FIRMWARE("vx/x1_2_v22.xlx");
 23MODULE_FIRMWARE("vx/x1_1_vxp.xlx");
 24MODULE_FIRMWARE("vx/x1_1_vp4.xlx");
 25MODULE_FIRMWARE("vx/bd56002.boot");
 26MODULE_FIRMWARE("vx/bd563v2.boot");
 27MODULE_FIRMWARE("vx/bd563s3.boot");
 28MODULE_FIRMWARE("vx/l_1_vx2.d56");
 29MODULE_FIRMWARE("vx/l_1_v22.d56");
 30MODULE_FIRMWARE("vx/l_1_vxp.d56");
 31MODULE_FIRMWARE("vx/l_1_vp4.d56");
 32
 33int snd_vx_setup_firmware(struct vx_core *chip)
 34{
 35	static const char * const fw_files[VX_TYPE_NUMS][4] = {
 36		[VX_TYPE_BOARD] = {
 37			NULL, "x1_1_vx2.xlx", "bd56002.boot", "l_1_vx2.d56",
 38		},
 39		[VX_TYPE_V2] = {
 40			NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
 41		},
 42		[VX_TYPE_MIC] = {
 43			NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56",
 44		},
 45		[VX_TYPE_VXPOCKET] = {
 46			"bx_1_vxp.b56", "x1_1_vxp.xlx", "bd563s3.boot", "l_1_vxp.d56"
 47		},
 48		[VX_TYPE_VXP440] = {
 49			"bx_1_vp4.b56", "x1_1_vp4.xlx", "bd563s3.boot", "l_1_vp4.d56"
 50		},
 51	};
 52
 53	int i, err;
 54
 55	for (i = 0; i < 4; i++) {
 56		char path[32];
 57		const struct firmware *fw;
 58		if (! fw_files[chip->type][i])
 59			continue;
 60		sprintf(path, "vx/%s", fw_files[chip->type][i]);
 61		if (request_firmware(&fw, path, chip->dev)) {
 62			snd_printk(KERN_ERR "vx: can't load firmware %s\n", path);
 63			return -ENOENT;
 64		}
 65		err = chip->ops->load_dsp(chip, i, fw);
 66		if (err < 0) {
 67			release_firmware(fw);
 68			return err;
 69		}
 70		if (i == 1)
 71			chip->chip_status |= VX_STAT_XILINX_LOADED;
 72#ifdef CONFIG_PM
 73		chip->firmware[i] = fw;
 74#else
 75		release_firmware(fw);
 76#endif
 77	}
 78
 79	/* ok, we reached to the last one */
 80	/* create the devices if not built yet */
 81	err = snd_vx_pcm_new(chip);
 82	if (err < 0)
 83		return err;
 84
 85	err = snd_vx_mixer_new(chip);
 86	if (err < 0)
 87		return err;
 88
 89	if (chip->ops->add_controls) {
 90		err = chip->ops->add_controls(chip);
 91		if (err < 0)
 92			return err;
 93	}
 94
 95	chip->chip_status |= VX_STAT_DEVICE_INIT;
 96	chip->chip_status |= VX_STAT_CHIP_INIT;
 97
 98	return snd_card_register(chip->card);
 99}
100
101/* exported */
102void snd_vx_free_firmware(struct vx_core *chip)
103{
104#ifdef CONFIG_PM
105	int i;
106	for (i = 0; i < 4; i++)
107		release_firmware(chip->firmware[i]);
108#endif
109}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111EXPORT_SYMBOL(snd_vx_setup_firmware);
112EXPORT_SYMBOL(snd_vx_free_firmware);