vx_hwdep.c 6.0 KB

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