Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Dummy soundcard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <sound/rawmidi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <sound/info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #define MAX_PCM_DEVICES		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define MAX_PCM_SUBSTREAMS	128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define MAX_MIDI_DEVICES	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) /* defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #define MAX_BUFFER_SIZE		(64*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define MIN_PERIOD_SIZE		64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define MAX_PERIOD_SIZE		MAX_BUFFER_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define USE_FORMATS 		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define USE_RATE		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define USE_RATE_MIN		5500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define USE_RATE_MAX		48000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define USE_CHANNELS_MIN 	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define USE_CHANNELS_MAX 	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define USE_PERIODS_MIN 	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define USE_PERIODS_MAX 	1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static char *model[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #ifdef CONFIG_HIGH_RES_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) static bool hrtimer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) static bool fake_buffer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) module_param_array(id, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) module_param_array(model, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) MODULE_PARM_DESC(model, "Soundcard model.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) module_param_array(pcm_devs, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) module_param_array(pcm_substreams, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) //module_param_array(midi_devs, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) module_param(fake_buffer, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #ifdef CONFIG_HIGH_RES_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) module_param(hrtimer, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) static struct platform_device *devices[SNDRV_CARDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define MIXER_ADDR_MASTER	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define MIXER_ADDR_LINE		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define MIXER_ADDR_MIC		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define MIXER_ADDR_SYNTH	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define MIXER_ADDR_CD		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define MIXER_ADDR_LAST		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) struct dummy_timer_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	int (*create)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	void (*free)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	int (*prepare)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	int (*start)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	int (*stop)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define get_dummy_ops(substream) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	(*(const struct dummy_timer_ops **)(substream)->runtime->private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) struct dummy_model {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	int (*playback_constraints)(struct snd_pcm_runtime *runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	int (*capture_constraints)(struct snd_pcm_runtime *runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	u64 formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	size_t buffer_bytes_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	size_t period_bytes_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	size_t period_bytes_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	unsigned int periods_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	unsigned int periods_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	unsigned int rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	unsigned int rate_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	unsigned int rate_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	unsigned int channels_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	unsigned int channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) struct snd_dummy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	const struct dummy_model *model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	struct snd_pcm_hardware pcm_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	spinlock_t mixer_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	int mixer_volume[MIXER_ADDR_LAST+1][2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	int capture_source[MIXER_ADDR_LAST+1][2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	int iobox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	struct snd_kcontrol *cd_volume_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	struct snd_kcontrol *cd_switch_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  * card models
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static const struct dummy_model model_emu10k1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	.name = "emu10k1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	.playback_constraints = emu10k1_playback_constraints,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	.buffer_bytes_max = 128 * 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static const struct dummy_model model_rme9652 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	.name = "rme9652",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	.buffer_bytes_max = 26 * 64 * 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	.formats = SNDRV_PCM_FMTBIT_S32_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	.channels_min = 26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	.channels_max = 26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	.periods_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	.periods_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) static const struct dummy_model model_ice1712 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	.name = "ice1712",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	.buffer_bytes_max = 256 * 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	.formats = SNDRV_PCM_FMTBIT_S32_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	.channels_min = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	.channels_max = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	.periods_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	.periods_max = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static const struct dummy_model model_uda1341 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	.name = "uda1341",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	.buffer_bytes_max = 16380,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	.channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	.channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	.periods_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	.periods_max = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static const struct dummy_model model_ac97 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	.name = "ac97",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	.channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	.channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	.rates = SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	.rate_min = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	.rate_max = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static const struct dummy_model model_ca0106 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	.name = "ca0106",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	.buffer_bytes_max = ((65536-64)*8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.period_bytes_max = (65536-64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	.periods_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	.periods_max = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	.channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	.rates = SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	.rate_min = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	.rate_max = 192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static const struct dummy_model *dummy_models[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	&model_emu10k1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	&model_rme9652,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	&model_ice1712,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	&model_uda1341,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	&model_ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	&model_ca0106,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  * system timer interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) struct dummy_systimer_pcm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	/* ops must be the first item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	const struct dummy_timer_ops *timer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	unsigned long base_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	unsigned int frac_pos;	/* fractional sample position (based HZ) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	unsigned int frac_period_rest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	unsigned int frac_buffer_size;	/* buffer_size * HZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	unsigned int frac_period_size;	/* period_size * HZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	unsigned int rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	int elapsed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	mod_timer(&dpcm->timer, jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		(dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	unsigned long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	delta = jiffies - dpcm->base_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	if (!delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	dpcm->base_time += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	delta *= dpcm->rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	dpcm->frac_pos += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	while (dpcm->frac_pos >= dpcm->frac_buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		dpcm->frac_pos -= dpcm->frac_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	while (dpcm->frac_period_rest <= delta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		dpcm->elapsed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		dpcm->frac_period_rest += dpcm->frac_period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	dpcm->frac_period_rest -= delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) static int dummy_systimer_start(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	spin_lock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	dpcm->base_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	dummy_systimer_rearm(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	spin_unlock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) static int dummy_systimer_stop(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	spin_lock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	del_timer(&dpcm->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	spin_unlock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) static int dummy_systimer_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	struct dummy_systimer_pcm *dpcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	dpcm->frac_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	dpcm->rate = runtime->rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	dpcm->frac_buffer_size = runtime->buffer_size * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	dpcm->frac_period_size = runtime->period_size * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	dpcm->frac_period_rest = dpcm->frac_period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	dpcm->elapsed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) static void dummy_systimer_callback(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	struct dummy_systimer_pcm *dpcm = from_timer(dpcm, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	int elapsed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	spin_lock_irqsave(&dpcm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	dummy_systimer_update(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	dummy_systimer_rearm(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	elapsed = dpcm->elapsed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	dpcm->elapsed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	spin_unlock_irqrestore(&dpcm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	if (elapsed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		snd_pcm_period_elapsed(dpcm->substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) dummy_systimer_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	snd_pcm_uframes_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	spin_lock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	dummy_systimer_update(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	pos = dpcm->frac_pos / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	spin_unlock(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) static int dummy_systimer_create(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	struct dummy_systimer_pcm *dpcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	if (!dpcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	substream->runtime->private_data = dpcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	timer_setup(&dpcm->timer, dummy_systimer_callback, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	spin_lock_init(&dpcm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	dpcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) static void dummy_systimer_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	kfree(substream->runtime->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) static const struct dummy_timer_ops dummy_systimer_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	.create =	dummy_systimer_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	.free =		dummy_systimer_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	.prepare =	dummy_systimer_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	.start =	dummy_systimer_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	.stop =		dummy_systimer_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	.pointer =	dummy_systimer_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) #ifdef CONFIG_HIGH_RES_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)  * hrtimer interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) struct dummy_hrtimer_pcm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	/* ops must be the first item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	const struct dummy_timer_ops *timer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	ktime_t base_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	ktime_t period_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	atomic_t running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	struct hrtimer timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	struct dummy_hrtimer_pcm *dpcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	if (!atomic_read(&dpcm->running))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	 * In cases of XRUN and draining, this calls .trigger to stop PCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	 * substream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	snd_pcm_period_elapsed(dpcm->substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (!atomic_read(&dpcm->running))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	hrtimer_forward_now(timer, dpcm->period_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	return HRTIMER_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) static int dummy_hrtimer_start(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL_SOFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	atomic_set(&dpcm->running, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) static int dummy_hrtimer_stop(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	atomic_set(&dpcm->running, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	if (!hrtimer_callback_running(&dpcm->timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		hrtimer_cancel(&dpcm->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	hrtimer_cancel(&dpcm->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) dummy_hrtimer_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	u64 delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	u32 pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			       dpcm->base_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	delta = div_u64(delta * runtime->rate + 999999, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	div_u64_rem(delta, runtime->buffer_size, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	unsigned int period, rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	long sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	unsigned long nsecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	dummy_hrtimer_sync(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	period = runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	rate = runtime->rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	sec = period / rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	period %= rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	dpcm->period_time = ktime_set(sec, nsecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) static int dummy_hrtimer_create(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	struct dummy_hrtimer_pcm *dpcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	if (!dpcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	substream->runtime->private_data = dpcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	dpcm->timer.function = dummy_hrtimer_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	dpcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	atomic_set(&dpcm->running, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) static void dummy_hrtimer_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	dummy_hrtimer_sync(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	kfree(dpcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static const struct dummy_timer_ops dummy_hrtimer_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	.create =	dummy_hrtimer_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	.free =		dummy_hrtimer_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	.prepare =	dummy_hrtimer_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	.start =	dummy_hrtimer_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	.stop =		dummy_hrtimer_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	.pointer =	dummy_hrtimer_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) #endif /* CONFIG_HIGH_RES_TIMERS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  * PCM interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		return get_dummy_ops(substream)->start(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		return get_dummy_ops(substream)->stop(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	return get_dummy_ops(substream)->prepare(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	return get_dummy_ops(substream)->pointer(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) static const struct snd_pcm_hardware dummy_pcm_hardware = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	.info =			(SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 				 SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 				 SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	.formats =		USE_FORMATS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	.rates =		USE_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	.rate_min =		USE_RATE_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	.rate_max =		USE_RATE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	.channels_min =		USE_CHANNELS_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	.channels_max =		USE_CHANNELS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	.buffer_bytes_max =	MAX_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	.period_bytes_min =	MIN_PERIOD_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	.period_bytes_max =	MAX_PERIOD_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	.periods_min =		USE_PERIODS_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	.periods_max =		USE_PERIODS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) static int dummy_pcm_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			       struct snd_pcm_hw_params *hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	if (fake_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		/* runtime->dma_bytes has to be set manually to allow mmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) static int dummy_pcm_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	const struct dummy_model *model = dummy->model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	const struct dummy_timer_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	ops = &dummy_systimer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) #ifdef CONFIG_HIGH_RES_TIMERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (hrtimer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		ops = &dummy_hrtimer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	err = ops->create(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	get_dummy_ops(substream) = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	runtime->hw = dummy->pcm_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	if (substream->pcm->device & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	if (substream->pcm->device & 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 				      SNDRV_PCM_INFO_MMAP_VALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	if (model == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		if (model->playback_constraints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 			err = model->playback_constraints(substream->runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		if (model->capture_constraints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 			err = model->capture_constraints(substream->runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		get_dummy_ops(substream)->free(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) static int dummy_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	get_dummy_ops(substream)->free(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  * dummy buffer handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) static void *dummy_page[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) static void free_fake_buffer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (fake_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			if (dummy_page[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 				free_page((unsigned long)dummy_page[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 				dummy_page[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) static int alloc_fake_buffer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (!fake_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if (!dummy_page[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			free_fake_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) static int dummy_pcm_copy(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			  int channel, unsigned long pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			  void __user *dst, unsigned long bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	return 0; /* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static int dummy_pcm_copy_kernel(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				 int channel, unsigned long pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				 void *dst, unsigned long bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	return 0; /* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) static int dummy_pcm_silence(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			     int channel, unsigned long pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			     unsigned long bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	return 0; /* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) static struct page *dummy_pcm_page(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 				   unsigned long offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	return virt_to_page(dummy_page[substream->stream]); /* the same page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) static const struct snd_pcm_ops dummy_pcm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	.open =		dummy_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	.close =	dummy_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	.hw_params =	dummy_pcm_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	.prepare =	dummy_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	.trigger =	dummy_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	.pointer =	dummy_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	.open =		dummy_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	.close =	dummy_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	.hw_params =	dummy_pcm_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	.prepare =	dummy_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	.trigger =	dummy_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	.pointer =	dummy_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	.copy_user =	dummy_pcm_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	.copy_kernel =	dummy_pcm_copy_kernel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	.fill_silence =	dummy_pcm_silence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	.page =		dummy_pcm_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) static int snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			      int substreams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	const struct snd_pcm_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	err = snd_pcm_new(dummy->card, "Dummy PCM", device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			       substreams, substreams, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	dummy->pcm = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	if (fake_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		ops = &dummy_pcm_ops_no_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		ops = &dummy_pcm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	pcm->private_data = dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	strcpy(pcm->name, "Dummy PCM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	if (!fake_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		snd_pcm_set_managed_buffer_all(pcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			SNDRV_DMA_TYPE_CONTINUOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			0, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700)  * mixer interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) #define DUMMY_VOLUME(xname, xindex, addr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)   .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)   .name = xname, .index = xindex, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)   .info = snd_dummy_volume_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)   .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)   .private_value = addr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)   .tlv = { .p = db_scale_dummy } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 				 struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	uinfo->value.integer.min = -50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	uinfo->value.integer.max = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	int addr = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	spin_lock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	spin_unlock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	int change, addr = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	int left, right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	left = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (left < -50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		left = -50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	if (left > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		left = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	right = ucontrol->value.integer.value[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (right < -50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		right = -50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	if (right > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		right = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	spin_lock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	change = dummy->mixer_volume[addr][0] != left ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	         dummy->mixer_volume[addr][1] != right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	dummy->mixer_volume[addr][0] = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	dummy->mixer_volume[addr][1] = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	spin_unlock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) #define DUMMY_CAPSRC(xname, xindex, addr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)   .info = snd_dummy_capsrc_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)   .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)   .private_value = addr }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) #define snd_dummy_capsrc_info	snd_ctl_boolean_stereo_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 				struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int addr = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	spin_lock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	ucontrol->value.integer.value[0] = dummy->capture_source[addr][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	ucontrol->value.integer.value[1] = dummy->capture_source[addr][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	spin_unlock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	int change, addr = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	int left, right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	left = ucontrol->value.integer.value[0] & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	right = ucontrol->value.integer.value[1] & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	spin_lock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	change = dummy->capture_source[addr][0] != left &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	         dummy->capture_source[addr][1] != right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	dummy->capture_source[addr][0] = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	dummy->capture_source[addr][1] = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	spin_unlock_irq(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 				struct snd_ctl_elem_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	static const char *const names[] = { "None", "CD Player" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	return snd_ctl_enum_info(info, 1, 2, names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			       struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	value->value.enumerated.item[0] = dummy->iobox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			       struct snd_ctl_elem_value *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	if (value->value.enumerated.item[0] > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	changed = value->value.enumerated.item[0] != dummy->iobox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	if (changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		dummy->iobox = value->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		if (dummy->iobox) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			dummy->cd_volume_ctl->vd[0].access &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			dummy->cd_switch_ctl->vd[0].access &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 				~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			dummy->cd_volume_ctl->vd[0].access |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			dummy->cd_switch_ctl->vd[0].access |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 				SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			       &dummy->cd_volume_ctl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			       &dummy->cd_switch_ctl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) static const struct snd_kcontrol_new snd_dummy_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	.name  = "External I/O Box",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	.info  = snd_dummy_iobox_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	.get   = snd_dummy_iobox_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	.put   = snd_dummy_iobox_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) static int snd_card_dummy_new_mixer(struct snd_dummy *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	struct snd_card *card = dummy->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	struct snd_kcontrol *kcontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	spin_lock_init(&dummy->mixer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	strcpy(card->mixername, "Dummy Mixer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	dummy->iobox = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		err = snd_ctl_add(card, kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		if (!strcmp(kcontrol->id.name, "CD Volume"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			dummy->cd_volume_ctl = kcontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		else if (!strcmp(kcontrol->id.name, "CD Capture Switch"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			dummy->cd_switch_ctl = kcontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_PROC_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  * proc interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) static void print_formats(struct snd_dummy *dummy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			  struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	snd_pcm_format_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	pcm_for_each_format(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		if (dummy->pcm_hw.formats & pcm_format_to_bits(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 			snd_iprintf(buffer, " %s", snd_pcm_format_name(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static void print_rates(struct snd_dummy *dummy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	static const int rates[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		64000, 88200, 96000, 176400, 192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_CONTINUOUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		snd_iprintf(buffer, " continuous");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_KNOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		snd_iprintf(buffer, " knot");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	for (i = 0; i < ARRAY_SIZE(rates); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		if (dummy->pcm_hw.rates & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 			snd_iprintf(buffer, " %d", rates[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) #define get_dummy_int_ptr(dummy, ofs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	(unsigned int *)((char *)&((dummy)->pcm_hw) + (ofs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) #define get_dummy_ll_ptr(dummy, ofs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	(unsigned long long *)((char *)&((dummy)->pcm_hw) + (ofs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) struct dummy_hw_field {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	const char *format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) #define FIELD_ENTRY(item, fmt) {		   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	.name = #item,				   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	.format = fmt,				   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	.offset = offsetof(struct snd_pcm_hardware, item), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	.size = sizeof(dummy_pcm_hardware.item) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) static const struct dummy_hw_field fields[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	FIELD_ENTRY(formats, "%#llx"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	FIELD_ENTRY(rates, "%#x"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	FIELD_ENTRY(rate_min, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	FIELD_ENTRY(rate_max, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	FIELD_ENTRY(channels_min, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	FIELD_ENTRY(channels_max, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	FIELD_ENTRY(buffer_bytes_max, "%ld"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	FIELD_ENTRY(period_bytes_min, "%ld"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	FIELD_ENTRY(period_bytes_max, "%ld"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	FIELD_ENTRY(periods_min, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	FIELD_ENTRY(periods_max, "%d"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) static void dummy_proc_read(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			    struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	struct snd_dummy *dummy = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	for (i = 0; i < ARRAY_SIZE(fields); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		snd_iprintf(buffer, "%s ", fields[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		if (fields[i].size == sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			snd_iprintf(buffer, fields[i].format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 				*get_dummy_int_ptr(dummy, fields[i].offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			snd_iprintf(buffer, fields[i].format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 				*get_dummy_ll_ptr(dummy, fields[i].offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		if (!strcmp(fields[i].name, "formats"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			print_formats(dummy, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		else if (!strcmp(fields[i].name, "rates"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			print_rates(dummy, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		snd_iprintf(buffer, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) static void dummy_proc_write(struct snd_info_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			     struct snd_info_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	struct snd_dummy *dummy = entry->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	char line[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		char item[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		const char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		unsigned long long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		ptr = snd_info_get_str(item, line, sizeof(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		for (i = 0; i < ARRAY_SIZE(fields); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			if (!strcmp(item, fields[i].name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		if (i >= ARRAY_SIZE(fields))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		snd_info_get_str(item, ptr, sizeof(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		if (kstrtoull(item, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		if (fields[i].size == sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			*get_dummy_int_ptr(dummy, fields[i].offset) = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			*get_dummy_ll_ptr(dummy, fields[i].offset) = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static void dummy_proc_init(struct snd_dummy *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	snd_card_rw_proc_new(chip->card, "dummy_pcm", chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 			     dummy_proc_read, dummy_proc_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) #define dummy_proc_init(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) #endif /* CONFIG_SND_DEBUG && CONFIG_SND_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static int snd_dummy_probe(struct platform_device *devptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	struct snd_dummy *dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	const struct dummy_model *m = NULL, **mdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	int idx, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	int dev = devptr->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			   sizeof(struct snd_dummy), &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	dummy = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	dummy->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	for (mdl = dummy_models; *mdl && model[dev]; mdl++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		if (strcmp(model[dev], (*mdl)->name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				"snd-dummy: Using model '%s' for card %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				(*mdl)->name, card->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			m = dummy->model = *mdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		if (pcm_substreams[dev] < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			pcm_substreams[dev] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			pcm_substreams[dev] = MAX_PCM_SUBSTREAMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			goto __nodev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	dummy->pcm_hw = dummy_pcm_hardware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (m) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		if (m->formats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			dummy->pcm_hw.formats = m->formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		if (m->buffer_bytes_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 			dummy->pcm_hw.buffer_bytes_max = m->buffer_bytes_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		if (m->period_bytes_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			dummy->pcm_hw.period_bytes_min = m->period_bytes_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		if (m->period_bytes_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 			dummy->pcm_hw.period_bytes_max = m->period_bytes_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		if (m->periods_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			dummy->pcm_hw.periods_min = m->periods_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		if (m->periods_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 			dummy->pcm_hw.periods_max = m->periods_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		if (m->rates)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			dummy->pcm_hw.rates = m->rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		if (m->rate_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 			dummy->pcm_hw.rate_min = m->rate_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		if (m->rate_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			dummy->pcm_hw.rate_max = m->rate_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		if (m->channels_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			dummy->pcm_hw.channels_min = m->channels_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		if (m->channels_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			dummy->pcm_hw.channels_max = m->channels_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	err = snd_card_dummy_new_mixer(dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		goto __nodev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	strcpy(card->driver, "Dummy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	strcpy(card->shortname, "Dummy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	sprintf(card->longname, "Dummy %i", dev + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	dummy_proc_init(dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		platform_set_drvdata(devptr, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)       __nodev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) static int snd_dummy_remove(struct platform_device *devptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	snd_card_free(platform_get_drvdata(devptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static int snd_dummy_suspend(struct device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct snd_card *card = dev_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) static int snd_dummy_resume(struct device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	struct snd_card *card = dev_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static SIMPLE_DEV_PM_OPS(snd_dummy_pm, snd_dummy_suspend, snd_dummy_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) #define SND_DUMMY_PM_OPS	&snd_dummy_pm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) #define SND_DUMMY_PM_OPS	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) #define SND_DUMMY_DRIVER	"snd_dummy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static struct platform_driver snd_dummy_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	.probe		= snd_dummy_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	.remove		= snd_dummy_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		.name	= SND_DUMMY_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		.pm	= SND_DUMMY_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) static void snd_dummy_unregister_all(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	for (i = 0; i < ARRAY_SIZE(devices); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		platform_device_unregister(devices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	platform_driver_unregister(&snd_dummy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	free_fake_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) static int __init alsa_card_dummy_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	int i, cards, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	err = platform_driver_register(&snd_dummy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	err = alloc_fake_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		platform_driver_unregister(&snd_dummy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	cards = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	for (i = 0; i < SNDRV_CARDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		struct platform_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		if (! enable[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		device = platform_device_register_simple(SND_DUMMY_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 							 i, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		if (IS_ERR(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		if (!platform_get_drvdata(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			platform_device_unregister(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		devices[i] = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		cards++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (!cards) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) #ifdef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		printk(KERN_ERR "Dummy soundcard not found or device busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		snd_dummy_unregister_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) static void __exit alsa_card_dummy_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	snd_dummy_unregister_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) module_init(alsa_card_dummy_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) module_exit(alsa_card_dummy_exit)