vx_hwdep.c 6.2 KB

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