18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_PCM_H
38c2ecf20Sopenharmony_ci#define __SOUND_PCM_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *  Digital Audio (PCM) abstract layer
78c2ecf20Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
88c2ecf20Sopenharmony_ci *                   Abramo Bagnara <abramo@alsa-project.org>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <sound/asound.h>
128c2ecf20Sopenharmony_ci#include <sound/memalloc.h>
138c2ecf20Sopenharmony_ci#include <sound/minors.h>
148c2ecf20Sopenharmony_ci#include <linux/poll.h>
158c2ecf20Sopenharmony_ci#include <linux/mm.h>
168c2ecf20Sopenharmony_ci#include <linux/bitops.h>
178c2ecf20Sopenharmony_ci#include <linux/pm_qos.h>
188c2ecf20Sopenharmony_ci#include <linux/refcount.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define snd_pcm_substream_chip(substream) ((substream)->private_data)
218c2ecf20Sopenharmony_ci#define snd_pcm_chip(pcm) ((pcm)->private_data)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
248c2ecf20Sopenharmony_ci#include <sound/pcm_oss.h>
258c2ecf20Sopenharmony_ci#endif
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci *  Hardware (lowlevel) section
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct snd_pcm_hardware {
328c2ecf20Sopenharmony_ci	unsigned int info;		/* SNDRV_PCM_INFO_* */
338c2ecf20Sopenharmony_ci	u64 formats;			/* SNDRV_PCM_FMTBIT_* */
348c2ecf20Sopenharmony_ci	unsigned int rates;		/* SNDRV_PCM_RATE_* */
358c2ecf20Sopenharmony_ci	unsigned int rate_min;		/* min rate */
368c2ecf20Sopenharmony_ci	unsigned int rate_max;		/* max rate */
378c2ecf20Sopenharmony_ci	unsigned int channels_min;	/* min channels */
388c2ecf20Sopenharmony_ci	unsigned int channels_max;	/* max channels */
398c2ecf20Sopenharmony_ci	size_t buffer_bytes_max;	/* max buffer size */
408c2ecf20Sopenharmony_ci	size_t period_bytes_min;	/* min period size */
418c2ecf20Sopenharmony_ci	size_t period_bytes_max;	/* max period size */
428c2ecf20Sopenharmony_ci	unsigned int periods_min;	/* min # of periods */
438c2ecf20Sopenharmony_ci	unsigned int periods_max;	/* max # of periods */
448c2ecf20Sopenharmony_ci	size_t fifo_size;		/* fifo size in bytes */
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct snd_pcm_status64;
488c2ecf20Sopenharmony_cistruct snd_pcm_substream;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct snd_pcm_audio_tstamp_config; /* definitions further down */
518c2ecf20Sopenharmony_cistruct snd_pcm_audio_tstamp_report;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct snd_pcm_ops {
548c2ecf20Sopenharmony_ci	int (*open)(struct snd_pcm_substream *substream);
558c2ecf20Sopenharmony_ci	int (*close)(struct snd_pcm_substream *substream);
568c2ecf20Sopenharmony_ci	int (*ioctl)(struct snd_pcm_substream * substream,
578c2ecf20Sopenharmony_ci		     unsigned int cmd, void *arg);
588c2ecf20Sopenharmony_ci	int (*hw_params)(struct snd_pcm_substream *substream,
598c2ecf20Sopenharmony_ci			 struct snd_pcm_hw_params *params);
608c2ecf20Sopenharmony_ci	int (*hw_free)(struct snd_pcm_substream *substream);
618c2ecf20Sopenharmony_ci	int (*prepare)(struct snd_pcm_substream *substream);
628c2ecf20Sopenharmony_ci	int (*trigger)(struct snd_pcm_substream *substream, int cmd);
638c2ecf20Sopenharmony_ci	int (*sync_stop)(struct snd_pcm_substream *substream);
648c2ecf20Sopenharmony_ci	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
658c2ecf20Sopenharmony_ci	int (*get_time_info)(struct snd_pcm_substream *substream,
668c2ecf20Sopenharmony_ci			struct timespec64 *system_ts, struct timespec64 *audio_ts,
678c2ecf20Sopenharmony_ci			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
688c2ecf20Sopenharmony_ci			struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
698c2ecf20Sopenharmony_ci	int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
708c2ecf20Sopenharmony_ci			    unsigned long pos, unsigned long bytes);
718c2ecf20Sopenharmony_ci	int (*copy_user)(struct snd_pcm_substream *substream, int channel,
728c2ecf20Sopenharmony_ci			 unsigned long pos, void __user *buf,
738c2ecf20Sopenharmony_ci			 unsigned long bytes);
748c2ecf20Sopenharmony_ci	int (*copy_kernel)(struct snd_pcm_substream *substream, int channel,
758c2ecf20Sopenharmony_ci			   unsigned long pos, void *buf, unsigned long bytes);
768c2ecf20Sopenharmony_ci	struct page *(*page)(struct snd_pcm_substream *substream,
778c2ecf20Sopenharmony_ci			     unsigned long offset);
788c2ecf20Sopenharmony_ci	int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
798c2ecf20Sopenharmony_ci	int (*ack)(struct snd_pcm_substream *substream);
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#if defined(CONFIG_SND_DYNAMIC_MINORS)
878c2ecf20Sopenharmony_ci#define SNDRV_PCM_DEVICES	(SNDRV_OS_MINORS-2)
888c2ecf20Sopenharmony_ci#else
898c2ecf20Sopenharmony_ci#define SNDRV_PCM_DEVICES	8
908c2ecf20Sopenharmony_ci#endif
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL1_RESET		0
938c2ecf20Sopenharmony_ci/* 1 is absent slot. */
948c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL1_CHANNEL_INFO	2
958c2ecf20Sopenharmony_ci/* 3 is absent slot. */
968c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL1_FIFO_SIZE	4
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_STOP		0
998c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_START		1
1008c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_PAUSE_PUSH	3
1018c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_PAUSE_RELEASE	4
1028c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_SUSPEND	5
1038c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_RESUME	6
1048c2ecf20Sopenharmony_ci#define SNDRV_PCM_TRIGGER_DRAIN		7
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define SNDRV_PCM_POS_XRUN		((snd_pcm_uframes_t)-1)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* If you change this don't forget to change rates[] table in pcm_native.c */
1098c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_5512		(1U<<0)		/* 5512Hz */
1108c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000		(1U<<1)		/* 8000Hz */
1118c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_11025		(1U<<2)		/* 11025Hz */
1128c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_16000		(1U<<3)		/* 16000Hz */
1138c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_22050		(1U<<4)		/* 22050Hz */
1148c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_32000		(1U<<5)		/* 32000Hz */
1158c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_44100		(1U<<6)		/* 44100Hz */
1168c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_48000		(1U<<7)		/* 48000Hz */
1178c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_64000		(1U<<8)		/* 64000Hz */
1188c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_88200		(1U<<9)		/* 88200Hz */
1198c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_96000		(1U<<10)	/* 96000Hz */
1208c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_176400		(1U<<11)	/* 176400Hz */
1218c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_192000		(1U<<12)	/* 192000Hz */
1228c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_352800		(1U<<13)	/* 352800Hz */
1238c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_384000		(1U<<14)	/* 384000Hz */
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_CONTINUOUS	(1U<<30)	/* continuous range */
1268c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_KNOT		(1U<<31)	/* supports more non-continuos rates */
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000_44100	(SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
1298c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
1308c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
1318c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000_48000	(SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
1328c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000_96000	(SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
1338c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
1348c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000_192000	(SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\
1358c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_192000)
1368c2ecf20Sopenharmony_ci#define SNDRV_PCM_RATE_8000_384000	(SNDRV_PCM_RATE_8000_192000|\
1378c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_352800|\
1388c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_384000)
1398c2ecf20Sopenharmony_ci#define _SNDRV_PCM_FMTBIT(fmt)		(1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)
1408c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S8		_SNDRV_PCM_FMTBIT(S8)
1418c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U8		_SNDRV_PCM_FMTBIT(U8)
1428c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S16_LE		_SNDRV_PCM_FMTBIT(S16_LE)
1438c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S16_BE		_SNDRV_PCM_FMTBIT(S16_BE)
1448c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U16_LE		_SNDRV_PCM_FMTBIT(U16_LE)
1458c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U16_BE		_SNDRV_PCM_FMTBIT(U16_BE)
1468c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24_LE		_SNDRV_PCM_FMTBIT(S24_LE)
1478c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24_BE		_SNDRV_PCM_FMTBIT(S24_BE)
1488c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24_LE		_SNDRV_PCM_FMTBIT(U24_LE)
1498c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24_BE		_SNDRV_PCM_FMTBIT(U24_BE)
1508c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S32_LE		_SNDRV_PCM_FMTBIT(S32_LE)
1518c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S32_BE		_SNDRV_PCM_FMTBIT(S32_BE)
1528c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U32_LE		_SNDRV_PCM_FMTBIT(U32_LE)
1538c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U32_BE		_SNDRV_PCM_FMTBIT(U32_BE)
1548c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT_LE	_SNDRV_PCM_FMTBIT(FLOAT_LE)
1558c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT_BE	_SNDRV_PCM_FMTBIT(FLOAT_BE)
1568c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT64_LE	_SNDRV_PCM_FMTBIT(FLOAT64_LE)
1578c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT64_BE	_SNDRV_PCM_FMTBIT(FLOAT64_BE)
1588c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_LE)
1598c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_BE)
1608c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_MU_LAW		_SNDRV_PCM_FMTBIT(MU_LAW)
1618c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_A_LAW		_SNDRV_PCM_FMTBIT(A_LAW)
1628c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_IMA_ADPCM	_SNDRV_PCM_FMTBIT(IMA_ADPCM)
1638c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_MPEG		_SNDRV_PCM_FMTBIT(MPEG)
1648c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_GSM		_SNDRV_PCM_FMTBIT(GSM)
1658c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20_LE	_SNDRV_PCM_FMTBIT(S20_LE)
1668c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20_LE	_SNDRV_PCM_FMTBIT(U20_LE)
1678c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20_BE	_SNDRV_PCM_FMTBIT(S20_BE)
1688c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20_BE	_SNDRV_PCM_FMTBIT(U20_BE)
1698c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_SPECIAL	_SNDRV_PCM_FMTBIT(SPECIAL)
1708c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24_3LE	_SNDRV_PCM_FMTBIT(S24_3LE)
1718c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24_3LE	_SNDRV_PCM_FMTBIT(U24_3LE)
1728c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24_3BE	_SNDRV_PCM_FMTBIT(S24_3BE)
1738c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24_3BE	_SNDRV_PCM_FMTBIT(U24_3BE)
1748c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20_3LE	_SNDRV_PCM_FMTBIT(S20_3LE)
1758c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20_3LE	_SNDRV_PCM_FMTBIT(U20_3LE)
1768c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20_3BE	_SNDRV_PCM_FMTBIT(S20_3BE)
1778c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20_3BE	_SNDRV_PCM_FMTBIT(U20_3BE)
1788c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S18_3LE	_SNDRV_PCM_FMTBIT(S18_3LE)
1798c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U18_3LE	_SNDRV_PCM_FMTBIT(U18_3LE)
1808c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S18_3BE	_SNDRV_PCM_FMTBIT(S18_3BE)
1818c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U18_3BE	_SNDRV_PCM_FMTBIT(U18_3BE)
1828c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_G723_24	_SNDRV_PCM_FMTBIT(G723_24)
1838c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_G723_24_1B	_SNDRV_PCM_FMTBIT(G723_24_1B)
1848c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_G723_40	_SNDRV_PCM_FMTBIT(G723_40)
1858c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_G723_40_1B	_SNDRV_PCM_FMTBIT(G723_40_1B)
1868c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_DSD_U8		_SNDRV_PCM_FMTBIT(DSD_U8)
1878c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_DSD_U16_LE	_SNDRV_PCM_FMTBIT(DSD_U16_LE)
1888c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_DSD_U32_LE	_SNDRV_PCM_FMTBIT(DSD_U32_LE)
1898c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_DSD_U16_BE	_SNDRV_PCM_FMTBIT(DSD_U16_BE)
1908c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_DSD_U32_BE	_SNDRV_PCM_FMTBIT(DSD_U32_BE)
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#ifdef SNDRV_LITTLE_ENDIAN
1938c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S16		SNDRV_PCM_FMTBIT_S16_LE
1948c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U16		SNDRV_PCM_FMTBIT_U16_LE
1958c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24		SNDRV_PCM_FMTBIT_S24_LE
1968c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24		SNDRV_PCM_FMTBIT_U24_LE
1978c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S32		SNDRV_PCM_FMTBIT_S32_LE
1988c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U32		SNDRV_PCM_FMTBIT_U32_LE
1998c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT		SNDRV_PCM_FMTBIT_FLOAT_LE
2008c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT64	SNDRV_PCM_FMTBIT_FLOAT64_LE
2018c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
2028c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20		SNDRV_PCM_FMTBIT_S20_LE
2038c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20		SNDRV_PCM_FMTBIT_U20_LE
2048c2ecf20Sopenharmony_ci#endif
2058c2ecf20Sopenharmony_ci#ifdef SNDRV_BIG_ENDIAN
2068c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S16		SNDRV_PCM_FMTBIT_S16_BE
2078c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U16		SNDRV_PCM_FMTBIT_U16_BE
2088c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S24		SNDRV_PCM_FMTBIT_S24_BE
2098c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U24		SNDRV_PCM_FMTBIT_U24_BE
2108c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S32		SNDRV_PCM_FMTBIT_S32_BE
2118c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U32		SNDRV_PCM_FMTBIT_U32_BE
2128c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT		SNDRV_PCM_FMTBIT_FLOAT_BE
2138c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_FLOAT64	SNDRV_PCM_FMTBIT_FLOAT64_BE
2148c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
2158c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_S20		SNDRV_PCM_FMTBIT_S20_BE
2168c2ecf20Sopenharmony_ci#define SNDRV_PCM_FMTBIT_U20		SNDRV_PCM_FMTBIT_U20_BE
2178c2ecf20Sopenharmony_ci#endif
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistruct snd_pcm_file {
2208c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream;
2218c2ecf20Sopenharmony_ci	int no_compat_mmap;
2228c2ecf20Sopenharmony_ci	unsigned int user_pversion;	/* supported protocol version */
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistruct snd_pcm_hw_rule;
2268c2ecf20Sopenharmony_citypedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
2278c2ecf20Sopenharmony_ci				      struct snd_pcm_hw_rule *rule);
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_cistruct snd_pcm_hw_rule {
2308c2ecf20Sopenharmony_ci	unsigned int cond;
2318c2ecf20Sopenharmony_ci	int var;
2328c2ecf20Sopenharmony_ci	int deps[4];
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	snd_pcm_hw_rule_func_t func;
2358c2ecf20Sopenharmony_ci	void *private;
2368c2ecf20Sopenharmony_ci};
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistruct snd_pcm_hw_constraints {
2398c2ecf20Sopenharmony_ci	struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
2408c2ecf20Sopenharmony_ci			 SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
2418c2ecf20Sopenharmony_ci	struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
2428c2ecf20Sopenharmony_ci			     SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
2438c2ecf20Sopenharmony_ci	unsigned int rules_num;
2448c2ecf20Sopenharmony_ci	unsigned int rules_all;
2458c2ecf20Sopenharmony_ci	struct snd_pcm_hw_rule *rules;
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
2498c2ecf20Sopenharmony_ci					    snd_pcm_hw_param_t var)
2508c2ecf20Sopenharmony_ci{
2518c2ecf20Sopenharmony_ci	return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
2528c2ecf20Sopenharmony_ci}
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_cistatic inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
2558c2ecf20Sopenharmony_ci						    snd_pcm_hw_param_t var)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistruct snd_ratnum {
2618c2ecf20Sopenharmony_ci	unsigned int num;
2628c2ecf20Sopenharmony_ci	unsigned int den_min, den_max, den_step;
2638c2ecf20Sopenharmony_ci};
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistruct snd_ratden {
2668c2ecf20Sopenharmony_ci	unsigned int num_min, num_max, num_step;
2678c2ecf20Sopenharmony_ci	unsigned int den;
2688c2ecf20Sopenharmony_ci};
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistruct snd_pcm_hw_constraint_ratnums {
2718c2ecf20Sopenharmony_ci	int nrats;
2728c2ecf20Sopenharmony_ci	const struct snd_ratnum *rats;
2738c2ecf20Sopenharmony_ci};
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_cistruct snd_pcm_hw_constraint_ratdens {
2768c2ecf20Sopenharmony_ci	int nrats;
2778c2ecf20Sopenharmony_ci	const struct snd_ratden *rats;
2788c2ecf20Sopenharmony_ci};
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistruct snd_pcm_hw_constraint_list {
2818c2ecf20Sopenharmony_ci	const unsigned int *list;
2828c2ecf20Sopenharmony_ci	unsigned int count;
2838c2ecf20Sopenharmony_ci	unsigned int mask;
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistruct snd_pcm_hw_constraint_ranges {
2878c2ecf20Sopenharmony_ci	unsigned int count;
2888c2ecf20Sopenharmony_ci	const struct snd_interval *ranges;
2898c2ecf20Sopenharmony_ci	unsigned int mask;
2908c2ecf20Sopenharmony_ci};
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci/*
2938c2ecf20Sopenharmony_ci * userspace-provided audio timestamp config to kernel,
2948c2ecf20Sopenharmony_ci * structure is for internal use only and filled with dedicated unpack routine
2958c2ecf20Sopenharmony_ci */
2968c2ecf20Sopenharmony_cistruct snd_pcm_audio_tstamp_config {
2978c2ecf20Sopenharmony_ci	/* 5 of max 16 bits used */
2988c2ecf20Sopenharmony_ci	u32 type_requested:4;
2998c2ecf20Sopenharmony_ci	u32 report_delay:1; /* add total delay to A/D or D/A */
3008c2ecf20Sopenharmony_ci};
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic inline void snd_pcm_unpack_audio_tstamp_config(__u32 data,
3038c2ecf20Sopenharmony_ci						struct snd_pcm_audio_tstamp_config *config)
3048c2ecf20Sopenharmony_ci{
3058c2ecf20Sopenharmony_ci	config->type_requested = data & 0xF;
3068c2ecf20Sopenharmony_ci	config->report_delay = (data >> 4) & 1;
3078c2ecf20Sopenharmony_ci}
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/*
3108c2ecf20Sopenharmony_ci * kernel-provided audio timestamp report to user-space
3118c2ecf20Sopenharmony_ci * structure is for internal use only and read by dedicated pack routine
3128c2ecf20Sopenharmony_ci */
3138c2ecf20Sopenharmony_cistruct snd_pcm_audio_tstamp_report {
3148c2ecf20Sopenharmony_ci	/* 6 of max 16 bits used for bit-fields */
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	/* for backwards compatibility */
3178c2ecf20Sopenharmony_ci	u32 valid:1;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	/* actual type if hardware could not support requested timestamp */
3208c2ecf20Sopenharmony_ci	u32 actual_type:4;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	/* accuracy represented in ns units */
3238c2ecf20Sopenharmony_ci	u32 accuracy_report:1; /* 0 if accuracy unknown, 1 if accuracy field is valid */
3248c2ecf20Sopenharmony_ci	u32 accuracy; /* up to 4.29s, will be packed in separate field  */
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistatic inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy,
3288c2ecf20Sopenharmony_ci						const struct snd_pcm_audio_tstamp_report *report)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	u32 tmp;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	tmp = report->accuracy_report;
3338c2ecf20Sopenharmony_ci	tmp <<= 4;
3348c2ecf20Sopenharmony_ci	tmp |= report->actual_type;
3358c2ecf20Sopenharmony_ci	tmp <<= 1;
3368c2ecf20Sopenharmony_ci	tmp |= report->valid;
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	*data &= 0xffff; /* zero-clear MSBs */
3398c2ecf20Sopenharmony_ci	*data |= (tmp << 16);
3408c2ecf20Sopenharmony_ci	*accuracy = report->accuracy;
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cistruct snd_pcm_runtime {
3458c2ecf20Sopenharmony_ci	/* -- Status -- */
3468c2ecf20Sopenharmony_ci	struct snd_pcm_substream *trigger_master;
3478c2ecf20Sopenharmony_ci	struct timespec64 trigger_tstamp;	/* trigger timestamp */
3488c2ecf20Sopenharmony_ci	bool trigger_tstamp_latched;     /* trigger timestamp latched in low-level driver/hardware */
3498c2ecf20Sopenharmony_ci	int overrange;
3508c2ecf20Sopenharmony_ci	snd_pcm_uframes_t avail_max;
3518c2ecf20Sopenharmony_ci	snd_pcm_uframes_t hw_ptr_base;	/* Position at buffer restart */
3528c2ecf20Sopenharmony_ci	snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
3538c2ecf20Sopenharmony_ci	unsigned long hw_ptr_jiffies;	/* Time when hw_ptr is updated */
3548c2ecf20Sopenharmony_ci	unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
3558c2ecf20Sopenharmony_ci	snd_pcm_sframes_t delay;	/* extra delay; typically FIFO size */
3568c2ecf20Sopenharmony_ci	u64 hw_ptr_wrap;                /* offset for hw_ptr due to boundary wrap-around */
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	/* -- HW params -- */
3598c2ecf20Sopenharmony_ci	snd_pcm_access_t access;	/* access mode */
3608c2ecf20Sopenharmony_ci	snd_pcm_format_t format;	/* SNDRV_PCM_FORMAT_* */
3618c2ecf20Sopenharmony_ci	snd_pcm_subformat_t subformat;	/* subformat */
3628c2ecf20Sopenharmony_ci	unsigned int rate;		/* rate in Hz */
3638c2ecf20Sopenharmony_ci	unsigned int channels;		/* channels */
3648c2ecf20Sopenharmony_ci	snd_pcm_uframes_t period_size;	/* period size */
3658c2ecf20Sopenharmony_ci	unsigned int periods;		/* periods */
3668c2ecf20Sopenharmony_ci	snd_pcm_uframes_t buffer_size;	/* buffer size */
3678c2ecf20Sopenharmony_ci	snd_pcm_uframes_t min_align;	/* Min alignment for the format */
3688c2ecf20Sopenharmony_ci	size_t byte_align;
3698c2ecf20Sopenharmony_ci	unsigned int frame_bits;
3708c2ecf20Sopenharmony_ci	unsigned int sample_bits;
3718c2ecf20Sopenharmony_ci	unsigned int info;
3728c2ecf20Sopenharmony_ci	unsigned int rate_num;
3738c2ecf20Sopenharmony_ci	unsigned int rate_den;
3748c2ecf20Sopenharmony_ci	unsigned int no_period_wakeup: 1;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	/* -- SW params -- */
3778c2ecf20Sopenharmony_ci	int tstamp_mode;		/* mmap timestamp is updated */
3788c2ecf20Sopenharmony_ci  	unsigned int period_step;
3798c2ecf20Sopenharmony_ci	snd_pcm_uframes_t start_threshold;
3808c2ecf20Sopenharmony_ci	snd_pcm_uframes_t stop_threshold;
3818c2ecf20Sopenharmony_ci	snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
3828c2ecf20Sopenharmony_ci						noise is nearest than this */
3838c2ecf20Sopenharmony_ci	snd_pcm_uframes_t silence_size;	/* Silence filling size */
3848c2ecf20Sopenharmony_ci	snd_pcm_uframes_t boundary;	/* pointers wrap point */
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
3878c2ecf20Sopenharmony_ci	snd_pcm_uframes_t silence_filled; /* size filled with silence */
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	union snd_pcm_sync_id sync;	/* hardware synchronization ID */
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	/* -- mmap -- */
3928c2ecf20Sopenharmony_ci	struct snd_pcm_mmap_status *status;
3938c2ecf20Sopenharmony_ci	struct snd_pcm_mmap_control *control;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	/* -- locking / scheduling -- */
3968c2ecf20Sopenharmony_ci	snd_pcm_uframes_t twake; 	/* do transfer (!poll) wakeup if non-zero */
3978c2ecf20Sopenharmony_ci	wait_queue_head_t sleep;	/* poll sleep */
3988c2ecf20Sopenharmony_ci	wait_queue_head_t tsleep;	/* transfer sleep */
3998c2ecf20Sopenharmony_ci	struct fasync_struct *fasync;
4008c2ecf20Sopenharmony_ci	bool stop_operating;		/* sync_stop will be called */
4018c2ecf20Sopenharmony_ci	struct mutex buffer_mutex;	/* protect for buffer changes */
4028c2ecf20Sopenharmony_ci	atomic_t buffer_accessing;	/* >0: in r/w operation, <0: blocked */
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	/* -- private section -- */
4058c2ecf20Sopenharmony_ci	void *private_data;
4068c2ecf20Sopenharmony_ci	void (*private_free)(struct snd_pcm_runtime *runtime);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	/* -- hardware description -- */
4098c2ecf20Sopenharmony_ci	struct snd_pcm_hardware hw;
4108c2ecf20Sopenharmony_ci	struct snd_pcm_hw_constraints hw_constraints;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	/* -- timer -- */
4138c2ecf20Sopenharmony_ci	unsigned int timer_resolution;	/* timer resolution */
4148c2ecf20Sopenharmony_ci	int tstamp_type;		/* timestamp type */
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	/* -- DMA -- */
4178c2ecf20Sopenharmony_ci	unsigned char *dma_area;	/* DMA area */
4188c2ecf20Sopenharmony_ci	dma_addr_t dma_addr;		/* physical bus address (not accessible from main CPU) */
4198c2ecf20Sopenharmony_ci	size_t dma_bytes;		/* size of DMA area */
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	struct snd_dma_buffer *dma_buffer_p;	/* allocated buffer */
4228c2ecf20Sopenharmony_ci	unsigned int buffer_changed:1;	/* buffer allocation changed; set only in managed mode */
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	/* -- audio timestamp config -- */
4258c2ecf20Sopenharmony_ci	struct snd_pcm_audio_tstamp_config audio_tstamp_config;
4268c2ecf20Sopenharmony_ci	struct snd_pcm_audio_tstamp_report audio_tstamp_report;
4278c2ecf20Sopenharmony_ci	struct timespec64 driver_tstamp;
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
4308c2ecf20Sopenharmony_ci	/* -- OSS things -- */
4318c2ecf20Sopenharmony_ci	struct snd_pcm_oss_runtime oss;
4328c2ecf20Sopenharmony_ci#endif
4338c2ecf20Sopenharmony_ci};
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistruct snd_pcm_group {		/* keep linked substreams */
4368c2ecf20Sopenharmony_ci	spinlock_t lock;
4378c2ecf20Sopenharmony_ci	struct mutex mutex;
4388c2ecf20Sopenharmony_ci	struct list_head substreams;
4398c2ecf20Sopenharmony_ci	refcount_t refs;
4408c2ecf20Sopenharmony_ci};
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cistruct pid;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistruct snd_pcm_substream {
4458c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
4468c2ecf20Sopenharmony_ci	struct snd_pcm_str *pstr;
4478c2ecf20Sopenharmony_ci	void *private_data;		/* copied from pcm->private_data */
4488c2ecf20Sopenharmony_ci	int number;
4498c2ecf20Sopenharmony_ci	char name[32];			/* substream name */
4508c2ecf20Sopenharmony_ci	int stream;			/* stream (direction) */
4518c2ecf20Sopenharmony_ci	struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
4528c2ecf20Sopenharmony_ci	size_t buffer_bytes_max;	/* limit ring buffer size */
4538c2ecf20Sopenharmony_ci	struct snd_dma_buffer dma_buffer;
4548c2ecf20Sopenharmony_ci	size_t dma_max;
4558c2ecf20Sopenharmony_ci	/* -- hardware operations -- */
4568c2ecf20Sopenharmony_ci	const struct snd_pcm_ops *ops;
4578c2ecf20Sopenharmony_ci	/* -- runtime information -- */
4588c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime;
4598c2ecf20Sopenharmony_ci        /* -- timer section -- */
4608c2ecf20Sopenharmony_ci	struct snd_timer *timer;		/* timer */
4618c2ecf20Sopenharmony_ci	unsigned timer_running: 1;	/* time is running */
4628c2ecf20Sopenharmony_ci	long wait_time;	/* time in ms for R/W to wait for avail */
4638c2ecf20Sopenharmony_ci	/* -- next substream -- */
4648c2ecf20Sopenharmony_ci	struct snd_pcm_substream *next;
4658c2ecf20Sopenharmony_ci	/* -- linked substreams -- */
4668c2ecf20Sopenharmony_ci	struct list_head link_list;	/* linked list member */
4678c2ecf20Sopenharmony_ci	struct snd_pcm_group self_group;	/* fake group for non linked substream (with substream lock inside) */
4688c2ecf20Sopenharmony_ci	struct snd_pcm_group *group;		/* pointer to current group */
4698c2ecf20Sopenharmony_ci	/* -- assigned files -- */
4708c2ecf20Sopenharmony_ci	int ref_count;
4718c2ecf20Sopenharmony_ci	atomic_t mmap_count;
4728c2ecf20Sopenharmony_ci	unsigned int f_flags;
4738c2ecf20Sopenharmony_ci	void (*pcm_release)(struct snd_pcm_substream *);
4748c2ecf20Sopenharmony_ci	struct pid *pid;
4758c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
4768c2ecf20Sopenharmony_ci	/* -- OSS things -- */
4778c2ecf20Sopenharmony_ci	struct snd_pcm_oss_substream oss;
4788c2ecf20Sopenharmony_ci#endif
4798c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_VERBOSE_PROCFS
4808c2ecf20Sopenharmony_ci	struct snd_info_entry *proc_root;
4818c2ecf20Sopenharmony_ci#endif /* CONFIG_SND_VERBOSE_PROCFS */
4828c2ecf20Sopenharmony_ci	/* misc flags */
4838c2ecf20Sopenharmony_ci	unsigned int hw_opened: 1;
4848c2ecf20Sopenharmony_ci	unsigned int managed_buffer_alloc:1;
4858c2ecf20Sopenharmony_ci};
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci#define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_cistruct snd_pcm_str {
4918c2ecf20Sopenharmony_ci	int stream;				/* stream (direction) */
4928c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
4938c2ecf20Sopenharmony_ci	/* -- substreams -- */
4948c2ecf20Sopenharmony_ci	unsigned int substream_count;
4958c2ecf20Sopenharmony_ci	unsigned int substream_opened;
4968c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream;
4978c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
4988c2ecf20Sopenharmony_ci	/* -- OSS things -- */
4998c2ecf20Sopenharmony_ci	struct snd_pcm_oss_stream oss;
5008c2ecf20Sopenharmony_ci#endif
5018c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_VERBOSE_PROCFS
5028c2ecf20Sopenharmony_ci	struct snd_info_entry *proc_root;
5038c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PCM_XRUN_DEBUG
5048c2ecf20Sopenharmony_ci	unsigned int xrun_debug;	/* 0 = disabled, 1 = verbose, 2 = stacktrace */
5058c2ecf20Sopenharmony_ci#endif
5068c2ecf20Sopenharmony_ci#endif
5078c2ecf20Sopenharmony_ci	struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
5088c2ecf20Sopenharmony_ci	struct device dev;
5098c2ecf20Sopenharmony_ci};
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_cistruct snd_pcm {
5128c2ecf20Sopenharmony_ci	struct snd_card *card;
5138c2ecf20Sopenharmony_ci	struct list_head list;
5148c2ecf20Sopenharmony_ci	int device; /* device number */
5158c2ecf20Sopenharmony_ci	unsigned int info_flags;
5168c2ecf20Sopenharmony_ci	unsigned short dev_class;
5178c2ecf20Sopenharmony_ci	unsigned short dev_subclass;
5188c2ecf20Sopenharmony_ci	char id[64];
5198c2ecf20Sopenharmony_ci	char name[80];
5208c2ecf20Sopenharmony_ci	struct snd_pcm_str streams[2];
5218c2ecf20Sopenharmony_ci	struct mutex open_mutex;
5228c2ecf20Sopenharmony_ci	wait_queue_head_t open_wait;
5238c2ecf20Sopenharmony_ci	void *private_data;
5248c2ecf20Sopenharmony_ci	void (*private_free) (struct snd_pcm *pcm);
5258c2ecf20Sopenharmony_ci	bool internal; /* pcm is for internal use only */
5268c2ecf20Sopenharmony_ci	bool nonatomic; /* whole PCM operations are in non-atomic context */
5278c2ecf20Sopenharmony_ci	bool no_device_suspend; /* don't invoke device PM suspend */
5288c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
5298c2ecf20Sopenharmony_ci	struct snd_pcm_oss oss;
5308c2ecf20Sopenharmony_ci#endif
5318c2ecf20Sopenharmony_ci};
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci/*
5348c2ecf20Sopenharmony_ci *  Registering
5358c2ecf20Sopenharmony_ci */
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ciextern const struct file_operations snd_pcm_f_ops[2];
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ciint snd_pcm_new(struct snd_card *card, const char *id, int device,
5408c2ecf20Sopenharmony_ci		int playback_count, int capture_count,
5418c2ecf20Sopenharmony_ci		struct snd_pcm **rpcm);
5428c2ecf20Sopenharmony_ciint snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
5438c2ecf20Sopenharmony_ci		int playback_count, int capture_count,
5448c2ecf20Sopenharmony_ci		struct snd_pcm **rpcm);
5458c2ecf20Sopenharmony_ciint snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_PCM_OSS)
5488c2ecf20Sopenharmony_cistruct snd_pcm_notify {
5498c2ecf20Sopenharmony_ci	int (*n_register) (struct snd_pcm * pcm);
5508c2ecf20Sopenharmony_ci	int (*n_disconnect) (struct snd_pcm * pcm);
5518c2ecf20Sopenharmony_ci	int (*n_unregister) (struct snd_pcm * pcm);
5528c2ecf20Sopenharmony_ci	struct list_head list;
5538c2ecf20Sopenharmony_ci};
5548c2ecf20Sopenharmony_ciint snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
5558c2ecf20Sopenharmony_ci#endif
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci/*
5588c2ecf20Sopenharmony_ci *  Native I/O
5598c2ecf20Sopenharmony_ci */
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ciint snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
5628c2ecf20Sopenharmony_ciint snd_pcm_info_user(struct snd_pcm_substream *substream,
5638c2ecf20Sopenharmony_ci		      struct snd_pcm_info __user *info);
5648c2ecf20Sopenharmony_ciint snd_pcm_status64(struct snd_pcm_substream *substream,
5658c2ecf20Sopenharmony_ci		     struct snd_pcm_status64 *status);
5668c2ecf20Sopenharmony_ciint snd_pcm_start(struct snd_pcm_substream *substream);
5678c2ecf20Sopenharmony_ciint snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
5688c2ecf20Sopenharmony_ciint snd_pcm_drain_done(struct snd_pcm_substream *substream);
5698c2ecf20Sopenharmony_ciint snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
5708c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
5718c2ecf20Sopenharmony_ciint snd_pcm_suspend_all(struct snd_pcm *pcm);
5728c2ecf20Sopenharmony_ci#else
5738c2ecf20Sopenharmony_cistatic inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
5748c2ecf20Sopenharmony_ci{
5758c2ecf20Sopenharmony_ci	return 0;
5768c2ecf20Sopenharmony_ci}
5778c2ecf20Sopenharmony_ci#endif
5788c2ecf20Sopenharmony_ciint snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
5798c2ecf20Sopenharmony_ciint snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
5808c2ecf20Sopenharmony_ci			   struct snd_pcm_substream **rsubstream);
5818c2ecf20Sopenharmony_civoid snd_pcm_release_substream(struct snd_pcm_substream *substream);
5828c2ecf20Sopenharmony_ciint snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
5838c2ecf20Sopenharmony_ci			     struct snd_pcm_substream **rsubstream);
5848c2ecf20Sopenharmony_civoid snd_pcm_detach_substream(struct snd_pcm_substream *substream);
5858c2ecf20Sopenharmony_ciint snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG
5898c2ecf20Sopenharmony_civoid snd_pcm_debug_name(struct snd_pcm_substream *substream,
5908c2ecf20Sopenharmony_ci			   char *name, size_t len);
5918c2ecf20Sopenharmony_ci#else
5928c2ecf20Sopenharmony_cistatic inline void
5938c2ecf20Sopenharmony_cisnd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
5948c2ecf20Sopenharmony_ci{
5958c2ecf20Sopenharmony_ci	*buf = 0;
5968c2ecf20Sopenharmony_ci}
5978c2ecf20Sopenharmony_ci#endif
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci/*
6008c2ecf20Sopenharmony_ci *  PCM library
6018c2ecf20Sopenharmony_ci */
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci/**
6048c2ecf20Sopenharmony_ci * snd_pcm_stream_linked - Check whether the substream is linked with others
6058c2ecf20Sopenharmony_ci * @substream: substream to check
6068c2ecf20Sopenharmony_ci *
6078c2ecf20Sopenharmony_ci * Returns true if the given substream is being linked with others.
6088c2ecf20Sopenharmony_ci */
6098c2ecf20Sopenharmony_cistatic inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
6108c2ecf20Sopenharmony_ci{
6118c2ecf20Sopenharmony_ci	return substream->group != &substream->self_group;
6128c2ecf20Sopenharmony_ci}
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_civoid snd_pcm_stream_lock(struct snd_pcm_substream *substream);
6158c2ecf20Sopenharmony_civoid snd_pcm_stream_unlock(struct snd_pcm_substream *substream);
6168c2ecf20Sopenharmony_civoid snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream);
6178c2ecf20Sopenharmony_civoid snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream);
6188c2ecf20Sopenharmony_ciunsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci/**
6218c2ecf20Sopenharmony_ci * snd_pcm_stream_lock_irqsave - Lock the PCM stream
6228c2ecf20Sopenharmony_ci * @substream: PCM substream
6238c2ecf20Sopenharmony_ci * @flags: irq flags
6248c2ecf20Sopenharmony_ci *
6258c2ecf20Sopenharmony_ci * This locks the PCM stream like snd_pcm_stream_lock() but with the local
6268c2ecf20Sopenharmony_ci * IRQ (only when nonatomic is false).  In nonatomic case, this is identical
6278c2ecf20Sopenharmony_ci * as snd_pcm_stream_lock().
6288c2ecf20Sopenharmony_ci */
6298c2ecf20Sopenharmony_ci#define snd_pcm_stream_lock_irqsave(substream, flags)		 \
6308c2ecf20Sopenharmony_ci	do {							 \
6318c2ecf20Sopenharmony_ci		typecheck(unsigned long, flags);		 \
6328c2ecf20Sopenharmony_ci		flags = _snd_pcm_stream_lock_irqsave(substream); \
6338c2ecf20Sopenharmony_ci	} while (0)
6348c2ecf20Sopenharmony_civoid snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
6358c2ecf20Sopenharmony_ci				      unsigned long flags);
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci/**
6388c2ecf20Sopenharmony_ci * snd_pcm_group_for_each_entry - iterate over the linked substreams
6398c2ecf20Sopenharmony_ci * @s: the iterator
6408c2ecf20Sopenharmony_ci * @substream: the substream
6418c2ecf20Sopenharmony_ci *
6428c2ecf20Sopenharmony_ci * Iterate over the all linked substreams to the given @substream.
6438c2ecf20Sopenharmony_ci * When @substream isn't linked with any others, this gives returns @substream
6448c2ecf20Sopenharmony_ci * itself once.
6458c2ecf20Sopenharmony_ci */
6468c2ecf20Sopenharmony_ci#define snd_pcm_group_for_each_entry(s, substream) \
6478c2ecf20Sopenharmony_ci	list_for_each_entry(s, &substream->group->substreams, link_list)
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci#define for_each_pcm_streams(stream)			\
6508c2ecf20Sopenharmony_ci	for (stream  = SNDRV_PCM_STREAM_PLAYBACK;	\
6518c2ecf20Sopenharmony_ci	     stream <= SNDRV_PCM_STREAM_LAST;		\
6528c2ecf20Sopenharmony_ci	     stream++)
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci/**
6558c2ecf20Sopenharmony_ci * snd_pcm_running - Check whether the substream is in a running state
6568c2ecf20Sopenharmony_ci * @substream: substream to check
6578c2ecf20Sopenharmony_ci *
6588c2ecf20Sopenharmony_ci * Returns true if the given substream is in the state RUNNING, or in the
6598c2ecf20Sopenharmony_ci * state DRAINING for playback.
6608c2ecf20Sopenharmony_ci */
6618c2ecf20Sopenharmony_cistatic inline int snd_pcm_running(struct snd_pcm_substream *substream)
6628c2ecf20Sopenharmony_ci{
6638c2ecf20Sopenharmony_ci	return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
6648c2ecf20Sopenharmony_ci		(substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
6658c2ecf20Sopenharmony_ci		 substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
6668c2ecf20Sopenharmony_ci}
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci/**
6698c2ecf20Sopenharmony_ci * bytes_to_samples - Unit conversion of the size from bytes to samples
6708c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
6718c2ecf20Sopenharmony_ci * @size: size in bytes
6728c2ecf20Sopenharmony_ci */
6738c2ecf20Sopenharmony_cistatic inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
6748c2ecf20Sopenharmony_ci{
6758c2ecf20Sopenharmony_ci	return size * 8 / runtime->sample_bits;
6768c2ecf20Sopenharmony_ci}
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci/**
6798c2ecf20Sopenharmony_ci * bytes_to_frames - Unit conversion of the size from bytes to frames
6808c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
6818c2ecf20Sopenharmony_ci * @size: size in bytes
6828c2ecf20Sopenharmony_ci */
6838c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
6848c2ecf20Sopenharmony_ci{
6858c2ecf20Sopenharmony_ci	return size * 8 / runtime->frame_bits;
6868c2ecf20Sopenharmony_ci}
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci/**
6898c2ecf20Sopenharmony_ci * samples_to_bytes - Unit conversion of the size from samples to bytes
6908c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
6918c2ecf20Sopenharmony_ci * @size: size in samples
6928c2ecf20Sopenharmony_ci */
6938c2ecf20Sopenharmony_cistatic inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
6948c2ecf20Sopenharmony_ci{
6958c2ecf20Sopenharmony_ci	return size * runtime->sample_bits / 8;
6968c2ecf20Sopenharmony_ci}
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci/**
6998c2ecf20Sopenharmony_ci * frames_to_bytes - Unit conversion of the size from frames to bytes
7008c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7018c2ecf20Sopenharmony_ci * @size: size in frames
7028c2ecf20Sopenharmony_ci */
7038c2ecf20Sopenharmony_cistatic inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
7048c2ecf20Sopenharmony_ci{
7058c2ecf20Sopenharmony_ci	return size * runtime->frame_bits / 8;
7068c2ecf20Sopenharmony_ci}
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci/**
7098c2ecf20Sopenharmony_ci * frame_aligned - Check whether the byte size is aligned to frames
7108c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7118c2ecf20Sopenharmony_ci * @bytes: size in bytes
7128c2ecf20Sopenharmony_ci */
7138c2ecf20Sopenharmony_cistatic inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
7148c2ecf20Sopenharmony_ci{
7158c2ecf20Sopenharmony_ci	return bytes % runtime->byte_align == 0;
7168c2ecf20Sopenharmony_ci}
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci/**
7198c2ecf20Sopenharmony_ci * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
7208c2ecf20Sopenharmony_ci * @substream: PCM substream
7218c2ecf20Sopenharmony_ci */
7228c2ecf20Sopenharmony_cistatic inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
7238c2ecf20Sopenharmony_ci{
7248c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
7258c2ecf20Sopenharmony_ci	return frames_to_bytes(runtime, runtime->buffer_size);
7268c2ecf20Sopenharmony_ci}
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci/**
7298c2ecf20Sopenharmony_ci * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
7308c2ecf20Sopenharmony_ci * @substream: PCM substream
7318c2ecf20Sopenharmony_ci */
7328c2ecf20Sopenharmony_cistatic inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
7338c2ecf20Sopenharmony_ci{
7348c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
7358c2ecf20Sopenharmony_ci	return frames_to_bytes(runtime, runtime->period_size);
7368c2ecf20Sopenharmony_ci}
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci/**
7398c2ecf20Sopenharmony_ci * snd_pcm_playback_avail - Get the available (writable) space for playback
7408c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7418c2ecf20Sopenharmony_ci *
7428c2ecf20Sopenharmony_ci * Result is between 0 ... (boundary - 1)
7438c2ecf20Sopenharmony_ci */
7448c2ecf20Sopenharmony_cistatic inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
7458c2ecf20Sopenharmony_ci{
7468c2ecf20Sopenharmony_ci	snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
7478c2ecf20Sopenharmony_ci	if (avail < 0)
7488c2ecf20Sopenharmony_ci		avail += runtime->boundary;
7498c2ecf20Sopenharmony_ci	else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
7508c2ecf20Sopenharmony_ci		avail -= runtime->boundary;
7518c2ecf20Sopenharmony_ci	return avail;
7528c2ecf20Sopenharmony_ci}
7538c2ecf20Sopenharmony_ci
7548c2ecf20Sopenharmony_ci/**
7558c2ecf20Sopenharmony_ci * snd_pcm_capture_avail - Get the available (readable) space for capture
7568c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7578c2ecf20Sopenharmony_ci *
7588c2ecf20Sopenharmony_ci * Result is between 0 ... (boundary - 1)
7598c2ecf20Sopenharmony_ci */
7608c2ecf20Sopenharmony_cistatic inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
7618c2ecf20Sopenharmony_ci{
7628c2ecf20Sopenharmony_ci	snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
7638c2ecf20Sopenharmony_ci	if (avail < 0)
7648c2ecf20Sopenharmony_ci		avail += runtime->boundary;
7658c2ecf20Sopenharmony_ci	return avail;
7668c2ecf20Sopenharmony_ci}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci/**
7698c2ecf20Sopenharmony_ci * snd_pcm_playback_hw_avail - Get the queued space for playback
7708c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7718c2ecf20Sopenharmony_ci */
7728c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
7738c2ecf20Sopenharmony_ci{
7748c2ecf20Sopenharmony_ci	return runtime->buffer_size - snd_pcm_playback_avail(runtime);
7758c2ecf20Sopenharmony_ci}
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci/**
7788c2ecf20Sopenharmony_ci * snd_pcm_capture_hw_avail - Get the free space for capture
7798c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
7808c2ecf20Sopenharmony_ci */
7818c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
7828c2ecf20Sopenharmony_ci{
7838c2ecf20Sopenharmony_ci	return runtime->buffer_size - snd_pcm_capture_avail(runtime);
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci/**
7878c2ecf20Sopenharmony_ci * snd_pcm_playback_ready - check whether the playback buffer is available
7888c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
7898c2ecf20Sopenharmony_ci *
7908c2ecf20Sopenharmony_ci * Checks whether enough free space is available on the playback buffer.
7918c2ecf20Sopenharmony_ci *
7928c2ecf20Sopenharmony_ci * Return: Non-zero if available, or zero if not.
7938c2ecf20Sopenharmony_ci */
7948c2ecf20Sopenharmony_cistatic inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
7958c2ecf20Sopenharmony_ci{
7968c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
7978c2ecf20Sopenharmony_ci	return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
7988c2ecf20Sopenharmony_ci}
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ci/**
8018c2ecf20Sopenharmony_ci * snd_pcm_capture_ready - check whether the capture buffer is available
8028c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
8038c2ecf20Sopenharmony_ci *
8048c2ecf20Sopenharmony_ci * Checks whether enough capture data is available on the capture buffer.
8058c2ecf20Sopenharmony_ci *
8068c2ecf20Sopenharmony_ci * Return: Non-zero if available, or zero if not.
8078c2ecf20Sopenharmony_ci */
8088c2ecf20Sopenharmony_cistatic inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
8098c2ecf20Sopenharmony_ci{
8108c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
8118c2ecf20Sopenharmony_ci	return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
8128c2ecf20Sopenharmony_ci}
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci/**
8158c2ecf20Sopenharmony_ci * snd_pcm_playback_data - check whether any data exists on the playback buffer
8168c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
8178c2ecf20Sopenharmony_ci *
8188c2ecf20Sopenharmony_ci * Checks whether any data exists on the playback buffer.
8198c2ecf20Sopenharmony_ci *
8208c2ecf20Sopenharmony_ci * Return: Non-zero if any data exists, or zero if not. If stop_threshold
8218c2ecf20Sopenharmony_ci * is bigger or equal to boundary, then this function returns always non-zero.
8228c2ecf20Sopenharmony_ci */
8238c2ecf20Sopenharmony_cistatic inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
8248c2ecf20Sopenharmony_ci{
8258c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ci	if (runtime->stop_threshold >= runtime->boundary)
8288c2ecf20Sopenharmony_ci		return 1;
8298c2ecf20Sopenharmony_ci	return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
8308c2ecf20Sopenharmony_ci}
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci/**
8338c2ecf20Sopenharmony_ci * snd_pcm_playback_empty - check whether the playback buffer is empty
8348c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
8358c2ecf20Sopenharmony_ci *
8368c2ecf20Sopenharmony_ci * Checks whether the playback buffer is empty.
8378c2ecf20Sopenharmony_ci *
8388c2ecf20Sopenharmony_ci * Return: Non-zero if empty, or zero if not.
8398c2ecf20Sopenharmony_ci */
8408c2ecf20Sopenharmony_cistatic inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
8418c2ecf20Sopenharmony_ci{
8428c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
8438c2ecf20Sopenharmony_ci	return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
8448c2ecf20Sopenharmony_ci}
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci/**
8478c2ecf20Sopenharmony_ci * snd_pcm_capture_empty - check whether the capture buffer is empty
8488c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
8498c2ecf20Sopenharmony_ci *
8508c2ecf20Sopenharmony_ci * Checks whether the capture buffer is empty.
8518c2ecf20Sopenharmony_ci *
8528c2ecf20Sopenharmony_ci * Return: Non-zero if empty, or zero if not.
8538c2ecf20Sopenharmony_ci */
8548c2ecf20Sopenharmony_cistatic inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
8558c2ecf20Sopenharmony_ci{
8568c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
8578c2ecf20Sopenharmony_ci	return snd_pcm_capture_avail(runtime) == 0;
8588c2ecf20Sopenharmony_ci}
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci/**
8618c2ecf20Sopenharmony_ci * snd_pcm_trigger_done - Mark the master substream
8628c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
8638c2ecf20Sopenharmony_ci * @master: the linked master substream
8648c2ecf20Sopenharmony_ci *
8658c2ecf20Sopenharmony_ci * When multiple substreams of the same card are linked and the hardware
8668c2ecf20Sopenharmony_ci * supports the single-shot operation, the driver calls this in the loop
8678c2ecf20Sopenharmony_ci * in snd_pcm_group_for_each_entry() for marking the substream as "done".
8688c2ecf20Sopenharmony_ci * Then most of trigger operations are performed only to the given master
8698c2ecf20Sopenharmony_ci * substream.
8708c2ecf20Sopenharmony_ci *
8718c2ecf20Sopenharmony_ci * The trigger_master mark is cleared at timestamp updates at the end
8728c2ecf20Sopenharmony_ci * of trigger operations.
8738c2ecf20Sopenharmony_ci */
8748c2ecf20Sopenharmony_cistatic inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
8758c2ecf20Sopenharmony_ci					struct snd_pcm_substream *master)
8768c2ecf20Sopenharmony_ci{
8778c2ecf20Sopenharmony_ci	substream->runtime->trigger_master = master;
8788c2ecf20Sopenharmony_ci}
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_cistatic inline int hw_is_mask(int var)
8818c2ecf20Sopenharmony_ci{
8828c2ecf20Sopenharmony_ci	return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
8838c2ecf20Sopenharmony_ci		var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
8848c2ecf20Sopenharmony_ci}
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_cistatic inline int hw_is_interval(int var)
8878c2ecf20Sopenharmony_ci{
8888c2ecf20Sopenharmony_ci	return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
8898c2ecf20Sopenharmony_ci		var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
8908c2ecf20Sopenharmony_ci}
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_cistatic inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
8938c2ecf20Sopenharmony_ci				     snd_pcm_hw_param_t var)
8948c2ecf20Sopenharmony_ci{
8958c2ecf20Sopenharmony_ci	return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
8968c2ecf20Sopenharmony_ci}
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_cistatic inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
8998c2ecf20Sopenharmony_ci					     snd_pcm_hw_param_t var)
9008c2ecf20Sopenharmony_ci{
9018c2ecf20Sopenharmony_ci	return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
9028c2ecf20Sopenharmony_ci}
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_cistatic inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
9058c2ecf20Sopenharmony_ci					     snd_pcm_hw_param_t var)
9068c2ecf20Sopenharmony_ci{
9078c2ecf20Sopenharmony_ci	return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
9088c2ecf20Sopenharmony_ci}
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_cistatic inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
9118c2ecf20Sopenharmony_ci						     snd_pcm_hw_param_t var)
9128c2ecf20Sopenharmony_ci{
9138c2ecf20Sopenharmony_ci	return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
9148c2ecf20Sopenharmony_ci}
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci/**
9178c2ecf20Sopenharmony_ci * params_channels - Get the number of channels from the hw params
9188c2ecf20Sopenharmony_ci * @p: hw params
9198c2ecf20Sopenharmony_ci */
9208c2ecf20Sopenharmony_cistatic inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
9218c2ecf20Sopenharmony_ci{
9228c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_CHANNELS)->min;
9238c2ecf20Sopenharmony_ci}
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci/**
9268c2ecf20Sopenharmony_ci * params_rate - Get the sample rate from the hw params
9278c2ecf20Sopenharmony_ci * @p: hw params
9288c2ecf20Sopenharmony_ci */
9298c2ecf20Sopenharmony_cistatic inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
9308c2ecf20Sopenharmony_ci{
9318c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_RATE)->min;
9328c2ecf20Sopenharmony_ci}
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci/**
9358c2ecf20Sopenharmony_ci * params_period_size - Get the period size (in frames) from the hw params
9368c2ecf20Sopenharmony_ci * @p: hw params
9378c2ecf20Sopenharmony_ci */
9388c2ecf20Sopenharmony_cistatic inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
9398c2ecf20Sopenharmony_ci{
9408c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min;
9418c2ecf20Sopenharmony_ci}
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci/**
9448c2ecf20Sopenharmony_ci * params_periods - Get the number of periods from the hw params
9458c2ecf20Sopenharmony_ci * @p: hw params
9468c2ecf20Sopenharmony_ci */
9478c2ecf20Sopenharmony_cistatic inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
9488c2ecf20Sopenharmony_ci{
9498c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIODS)->min;
9508c2ecf20Sopenharmony_ci}
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci/**
9538c2ecf20Sopenharmony_ci * params_buffer_size - Get the buffer size (in frames) from the hw params
9548c2ecf20Sopenharmony_ci * @p: hw params
9558c2ecf20Sopenharmony_ci */
9568c2ecf20Sopenharmony_cistatic inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
9578c2ecf20Sopenharmony_ci{
9588c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min;
9598c2ecf20Sopenharmony_ci}
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci/**
9628c2ecf20Sopenharmony_ci * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
9638c2ecf20Sopenharmony_ci * @p: hw params
9648c2ecf20Sopenharmony_ci */
9658c2ecf20Sopenharmony_cistatic inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
9668c2ecf20Sopenharmony_ci{
9678c2ecf20Sopenharmony_ci	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min;
9688c2ecf20Sopenharmony_ci}
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ciint snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
9718c2ecf20Sopenharmony_ciint snd_interval_list(struct snd_interval *i, unsigned int count,
9728c2ecf20Sopenharmony_ci		      const unsigned int *list, unsigned int mask);
9738c2ecf20Sopenharmony_ciint snd_interval_ranges(struct snd_interval *i, unsigned int count,
9748c2ecf20Sopenharmony_ci			const struct snd_interval *list, unsigned int mask);
9758c2ecf20Sopenharmony_ciint snd_interval_ratnum(struct snd_interval *i,
9768c2ecf20Sopenharmony_ci			unsigned int rats_count, const struct snd_ratnum *rats,
9778c2ecf20Sopenharmony_ci			unsigned int *nump, unsigned int *denp);
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_civoid _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
9808c2ecf20Sopenharmony_civoid _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
9818c2ecf20Sopenharmony_ci
9828c2ecf20Sopenharmony_ciint snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
9858c2ecf20Sopenharmony_ci				 u_int64_t mask);
9868c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
9878c2ecf20Sopenharmony_ci				 unsigned int min, unsigned int max);
9888c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
9898c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
9908c2ecf20Sopenharmony_ci			       unsigned int cond,
9918c2ecf20Sopenharmony_ci			       snd_pcm_hw_param_t var,
9928c2ecf20Sopenharmony_ci			       const struct snd_pcm_hw_constraint_list *l);
9938c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
9948c2ecf20Sopenharmony_ci				 unsigned int cond,
9958c2ecf20Sopenharmony_ci				 snd_pcm_hw_param_t var,
9968c2ecf20Sopenharmony_ci				 const struct snd_pcm_hw_constraint_ranges *r);
9978c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
9988c2ecf20Sopenharmony_ci				  unsigned int cond,
9998c2ecf20Sopenharmony_ci				  snd_pcm_hw_param_t var,
10008c2ecf20Sopenharmony_ci				  const struct snd_pcm_hw_constraint_ratnums *r);
10018c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
10028c2ecf20Sopenharmony_ci				  unsigned int cond,
10038c2ecf20Sopenharmony_ci				  snd_pcm_hw_param_t var,
10048c2ecf20Sopenharmony_ci				  const struct snd_pcm_hw_constraint_ratdens *r);
10058c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
10068c2ecf20Sopenharmony_ci				 unsigned int cond,
10078c2ecf20Sopenharmony_ci				 unsigned int width,
10088c2ecf20Sopenharmony_ci				 unsigned int msbits);
10098c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
10108c2ecf20Sopenharmony_ci			       unsigned int cond,
10118c2ecf20Sopenharmony_ci			       snd_pcm_hw_param_t var,
10128c2ecf20Sopenharmony_ci			       unsigned long step);
10138c2ecf20Sopenharmony_ciint snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
10148c2ecf20Sopenharmony_ci			       unsigned int cond,
10158c2ecf20Sopenharmony_ci			       snd_pcm_hw_param_t var);
10168c2ecf20Sopenharmony_ciint snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
10178c2ecf20Sopenharmony_ci			       unsigned int base_rate);
10188c2ecf20Sopenharmony_ciint snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
10198c2ecf20Sopenharmony_ci			unsigned int cond,
10208c2ecf20Sopenharmony_ci			int var,
10218c2ecf20Sopenharmony_ci			snd_pcm_hw_rule_func_t func, void *private,
10228c2ecf20Sopenharmony_ci			int dep, ...);
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci/**
10258c2ecf20Sopenharmony_ci * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
10268c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
10278c2ecf20Sopenharmony_ci * @var: The hw_params variable to constrain
10288c2ecf20Sopenharmony_ci * @val: The value to constrain to
10298c2ecf20Sopenharmony_ci *
10308c2ecf20Sopenharmony_ci * Return: Positive if the value is changed, zero if it's not changed, or a
10318c2ecf20Sopenharmony_ci * negative error code.
10328c2ecf20Sopenharmony_ci */
10338c2ecf20Sopenharmony_cistatic inline int snd_pcm_hw_constraint_single(
10348c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
10358c2ecf20Sopenharmony_ci	unsigned int val)
10368c2ecf20Sopenharmony_ci{
10378c2ecf20Sopenharmony_ci	return snd_pcm_hw_constraint_minmax(runtime, var, val, val);
10388c2ecf20Sopenharmony_ci}
10398c2ecf20Sopenharmony_ci
10408c2ecf20Sopenharmony_ciint snd_pcm_format_signed(snd_pcm_format_t format);
10418c2ecf20Sopenharmony_ciint snd_pcm_format_unsigned(snd_pcm_format_t format);
10428c2ecf20Sopenharmony_ciint snd_pcm_format_linear(snd_pcm_format_t format);
10438c2ecf20Sopenharmony_ciint snd_pcm_format_little_endian(snd_pcm_format_t format);
10448c2ecf20Sopenharmony_ciint snd_pcm_format_big_endian(snd_pcm_format_t format);
10458c2ecf20Sopenharmony_ci#if 0 /* just for kernel-doc */
10468c2ecf20Sopenharmony_ci/**
10478c2ecf20Sopenharmony_ci * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
10488c2ecf20Sopenharmony_ci * @format: the format to check
10498c2ecf20Sopenharmony_ci *
10508c2ecf20Sopenharmony_ci * Return: 1 if the given PCM format is CPU-endian, 0 if
10518c2ecf20Sopenharmony_ci * opposite, or a negative error code if endian not specified.
10528c2ecf20Sopenharmony_ci */
10538c2ecf20Sopenharmony_ciint snd_pcm_format_cpu_endian(snd_pcm_format_t format);
10548c2ecf20Sopenharmony_ci#endif /* DocBook */
10558c2ecf20Sopenharmony_ci#ifdef SNDRV_LITTLE_ENDIAN
10568c2ecf20Sopenharmony_ci#define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
10578c2ecf20Sopenharmony_ci#else
10588c2ecf20Sopenharmony_ci#define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
10598c2ecf20Sopenharmony_ci#endif
10608c2ecf20Sopenharmony_ciint snd_pcm_format_width(snd_pcm_format_t format);			/* in bits */
10618c2ecf20Sopenharmony_ciint snd_pcm_format_physical_width(snd_pcm_format_t format);		/* in bits */
10628c2ecf20Sopenharmony_cissize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
10638c2ecf20Sopenharmony_ciconst unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
10648c2ecf20Sopenharmony_ciint snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_civoid snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
10678c2ecf20Sopenharmony_ci		     const struct snd_pcm_ops *ops);
10688c2ecf20Sopenharmony_civoid snd_pcm_set_sync(struct snd_pcm_substream *substream);
10698c2ecf20Sopenharmony_ciint snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
10708c2ecf20Sopenharmony_ci		      unsigned int cmd, void *arg);
10718c2ecf20Sopenharmony_civoid snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
10728c2ecf20Sopenharmony_cisnd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
10738c2ecf20Sopenharmony_ci				     void *buf, bool interleaved,
10748c2ecf20Sopenharmony_ci				     snd_pcm_uframes_t frames, bool in_kernel);
10758c2ecf20Sopenharmony_ci
10768c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
10778c2ecf20Sopenharmony_cisnd_pcm_lib_write(struct snd_pcm_substream *substream,
10788c2ecf20Sopenharmony_ci		  const void __user *buf, snd_pcm_uframes_t frames)
10798c2ecf20Sopenharmony_ci{
10808c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, (void __force *)buf, true, frames, false);
10818c2ecf20Sopenharmony_ci}
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
10848c2ecf20Sopenharmony_cisnd_pcm_lib_read(struct snd_pcm_substream *substream,
10858c2ecf20Sopenharmony_ci		 void __user *buf, snd_pcm_uframes_t frames)
10868c2ecf20Sopenharmony_ci{
10878c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, (void __force *)buf, true, frames, false);
10888c2ecf20Sopenharmony_ci}
10898c2ecf20Sopenharmony_ci
10908c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
10918c2ecf20Sopenharmony_cisnd_pcm_lib_writev(struct snd_pcm_substream *substream,
10928c2ecf20Sopenharmony_ci		   void __user **bufs, snd_pcm_uframes_t frames)
10938c2ecf20Sopenharmony_ci{
10948c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, (void *)bufs, false, frames, false);
10958c2ecf20Sopenharmony_ci}
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
10988c2ecf20Sopenharmony_cisnd_pcm_lib_readv(struct snd_pcm_substream *substream,
10998c2ecf20Sopenharmony_ci		  void __user **bufs, snd_pcm_uframes_t frames)
11008c2ecf20Sopenharmony_ci{
11018c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, (void *)bufs, false, frames, false);
11028c2ecf20Sopenharmony_ci}
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
11058c2ecf20Sopenharmony_cisnd_pcm_kernel_write(struct snd_pcm_substream *substream,
11068c2ecf20Sopenharmony_ci		     const void *buf, snd_pcm_uframes_t frames)
11078c2ecf20Sopenharmony_ci{
11088c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, (void *)buf, true, frames, true);
11098c2ecf20Sopenharmony_ci}
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
11128c2ecf20Sopenharmony_cisnd_pcm_kernel_read(struct snd_pcm_substream *substream,
11138c2ecf20Sopenharmony_ci		    void *buf, snd_pcm_uframes_t frames)
11148c2ecf20Sopenharmony_ci{
11158c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, buf, true, frames, true);
11168c2ecf20Sopenharmony_ci}
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
11198c2ecf20Sopenharmony_cisnd_pcm_kernel_writev(struct snd_pcm_substream *substream,
11208c2ecf20Sopenharmony_ci		      void **bufs, snd_pcm_uframes_t frames)
11218c2ecf20Sopenharmony_ci{
11228c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, bufs, false, frames, true);
11238c2ecf20Sopenharmony_ci}
11248c2ecf20Sopenharmony_ci
11258c2ecf20Sopenharmony_cistatic inline snd_pcm_sframes_t
11268c2ecf20Sopenharmony_cisnd_pcm_kernel_readv(struct snd_pcm_substream *substream,
11278c2ecf20Sopenharmony_ci		     void **bufs, snd_pcm_uframes_t frames)
11288c2ecf20Sopenharmony_ci{
11298c2ecf20Sopenharmony_ci	return __snd_pcm_lib_xfer(substream, bufs, false, frames, true);
11308c2ecf20Sopenharmony_ci}
11318c2ecf20Sopenharmony_ci
11328c2ecf20Sopenharmony_ciint snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw);
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_cistatic inline int
11358c2ecf20Sopenharmony_cisnd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
11368c2ecf20Sopenharmony_ci{
11378c2ecf20Sopenharmony_ci	return snd_pcm_hw_limit_rates(&runtime->hw);
11388c2ecf20Sopenharmony_ci}
11398c2ecf20Sopenharmony_ci
11408c2ecf20Sopenharmony_ciunsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
11418c2ecf20Sopenharmony_ciunsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
11428c2ecf20Sopenharmony_ciunsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
11438c2ecf20Sopenharmony_ci					 unsigned int rates_b);
11448c2ecf20Sopenharmony_ciunsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
11458c2ecf20Sopenharmony_ci					unsigned int rate_max);
11468c2ecf20Sopenharmony_ci
11478c2ecf20Sopenharmony_ci/**
11488c2ecf20Sopenharmony_ci * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
11498c2ecf20Sopenharmony_ci * @substream: PCM substream to set
11508c2ecf20Sopenharmony_ci * @bufp: the buffer information, NULL to clear
11518c2ecf20Sopenharmony_ci *
11528c2ecf20Sopenharmony_ci * Copy the buffer information to runtime->dma_buffer when @bufp is non-NULL.
11538c2ecf20Sopenharmony_ci * Otherwise it clears the current buffer information.
11548c2ecf20Sopenharmony_ci */
11558c2ecf20Sopenharmony_cistatic inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
11568c2ecf20Sopenharmony_ci					      struct snd_dma_buffer *bufp)
11578c2ecf20Sopenharmony_ci{
11588c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
11598c2ecf20Sopenharmony_ci	if (bufp) {
11608c2ecf20Sopenharmony_ci		runtime->dma_buffer_p = bufp;
11618c2ecf20Sopenharmony_ci		runtime->dma_area = bufp->area;
11628c2ecf20Sopenharmony_ci		runtime->dma_addr = bufp->addr;
11638c2ecf20Sopenharmony_ci		runtime->dma_bytes = bufp->bytes;
11648c2ecf20Sopenharmony_ci	} else {
11658c2ecf20Sopenharmony_ci		runtime->dma_buffer_p = NULL;
11668c2ecf20Sopenharmony_ci		runtime->dma_area = NULL;
11678c2ecf20Sopenharmony_ci		runtime->dma_addr = 0;
11688c2ecf20Sopenharmony_ci		runtime->dma_bytes = 0;
11698c2ecf20Sopenharmony_ci	}
11708c2ecf20Sopenharmony_ci}
11718c2ecf20Sopenharmony_ci
11728c2ecf20Sopenharmony_ci/**
11738c2ecf20Sopenharmony_ci * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode
11748c2ecf20Sopenharmony_ci * @runtime: PCM runtime instance
11758c2ecf20Sopenharmony_ci * @tv: timespec64 to fill
11768c2ecf20Sopenharmony_ci */
11778c2ecf20Sopenharmony_cistatic inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
11788c2ecf20Sopenharmony_ci				   struct timespec64 *tv)
11798c2ecf20Sopenharmony_ci{
11808c2ecf20Sopenharmony_ci	switch (runtime->tstamp_type) {
11818c2ecf20Sopenharmony_ci	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
11828c2ecf20Sopenharmony_ci		ktime_get_ts64(tv);
11838c2ecf20Sopenharmony_ci		break;
11848c2ecf20Sopenharmony_ci	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
11858c2ecf20Sopenharmony_ci		ktime_get_raw_ts64(tv);
11868c2ecf20Sopenharmony_ci		break;
11878c2ecf20Sopenharmony_ci	default:
11888c2ecf20Sopenharmony_ci		ktime_get_real_ts64(tv);
11898c2ecf20Sopenharmony_ci		break;
11908c2ecf20Sopenharmony_ci	}
11918c2ecf20Sopenharmony_ci}
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci/*
11948c2ecf20Sopenharmony_ci *  Memory
11958c2ecf20Sopenharmony_ci */
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_civoid snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
11988c2ecf20Sopenharmony_civoid snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
11998c2ecf20Sopenharmony_civoid snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
12008c2ecf20Sopenharmony_ci				  int type, struct device *data,
12018c2ecf20Sopenharmony_ci				  size_t size, size_t max);
12028c2ecf20Sopenharmony_civoid snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
12038c2ecf20Sopenharmony_ci					  int type, void *data,
12048c2ecf20Sopenharmony_ci					  size_t size, size_t max);
12058c2ecf20Sopenharmony_ciint snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
12068c2ecf20Sopenharmony_ciint snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_civoid snd_pcm_set_managed_buffer(struct snd_pcm_substream *substream, int type,
12098c2ecf20Sopenharmony_ci				struct device *data, size_t size, size_t max);
12108c2ecf20Sopenharmony_civoid snd_pcm_set_managed_buffer_all(struct snd_pcm *pcm, int type,
12118c2ecf20Sopenharmony_ci				    struct device *data,
12128c2ecf20Sopenharmony_ci				    size_t size, size_t max);
12138c2ecf20Sopenharmony_ci
12148c2ecf20Sopenharmony_ciint _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
12158c2ecf20Sopenharmony_ci				      size_t size, gfp_t gfp_flags);
12168c2ecf20Sopenharmony_ciint snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
12178c2ecf20Sopenharmony_cistruct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
12188c2ecf20Sopenharmony_ci					  unsigned long offset);
12198c2ecf20Sopenharmony_ci/**
12208c2ecf20Sopenharmony_ci * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
12218c2ecf20Sopenharmony_ci * @substream: the substream to allocate the buffer to
12228c2ecf20Sopenharmony_ci * @size: the requested buffer size, in bytes
12238c2ecf20Sopenharmony_ci *
12248c2ecf20Sopenharmony_ci * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
12258c2ecf20Sopenharmony_ci * contiguous in kernel virtual space, but not in physical memory.  Use this
12268c2ecf20Sopenharmony_ci * if the buffer is accessed by kernel code but not by device DMA.
12278c2ecf20Sopenharmony_ci *
12288c2ecf20Sopenharmony_ci * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
12298c2ecf20Sopenharmony_ci * code.
12308c2ecf20Sopenharmony_ci */
12318c2ecf20Sopenharmony_cistatic inline int snd_pcm_lib_alloc_vmalloc_buffer
12328c2ecf20Sopenharmony_ci			(struct snd_pcm_substream *substream, size_t size)
12338c2ecf20Sopenharmony_ci{
12348c2ecf20Sopenharmony_ci	return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
12358c2ecf20Sopenharmony_ci						 GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
12368c2ecf20Sopenharmony_ci}
12378c2ecf20Sopenharmony_ci
12388c2ecf20Sopenharmony_ci/**
12398c2ecf20Sopenharmony_ci * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
12408c2ecf20Sopenharmony_ci * @substream: the substream to allocate the buffer to
12418c2ecf20Sopenharmony_ci * @size: the requested buffer size, in bytes
12428c2ecf20Sopenharmony_ci *
12438c2ecf20Sopenharmony_ci * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
12448c2ecf20Sopenharmony_ci * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
12458c2ecf20Sopenharmony_ci *
12468c2ecf20Sopenharmony_ci * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
12478c2ecf20Sopenharmony_ci * code.
12488c2ecf20Sopenharmony_ci */
12498c2ecf20Sopenharmony_cistatic inline int snd_pcm_lib_alloc_vmalloc_32_buffer
12508c2ecf20Sopenharmony_ci			(struct snd_pcm_substream *substream, size_t size)
12518c2ecf20Sopenharmony_ci{
12528c2ecf20Sopenharmony_ci	return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
12538c2ecf20Sopenharmony_ci						 GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
12548c2ecf20Sopenharmony_ci}
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci#define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DMA_SGBUF
12598c2ecf20Sopenharmony_ci/*
12608c2ecf20Sopenharmony_ci * SG-buffer handling
12618c2ecf20Sopenharmony_ci */
12628c2ecf20Sopenharmony_ci#define snd_pcm_substream_sgbuf(substream) \
12638c2ecf20Sopenharmony_ci	snd_pcm_get_dma_buf(substream)->private_data
12648c2ecf20Sopenharmony_ci#endif /* SND_DMA_SGBUF */
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci/**
12678c2ecf20Sopenharmony_ci * snd_pcm_sgbuf_get_addr - Get the DMA address at the corresponding offset
12688c2ecf20Sopenharmony_ci * @substream: PCM substream
12698c2ecf20Sopenharmony_ci * @ofs: byte offset
12708c2ecf20Sopenharmony_ci */
12718c2ecf20Sopenharmony_cistatic inline dma_addr_t
12728c2ecf20Sopenharmony_cisnd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
12738c2ecf20Sopenharmony_ci{
12748c2ecf20Sopenharmony_ci	return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
12758c2ecf20Sopenharmony_ci}
12768c2ecf20Sopenharmony_ci
12778c2ecf20Sopenharmony_ci/**
12788c2ecf20Sopenharmony_ci * snd_pcm_sgbuf_get_ptr - Get the virtual address at the corresponding offset
12798c2ecf20Sopenharmony_ci * @substream: PCM substream
12808c2ecf20Sopenharmony_ci * @ofs: byte offset
12818c2ecf20Sopenharmony_ci */
12828c2ecf20Sopenharmony_cistatic inline void *
12838c2ecf20Sopenharmony_cisnd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
12848c2ecf20Sopenharmony_ci{
12858c2ecf20Sopenharmony_ci	return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
12868c2ecf20Sopenharmony_ci}
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_ci/**
12898c2ecf20Sopenharmony_ci * snd_pcm_sgbuf_get_chunk_size - Compute the max size that fits within the
12908c2ecf20Sopenharmony_ci * contig. page from the given size
12918c2ecf20Sopenharmony_ci * @substream: PCM substream
12928c2ecf20Sopenharmony_ci * @ofs: byte offset
12938c2ecf20Sopenharmony_ci * @size: byte size to examine
12948c2ecf20Sopenharmony_ci */
12958c2ecf20Sopenharmony_cistatic inline unsigned int
12968c2ecf20Sopenharmony_cisnd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
12978c2ecf20Sopenharmony_ci			     unsigned int ofs, unsigned int size)
12988c2ecf20Sopenharmony_ci{
12998c2ecf20Sopenharmony_ci	return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
13008c2ecf20Sopenharmony_ci}
13018c2ecf20Sopenharmony_ci
13028c2ecf20Sopenharmony_ci/**
13038c2ecf20Sopenharmony_ci * snd_pcm_mmap_data_open - increase the mmap counter
13048c2ecf20Sopenharmony_ci * @area: VMA
13058c2ecf20Sopenharmony_ci *
13068c2ecf20Sopenharmony_ci * PCM mmap callback should handle this counter properly
13078c2ecf20Sopenharmony_ci */
13088c2ecf20Sopenharmony_cistatic inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
13098c2ecf20Sopenharmony_ci{
13108c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
13118c2ecf20Sopenharmony_ci	atomic_inc(&substream->mmap_count);
13128c2ecf20Sopenharmony_ci}
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci/**
13158c2ecf20Sopenharmony_ci * snd_pcm_mmap_data_close - decrease the mmap counter
13168c2ecf20Sopenharmony_ci * @area: VMA
13178c2ecf20Sopenharmony_ci *
13188c2ecf20Sopenharmony_ci * PCM mmap callback should handle this counter properly
13198c2ecf20Sopenharmony_ci */
13208c2ecf20Sopenharmony_cistatic inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
13218c2ecf20Sopenharmony_ci{
13228c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
13238c2ecf20Sopenharmony_ci	atomic_dec(&substream->mmap_count);
13248c2ecf20Sopenharmony_ci}
13258c2ecf20Sopenharmony_ci
13268c2ecf20Sopenharmony_ciint snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
13278c2ecf20Sopenharmony_ci			     struct vm_area_struct *area);
13288c2ecf20Sopenharmony_ci/* mmap for io-memory area */
13298c2ecf20Sopenharmony_ci#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
13308c2ecf20Sopenharmony_ci#define SNDRV_PCM_INFO_MMAP_IOMEM	SNDRV_PCM_INFO_MMAP
13318c2ecf20Sopenharmony_ciint snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
13328c2ecf20Sopenharmony_ci#else
13338c2ecf20Sopenharmony_ci#define SNDRV_PCM_INFO_MMAP_IOMEM	0
13348c2ecf20Sopenharmony_ci#define snd_pcm_lib_mmap_iomem	NULL
13358c2ecf20Sopenharmony_ci#endif
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci/**
13388c2ecf20Sopenharmony_ci * snd_pcm_limit_isa_dma_size - Get the max size fitting with ISA DMA transfer
13398c2ecf20Sopenharmony_ci * @dma: DMA number
13408c2ecf20Sopenharmony_ci * @max: pointer to store the max size
13418c2ecf20Sopenharmony_ci */
13428c2ecf20Sopenharmony_cistatic inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
13438c2ecf20Sopenharmony_ci{
13448c2ecf20Sopenharmony_ci	*max = dma < 4 ? 64 * 1024 : 128 * 1024;
13458c2ecf20Sopenharmony_ci}
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci/*
13488c2ecf20Sopenharmony_ci *  Misc
13498c2ecf20Sopenharmony_ci */
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci#define SNDRV_PCM_DEFAULT_CON_SPDIF	(IEC958_AES0_CON_EMPHASIS_NONE|\
13528c2ecf20Sopenharmony_ci					 (IEC958_AES1_CON_ORIGINAL<<8)|\
13538c2ecf20Sopenharmony_ci					 (IEC958_AES1_CON_PCM_CODER<<8)|\
13548c2ecf20Sopenharmony_ci					 (IEC958_AES3_CON_FS_48000<<24))
13558c2ecf20Sopenharmony_ci
13568c2ecf20Sopenharmony_ciconst char *snd_pcm_format_name(snd_pcm_format_t format);
13578c2ecf20Sopenharmony_ci
13588c2ecf20Sopenharmony_ci/**
13598c2ecf20Sopenharmony_ci * snd_pcm_stream_str - Get a string naming the direction of a stream
13608c2ecf20Sopenharmony_ci * @substream: the pcm substream instance
13618c2ecf20Sopenharmony_ci *
13628c2ecf20Sopenharmony_ci * Return: A string naming the direction of the stream.
13638c2ecf20Sopenharmony_ci */
13648c2ecf20Sopenharmony_cistatic inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
13658c2ecf20Sopenharmony_ci{
13668c2ecf20Sopenharmony_ci	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
13678c2ecf20Sopenharmony_ci		return "Playback";
13688c2ecf20Sopenharmony_ci	else
13698c2ecf20Sopenharmony_ci		return "Capture";
13708c2ecf20Sopenharmony_ci}
13718c2ecf20Sopenharmony_ci
13728c2ecf20Sopenharmony_ci/*
13738c2ecf20Sopenharmony_ci * PCM channel-mapping control API
13748c2ecf20Sopenharmony_ci */
13758c2ecf20Sopenharmony_ci/* array element of channel maps */
13768c2ecf20Sopenharmony_cistruct snd_pcm_chmap_elem {
13778c2ecf20Sopenharmony_ci	unsigned char channels;
13788c2ecf20Sopenharmony_ci	unsigned char map[15];
13798c2ecf20Sopenharmony_ci};
13808c2ecf20Sopenharmony_ci
13818c2ecf20Sopenharmony_ci/* channel map information; retrieved via snd_kcontrol_chip() */
13828c2ecf20Sopenharmony_cistruct snd_pcm_chmap {
13838c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;	/* assigned PCM instance */
13848c2ecf20Sopenharmony_ci	int stream;		/* PLAYBACK or CAPTURE */
13858c2ecf20Sopenharmony_ci	struct snd_kcontrol *kctl;
13868c2ecf20Sopenharmony_ci	const struct snd_pcm_chmap_elem *chmap;
13878c2ecf20Sopenharmony_ci	unsigned int max_channels;
13888c2ecf20Sopenharmony_ci	unsigned int channel_mask;	/* optional: active channels bitmask */
13898c2ecf20Sopenharmony_ci	void *private_data;	/* optional: private data pointer */
13908c2ecf20Sopenharmony_ci};
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_ci/**
13938c2ecf20Sopenharmony_ci * snd_pcm_chmap_substream - get the PCM substream assigned to the given chmap info
13948c2ecf20Sopenharmony_ci * @info: chmap information
13958c2ecf20Sopenharmony_ci * @idx: the substream number index
13968c2ecf20Sopenharmony_ci */
13978c2ecf20Sopenharmony_cistatic inline struct snd_pcm_substream *
13988c2ecf20Sopenharmony_cisnd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
13998c2ecf20Sopenharmony_ci{
14008c2ecf20Sopenharmony_ci	struct snd_pcm_substream *s;
14018c2ecf20Sopenharmony_ci	for (s = info->pcm->streams[info->stream].substream; s; s = s->next)
14028c2ecf20Sopenharmony_ci		if (s->number == idx)
14038c2ecf20Sopenharmony_ci			return s;
14048c2ecf20Sopenharmony_ci	return NULL;
14058c2ecf20Sopenharmony_ci}
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci/* ALSA-standard channel maps (RL/RR prior to C/LFE) */
14088c2ecf20Sopenharmony_ciextern const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[];
14098c2ecf20Sopenharmony_ci/* Other world's standard channel maps (C/LFE prior to RL/RR) */
14108c2ecf20Sopenharmony_ciextern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
14118c2ecf20Sopenharmony_ci
14128c2ecf20Sopenharmony_ci/* bit masks to be passed to snd_pcm_chmap.channel_mask field */
14138c2ecf20Sopenharmony_ci#define SND_PCM_CHMAP_MASK_24	((1U << 2) | (1U << 4))
14148c2ecf20Sopenharmony_ci#define SND_PCM_CHMAP_MASK_246	(SND_PCM_CHMAP_MASK_24 | (1U << 6))
14158c2ecf20Sopenharmony_ci#define SND_PCM_CHMAP_MASK_2468	(SND_PCM_CHMAP_MASK_246 | (1U << 8))
14168c2ecf20Sopenharmony_ci
14178c2ecf20Sopenharmony_ciint snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
14188c2ecf20Sopenharmony_ci			   const struct snd_pcm_chmap_elem *chmap,
14198c2ecf20Sopenharmony_ci			   int max_channels,
14208c2ecf20Sopenharmony_ci			   unsigned long private_value,
14218c2ecf20Sopenharmony_ci			   struct snd_pcm_chmap **info_ret);
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci/**
14248c2ecf20Sopenharmony_ci * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
14258c2ecf20Sopenharmony_ci * @pcm_format: PCM format
14268c2ecf20Sopenharmony_ci */
14278c2ecf20Sopenharmony_cistatic inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
14288c2ecf20Sopenharmony_ci{
14298c2ecf20Sopenharmony_ci	return 1ULL << (__force int) pcm_format;
14308c2ecf20Sopenharmony_ci}
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci/**
14338c2ecf20Sopenharmony_ci * pcm_for_each_format - helper to iterate for each format type
14348c2ecf20Sopenharmony_ci * @f: the iterator variable in snd_pcm_format_t type
14358c2ecf20Sopenharmony_ci */
14368c2ecf20Sopenharmony_ci#define pcm_for_each_format(f)						\
14378c2ecf20Sopenharmony_ci	for ((f) = SNDRV_PCM_FORMAT_FIRST;				\
14388c2ecf20Sopenharmony_ci	     (__force int)(f) <= (__force int)SNDRV_PCM_FORMAT_LAST;	\
14398c2ecf20Sopenharmony_ci	     (f) = (__force snd_pcm_format_t)((__force int)(f) + 1))
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci/* printk helpers */
14428c2ecf20Sopenharmony_ci#define pcm_err(pcm, fmt, args...) \
14438c2ecf20Sopenharmony_ci	dev_err((pcm)->card->dev, fmt, ##args)
14448c2ecf20Sopenharmony_ci#define pcm_warn(pcm, fmt, args...) \
14458c2ecf20Sopenharmony_ci	dev_warn((pcm)->card->dev, fmt, ##args)
14468c2ecf20Sopenharmony_ci#define pcm_dbg(pcm, fmt, args...) \
14478c2ecf20Sopenharmony_ci	dev_dbg((pcm)->card->dev, fmt, ##args)
14488c2ecf20Sopenharmony_ci
14498c2ecf20Sopenharmony_cistruct snd_pcm_status64 {
14508c2ecf20Sopenharmony_ci	snd_pcm_state_t state;		/* stream state */
14518c2ecf20Sopenharmony_ci	u8 rsvd[4];
14528c2ecf20Sopenharmony_ci	s64 trigger_tstamp_sec;		/* time when stream was started/stopped/paused */
14538c2ecf20Sopenharmony_ci	s64 trigger_tstamp_nsec;
14548c2ecf20Sopenharmony_ci	s64 tstamp_sec;			/* reference timestamp */
14558c2ecf20Sopenharmony_ci	s64 tstamp_nsec;
14568c2ecf20Sopenharmony_ci	snd_pcm_uframes_t appl_ptr;	/* appl ptr */
14578c2ecf20Sopenharmony_ci	snd_pcm_uframes_t hw_ptr;	/* hw ptr */
14588c2ecf20Sopenharmony_ci	snd_pcm_sframes_t delay;	/* current delay in frames */
14598c2ecf20Sopenharmony_ci	snd_pcm_uframes_t avail;	/* number of frames available */
14608c2ecf20Sopenharmony_ci	snd_pcm_uframes_t avail_max;	/* max frames available on hw since last status */
14618c2ecf20Sopenharmony_ci	snd_pcm_uframes_t overrange;	/* count of ADC (capture) overrange detections from last status */
14628c2ecf20Sopenharmony_ci	snd_pcm_state_t suspended_state; /* suspended stream state */
14638c2ecf20Sopenharmony_ci	__u32 audio_tstamp_data;	 /* needed for 64-bit alignment, used for configs/report to/from userspace */
14648c2ecf20Sopenharmony_ci	s64 audio_tstamp_sec;		/* sample counter, wall clock, PHC or on-demand sync'ed */
14658c2ecf20Sopenharmony_ci	s64 audio_tstamp_nsec;
14668c2ecf20Sopenharmony_ci	s64 driver_tstamp_sec;		/* useful in case reference system tstamp is reported with delay */
14678c2ecf20Sopenharmony_ci	s64 driver_tstamp_nsec;
14688c2ecf20Sopenharmony_ci	__u32 audio_tstamp_accuracy;	/* in ns units, only valid if indicated in audio_tstamp_data */
14698c2ecf20Sopenharmony_ci	unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */
14708c2ecf20Sopenharmony_ci};
14718c2ecf20Sopenharmony_ci
14728c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL_STATUS64	_IOR('A', 0x20, struct snd_pcm_status64)
14738c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL_STATUS_EXT64	_IOWR('A', 0x24, struct snd_pcm_status64)
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_cistruct snd_pcm_status32 {
14768c2ecf20Sopenharmony_ci	snd_pcm_state_t state;		/* stream state */
14778c2ecf20Sopenharmony_ci	s32 trigger_tstamp_sec;	/* time when stream was started/stopped/paused */
14788c2ecf20Sopenharmony_ci	s32 trigger_tstamp_nsec;
14798c2ecf20Sopenharmony_ci	s32 tstamp_sec;		/* reference timestamp */
14808c2ecf20Sopenharmony_ci	s32 tstamp_nsec;
14818c2ecf20Sopenharmony_ci	u32 appl_ptr;		/* appl ptr */
14828c2ecf20Sopenharmony_ci	u32 hw_ptr;		/* hw ptr */
14838c2ecf20Sopenharmony_ci	s32 delay;		/* current delay in frames */
14848c2ecf20Sopenharmony_ci	u32 avail;		/* number of frames available */
14858c2ecf20Sopenharmony_ci	u32 avail_max;		/* max frames available on hw since last status */
14868c2ecf20Sopenharmony_ci	u32 overrange;		/* count of ADC (capture) overrange detections from last status */
14878c2ecf20Sopenharmony_ci	snd_pcm_state_t suspended_state;	/* suspended stream state */
14888c2ecf20Sopenharmony_ci	u32 audio_tstamp_data;	/* needed for 64-bit alignment, used for configs/report to/from userspace */
14898c2ecf20Sopenharmony_ci	s32 audio_tstamp_sec;	/* sample counter, wall clock, PHC or on-demand sync'ed */
14908c2ecf20Sopenharmony_ci	s32 audio_tstamp_nsec;
14918c2ecf20Sopenharmony_ci	s32 driver_tstamp_sec;	/* useful in case reference system tstamp is reported with delay */
14928c2ecf20Sopenharmony_ci	s32 driver_tstamp_nsec;
14938c2ecf20Sopenharmony_ci	u32 audio_tstamp_accuracy;	/* in ns units, only valid if indicated in audio_tstamp_data */
14948c2ecf20Sopenharmony_ci	unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */
14958c2ecf20Sopenharmony_ci};
14968c2ecf20Sopenharmony_ci
14978c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL_STATUS32	_IOR('A', 0x20, struct snd_pcm_status32)
14988c2ecf20Sopenharmony_ci#define SNDRV_PCM_IOCTL_STATUS_EXT32	_IOWR('A', 0x24, struct snd_pcm_status32)
14998c2ecf20Sopenharmony_ci
15008c2ecf20Sopenharmony_ci#endif /* __SOUND_PCM_H */
1501