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