18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  ALSA interface to cx18 PCM capture streams
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2009  Andy Walls <awalls@md.metrocast.net>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistruct snd_card;
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistruct snd_cx18_card {
118c2ecf20Sopenharmony_ci	struct v4l2_device *v4l2_dev;
128c2ecf20Sopenharmony_ci	struct snd_card *sc;
138c2ecf20Sopenharmony_ci	unsigned int capture_transfer_done;
148c2ecf20Sopenharmony_ci	unsigned int hwptr_done_capture;
158c2ecf20Sopenharmony_ci	struct snd_pcm_substream *capture_pcm_substream;
168c2ecf20Sopenharmony_ci	spinlock_t slock;
178c2ecf20Sopenharmony_ci};
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciextern int cx18_alsa_debug;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * File operations that manipulate the encoder or video or audio subdevices
238c2ecf20Sopenharmony_ci * need to be serialized.  Use the same lock we use for v4l2 file ops.
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_cistatic inline void snd_cx18_lock(struct snd_cx18_card *cxsc)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
288c2ecf20Sopenharmony_ci	mutex_lock(&cx->serialize_lock);
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline void snd_cx18_unlock(struct snd_cx18_card *cxsc)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
348c2ecf20Sopenharmony_ci	mutex_unlock(&cx->serialize_lock);
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define CX18_ALSA_DBGFLG_WARN  (1 << 0)
388c2ecf20Sopenharmony_ci#define CX18_ALSA_DBGFLG_INFO  (1 << 1)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define CX18_ALSA_DEBUG(x, type, fmt, args...) \
418c2ecf20Sopenharmony_ci	do { \
428c2ecf20Sopenharmony_ci		if ((x) & cx18_alsa_debug) \
438c2ecf20Sopenharmony_ci			printk(KERN_INFO "%s-alsa: " type ": " fmt, \
448c2ecf20Sopenharmony_ci				v4l2_dev->name , ## args); \
458c2ecf20Sopenharmony_ci	} while (0)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define CX18_ALSA_DEBUG_WARN(fmt, args...) \
488c2ecf20Sopenharmony_ci	CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_WARN, "warning", fmt , ## args)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define CX18_ALSA_DEBUG_INFO(fmt, args...) \
518c2ecf20Sopenharmony_ci	CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_INFO, "info", fmt , ## args)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define CX18_ALSA_ERR(fmt, args...) \
548c2ecf20Sopenharmony_ci	printk(KERN_ERR "%s-alsa: " fmt, v4l2_dev->name , ## args)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define CX18_ALSA_WARN(fmt, args...) \
578c2ecf20Sopenharmony_ci	printk(KERN_WARNING "%s-alsa: " fmt, v4l2_dev->name , ## args)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define CX18_ALSA_INFO(fmt, args...) \
608c2ecf20Sopenharmony_ci	printk(KERN_INFO "%s-alsa: " fmt, v4l2_dev->name , ## args)
61