| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <sound/driver.h> | 
|  | 24 | #include <linux/device.h> | 
|  | 25 | #include <linux/firmware.h> | 
| Andrew Morton | 409ef74 | 2005-11-08 21:34:26 -0800 | [diff] [blame] | 26 | #include <linux/vmalloc.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <sound/core.h> | 
|  | 28 | #include <sound/hwdep.h> | 
|  | 29 | #include <sound/vx_core.h> | 
|  | 30 |  | 
|  | 31 | #ifdef SND_VX_FW_LOADER | 
|  | 32 |  | 
| Clemens Ladisch | 7e0af29 | 2007-05-03 17:59:54 +0200 | [diff] [blame] | 33 | MODULE_FIRMWARE("vx/bx_1_vxp.b56"); | 
|  | 34 | MODULE_FIRMWARE("vx/bx_1_vp4.b56"); | 
|  | 35 | MODULE_FIRMWARE("vx/x1_1_vx2.xlx"); | 
|  | 36 | MODULE_FIRMWARE("vx/x1_2_v22.xlx"); | 
|  | 37 | MODULE_FIRMWARE("vx/x1_1_vxp.xlx"); | 
|  | 38 | MODULE_FIRMWARE("vx/x1_1_vp4.xlx"); | 
|  | 39 | MODULE_FIRMWARE("vx/bd56002.boot"); | 
|  | 40 | MODULE_FIRMWARE("vx/bd563v2.boot"); | 
|  | 41 | MODULE_FIRMWARE("vx/bd563s3.boot"); | 
|  | 42 | MODULE_FIRMWARE("vx/l_1_vx2.d56"); | 
|  | 43 | MODULE_FIRMWARE("vx/l_1_v22.d56"); | 
|  | 44 | MODULE_FIRMWARE("vx/l_1_vxp.d56"); | 
|  | 45 | MODULE_FIRMWARE("vx/l_1_vp4.d56"); | 
|  | 46 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 47 | int snd_vx_setup_firmware(struct vx_core *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 112 | void snd_vx_free_firmware(struct vx_core *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 123 | static int vx_hwdep_open(struct snd_hwdep *hw, struct file *file) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { | 
|  | 125 | return 0; | 
|  | 126 | } | 
|  | 127 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 128 | static int vx_hwdep_release(struct snd_hwdep *hw, struct file *file) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { | 
|  | 130 | return 0; | 
|  | 131 | } | 
|  | 132 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 133 | static int vx_hwdep_dsp_status(struct snd_hwdep *hw, | 
|  | 134 | struct snd_hwdep_dsp_status *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { | 
|  | 136 | static char *type_ids[VX_TYPE_NUMS] = { | 
|  | 137 | [VX_TYPE_BOARD] = "vxboard", | 
|  | 138 | [VX_TYPE_V2] = "vx222", | 
|  | 139 | [VX_TYPE_MIC] = "vx222", | 
|  | 140 | [VX_TYPE_VXPOCKET] = "vxpocket", | 
|  | 141 | [VX_TYPE_VXP440] = "vxp440", | 
|  | 142 | }; | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 143 | struct vx_core *vx = hw->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 |  | 
|  | 145 | snd_assert(type_ids[vx->type], return -EINVAL); | 
|  | 146 | strcpy(info->id, type_ids[vx->type]); | 
|  | 147 | if (vx_is_pcmcia(vx)) | 
|  | 148 | info->num_dsps = 4; | 
|  | 149 | else | 
|  | 150 | info->num_dsps = 3; | 
|  | 151 | if (vx->chip_status & VX_STAT_CHIP_INIT) | 
|  | 152 | info->chip_ready = 1; | 
|  | 153 | info->version = VX_DRIVER_VERSION; | 
|  | 154 | return 0; | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | static void free_fw(const struct firmware *fw) | 
|  | 158 | { | 
|  | 159 | if (fw) { | 
|  | 160 | vfree(fw->data); | 
|  | 161 | kfree(fw); | 
|  | 162 | } | 
|  | 163 | } | 
|  | 164 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 165 | static int vx_hwdep_dsp_load(struct snd_hwdep *hw, | 
|  | 166 | struct snd_hwdep_dsp_image *dsp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 168 | struct vx_core *vx = hw->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | int index, err; | 
|  | 170 | struct firmware *fw; | 
|  | 171 |  | 
|  | 172 | snd_assert(vx->ops->load_dsp, return -ENXIO); | 
|  | 173 |  | 
|  | 174 | fw = kmalloc(sizeof(*fw), GFP_KERNEL); | 
|  | 175 | if (! fw) { | 
|  | 176 | snd_printk(KERN_ERR "cannot allocate firmware\n"); | 
|  | 177 | return -ENOMEM; | 
|  | 178 | } | 
|  | 179 | fw->size = dsp->length; | 
|  | 180 | fw->data = vmalloc(fw->size); | 
|  | 181 | if (! fw->data) { | 
|  | 182 | snd_printk(KERN_ERR "cannot allocate firmware image (length=%d)\n", | 
|  | 183 | (int)fw->size); | 
|  | 184 | kfree(fw); | 
|  | 185 | return -ENOMEM; | 
|  | 186 | } | 
|  | 187 | if (copy_from_user(fw->data, dsp->image, dsp->length)) { | 
|  | 188 | free_fw(fw); | 
|  | 189 | return -EFAULT; | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | index = dsp->index; | 
|  | 193 | if (! vx_is_pcmcia(vx)) | 
|  | 194 | index++; | 
|  | 195 | err = vx->ops->load_dsp(vx, index, fw); | 
|  | 196 | if (err < 0) { | 
|  | 197 | free_fw(fw); | 
|  | 198 | return err; | 
|  | 199 | } | 
|  | 200 | #ifdef CONFIG_PM | 
|  | 201 | vx->firmware[index] = fw; | 
|  | 202 | #else | 
|  | 203 | free_fw(fw); | 
|  | 204 | #endif | 
|  | 205 |  | 
|  | 206 | if (index == 1) | 
|  | 207 | vx->chip_status |= VX_STAT_XILINX_LOADED; | 
|  | 208 | if (index < 3) | 
|  | 209 | return 0; | 
|  | 210 |  | 
|  | 211 | /* ok, we reached to the last one */ | 
|  | 212 | /* create the devices if not built yet */ | 
|  | 213 | if (! (vx->chip_status & VX_STAT_DEVICE_INIT)) { | 
|  | 214 | if ((err = snd_vx_pcm_new(vx)) < 0) | 
|  | 215 | return err; | 
|  | 216 |  | 
|  | 217 | if ((err = snd_vx_mixer_new(vx)) < 0) | 
|  | 218 | return err; | 
|  | 219 |  | 
|  | 220 | if (vx->ops->add_controls) | 
|  | 221 | if ((err = vx->ops->add_controls(vx)) < 0) | 
|  | 222 | return err; | 
|  | 223 |  | 
|  | 224 | if ((err = snd_card_register(vx->card)) < 0) | 
|  | 225 | return err; | 
|  | 226 |  | 
|  | 227 | vx->chip_status |= VX_STAT_DEVICE_INIT; | 
|  | 228 | } | 
|  | 229 | vx->chip_status |= VX_STAT_CHIP_INIT; | 
|  | 230 | return 0; | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 |  | 
|  | 234 | /* exported */ | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 235 | int snd_vx_setup_firmware(struct vx_core *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { | 
|  | 237 | int err; | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 238 | struct snd_hwdep *hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 |  | 
|  | 240 | if ((err = snd_hwdep_new(chip->card, SND_VX_HWDEP_ID, 0, &hw)) < 0) | 
|  | 241 | return err; | 
|  | 242 |  | 
|  | 243 | hw->iface = SNDRV_HWDEP_IFACE_VX; | 
|  | 244 | hw->private_data = chip; | 
|  | 245 | hw->ops.open = vx_hwdep_open; | 
|  | 246 | hw->ops.release = vx_hwdep_release; | 
|  | 247 | hw->ops.dsp_status = vx_hwdep_dsp_status; | 
|  | 248 | hw->ops.dsp_load = vx_hwdep_dsp_load; | 
|  | 249 | hw->exclusive = 1; | 
|  | 250 | sprintf(hw->name, "VX Loader (%s)", chip->card->driver); | 
|  | 251 | chip->hwdep = hw; | 
|  | 252 |  | 
|  | 253 | return snd_card_register(chip->card); | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | /* exported */ | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 257 | void snd_vx_free_firmware(struct vx_core *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { | 
|  | 259 | #ifdef CONFIG_PM | 
|  | 260 | int i; | 
|  | 261 | for (i = 0; i < 4; i++) | 
|  | 262 | free_fw(chip->firmware[i]); | 
|  | 263 | #endif | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | #endif /* SND_VX_FW_LOADER */ | 
| Takashi Iwai | fa325eb | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 267 |  | 
|  | 268 | EXPORT_SYMBOL(snd_vx_setup_firmware); | 
|  | 269 | EXPORT_SYMBOL(snd_vx_free_firmware); |