vx_hwdep.c 5.8 KB

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