vx_hwdep.c 5.6 KB

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