ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / drivers / vx / vx_hwdep.c
1 /*
2  * Driver for Digigram VX soundcards
3  *
4  * hwdep device manager
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
23 #include <sound/driver.h>
24 #include <sound/core.h>
25 #include <sound/hwdep.h>
26 #include <sound/vx_core.h>
27
28 static int vx_hwdep_open(snd_hwdep_t *hw, struct file *file)
29 {
30         return 0;
31 }
32
33 static int vx_hwdep_release(snd_hwdep_t *hw, struct file *file)
34 {
35         return 0;
36 }
37
38 static int vx_hwdep_dsp_status(snd_hwdep_t *hw, snd_hwdep_dsp_status_t *info)
39 {
40         static char *type_ids[VX_TYPE_NUMS] = {
41                 [VX_TYPE_BOARD] = "vxboard",
42                 [VX_TYPE_V2] = "vx222",
43                 [VX_TYPE_MIC] = "vx222",
44                 [VX_TYPE_VXPOCKET] = "vxpocket",
45                 [VX_TYPE_VXP440] = "vxp440",
46         };
47         vx_core_t *vx = snd_magic_cast(vx_core_t, hw->private_data, return -ENXIO);
48
49         snd_assert(type_ids[vx->type], return -EINVAL);
50         strcpy(info->id, type_ids[vx->type]);
51         if (vx_is_pcmcia(vx))
52                 info->num_dsps = 4;
53         else
54                 info->num_dsps = 3;
55         if (vx->chip_status & VX_STAT_CHIP_INIT)
56                 info->chip_ready = 1;
57         info->version = VX_DRIVER_VERSION;
58         return 0;
59 }
60
61 static int vx_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
62 {
63         vx_core_t *vx = snd_magic_cast(vx_core_t, hw->private_data, return -ENXIO);
64         int index, err;
65
66         snd_assert(vx->ops->load_dsp, return -ENXIO);
67         err = vx->ops->load_dsp(vx, dsp);
68         if (err < 0)
69                 return err;
70
71         index = dsp->index;
72         if (! vx_is_pcmcia(vx))
73                 index++;
74         if (index == 1)
75                 vx->chip_status |= VX_STAT_XILINX_LOADED;
76         if (index < 3)
77                 return 0;
78
79         /* ok, we reached to the last one */
80         /* create the devices if not built yet */
81         if (! (vx->chip_status & VX_STAT_DEVICE_INIT)) {
82                 if ((err = snd_vx_pcm_new(vx)) < 0)
83                         return err;
84
85                 if ((err = snd_vx_mixer_new(vx)) < 0)
86                         return err;
87
88                 if (vx->ops->add_controls)
89                         if ((err = vx->ops->add_controls(vx)) < 0)
90                                 return err;
91
92                 if ((err = snd_card_register(vx->card)) < 0)
93                         return err;
94
95                 vx->chip_status |= VX_STAT_DEVICE_INIT;
96         }
97         vx->chip_status |= VX_STAT_CHIP_INIT;
98         return 0;
99 }
100
101
102 /* exported */
103 int snd_vx_hwdep_new(vx_core_t *chip)
104 {
105         int err;
106         snd_hwdep_t *hw;
107
108         if ((err = snd_hwdep_new(chip->card, SND_VX_HWDEP_ID, 0, &hw)) < 0)
109                 return err;
110
111         hw->iface = SNDRV_HWDEP_IFACE_VX;
112         hw->private_data = chip;
113         hw->ops.open = vx_hwdep_open;
114         hw->ops.release = vx_hwdep_release;
115         hw->ops.dsp_status = vx_hwdep_dsp_status;
116         hw->ops.dsp_load = vx_hwdep_dsp_load;
117         hw->exclusive = 1;
118         sprintf(hw->name, "VX Loader (%s)", chip->card->driver);
119         chip->hwdep = hw;
120
121         return 0;
122 }