1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  ALSA interface to cx18 PCM capture streams
4  *
5  *  Copyright (C) 2009  Andy Walls <awalls@md.metrocast.net>
6  */
7 
8 struct snd_card;
9 
10 struct snd_cx18_card {
11 	struct v4l2_device *v4l2_dev;
12 	struct snd_card *sc;
13 	unsigned int capture_transfer_done;
14 	unsigned int hwptr_done_capture;
15 	struct snd_pcm_substream *capture_pcm_substream;
16 	spinlock_t slock;
17 };
18 
19 extern int cx18_alsa_debug;
20 
21 /*
22  * File operations that manipulate the encoder or video or audio subdevices
23  * need to be serialized.  Use the same lock we use for v4l2 file ops.
24  */
snd_cx18_lock(struct snd_cx18_card * cxsc)25 static inline void snd_cx18_lock(struct snd_cx18_card *cxsc)
26 {
27 	struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
28 	mutex_lock(&cx->serialize_lock);
29 }
30 
snd_cx18_unlock(struct snd_cx18_card * cxsc)31 static inline void snd_cx18_unlock(struct snd_cx18_card *cxsc)
32 {
33 	struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
34 	mutex_unlock(&cx->serialize_lock);
35 }
36 
37 #define CX18_ALSA_DBGFLG_WARN  (1 << 0)
38 #define CX18_ALSA_DBGFLG_INFO  (1 << 1)
39 
40 #define CX18_ALSA_DEBUG(x, type, fmt, args...) \
41 	do { \
42 		if ((x) & cx18_alsa_debug) \
43 			printk(KERN_INFO "%s-alsa: " type ": " fmt, \
44 				v4l2_dev->name , ## args); \
45 	} while (0)
46 
47 #define CX18_ALSA_DEBUG_WARN(fmt, args...) \
48 	CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_WARN, "warning", fmt , ## args)
49 
50 #define CX18_ALSA_DEBUG_INFO(fmt, args...) \
51 	CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_INFO, "info", fmt , ## args)
52 
53 #define CX18_ALSA_ERR(fmt, args...) \
54 	printk(KERN_ERR "%s-alsa: " fmt, v4l2_dev->name , ## args)
55 
56 #define CX18_ALSA_WARN(fmt, args...) \
57 	printk(KERN_WARNING "%s-alsa: " fmt, v4l2_dev->name , ## args)
58 
59 #define CX18_ALSA_INFO(fmt, args...) \
60 	printk(KERN_INFO "%s-alsa: " fmt, v4l2_dev->name , ## args)
61