2 * ALSA interface to cobalt PCM capture streams
4 * Copyright 2014-2015 Cisco Systems, Inc. and/or its affiliates.
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/device.h>
26 #include <linux/spinlock.h>
28 #include <media/v4l2-device.h>
30 #include <sound/core.h>
31 #include <sound/initval.h>
33 #include "cobalt-driver.h"
34 #include "cobalt-alsa.h"
35 #include "cobalt-alsa-pcm.h"
37 static void snd_cobalt_card_free(struct snd_cobalt_card
*cobsc
)
42 cobsc
->s
->alsa
= NULL
;
47 static void snd_cobalt_card_private_free(struct snd_card
*sc
)
51 snd_cobalt_card_free(sc
->private_data
);
52 sc
->private_data
= NULL
;
53 sc
->private_free
= NULL
;
56 static int snd_cobalt_card_create(struct cobalt_stream
*s
,
58 struct snd_cobalt_card
**cobsc
)
60 *cobsc
= kzalloc(sizeof(struct snd_cobalt_card
), GFP_KERNEL
);
67 sc
->private_data
= *cobsc
;
68 sc
->private_free
= snd_cobalt_card_private_free
;
73 static int snd_cobalt_card_set_names(struct snd_cobalt_card
*cobsc
)
75 struct cobalt_stream
*s
= cobsc
->s
;
76 struct cobalt
*cobalt
= s
->cobalt
;
77 struct snd_card
*sc
= cobsc
->sc
;
79 /* sc->driver is used by alsa-lib's configurator: simple, unique */
80 strlcpy(sc
->driver
, "cobalt", sizeof(sc
->driver
));
82 /* sc->shortname is a symlink in /proc/asound: COBALT-M -> cardN */
83 snprintf(sc
->shortname
, sizeof(sc
->shortname
), "cobalt-%d-%d",
84 cobalt
->instance
, s
->video_channel
);
86 /* sc->longname is read from /proc/asound/cards */
87 snprintf(sc
->longname
, sizeof(sc
->longname
),
89 cobalt
->instance
, s
->video_channel
);
94 int cobalt_alsa_init(struct cobalt_stream
*s
)
96 struct cobalt
*cobalt
= s
->cobalt
;
97 struct snd_card
*sc
= NULL
;
98 struct snd_cobalt_card
*cobsc
;
101 /* Numbrs steps from "Writing an ALSA Driver" by Takashi Iwai */
103 /* (1) Check and increment the device index */
104 /* This is a no-op for us. We'll use the cobalt->instance */
106 /* (2) Create a card instance */
107 ret
= snd_card_new(&cobalt
->pci_dev
->dev
, SNDRV_DEFAULT_IDX1
,
108 SNDRV_DEFAULT_STR1
, THIS_MODULE
, 0, &sc
);
110 cobalt_err("snd_card_new() failed with err %d\n", ret
);
114 /* (3) Create a main component */
115 ret
= snd_cobalt_card_create(s
, sc
, &cobsc
);
117 cobalt_err("snd_cobalt_card_create() failed with err %d\n",
122 /* (4) Set the driver ID and name strings */
123 snd_cobalt_card_set_names(cobsc
);
125 ret
= snd_cobalt_pcm_create(cobsc
);
127 cobalt_err("snd_cobalt_pcm_create() failed with err %d\n",
131 /* FIXME - proc files */
133 /* (7) Set the driver data and return 0 */
134 /* We do this out of normal order for PCI drivers to avoid races */
137 /* (6) Register the card instance */
138 ret
= snd_card_register(sc
);
141 cobalt_err("snd_card_register() failed with err %d\n", ret
);
155 void cobalt_alsa_exit(struct cobalt_stream
*s
)
157 struct snd_cobalt_card
*cobsc
= s
->alsa
;
160 snd_card_free(cobsc
->sc
);