1 From e7243e41f004b985c5f4086faa47a92d066706f0 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:56 +0200
4 Subject: [PATCH 460/782] staging: bcm2835-audio: Simplify PCM creation helpers
6 commit 74470ffeb9aed5548654cfca881bf1d7469fe9c4 upstream.
8 All three functions to create PCM objects are fairly resemble, and can
9 be unified to a single common helper.
11 Signed-off-by: Takashi Iwai <tiwai@suse.de>
12 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 87 ++++---------------
16 .../vc04_services/bcm2835-audio/bcm2835.c | 17 +++-
17 .../vc04_services/bcm2835-audio/bcm2835.h | 9 +-
18 3 files changed, 32 insertions(+), 81 deletions(-)
20 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
21 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
22 @@ -324,91 +324,36 @@ static const struct snd_pcm_ops snd_bcm2
25 /* create a pcm device */
26 -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels)
27 +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name,
28 + int idx, enum snd_bcm2835_route route,
29 + u32 numchannels, bool spdif)
34 - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm);
37 - pcm->private_data = chip;
38 - pcm->nonatomic = true;
39 - strcpy(pcm->name, "bcm2835 ALSA");
41 - chip->dest = AUDIO_DEST_AUTO;
43 - chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
45 - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
46 - &snd_bcm2835_playback_ops);
48 - /* pre-allocation of buffers */
49 - /* NOTE: this may fail */
50 - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
51 - chip->card->dev->parent,
52 - snd_bcm2835_playback_hw.buffer_bytes_max,
53 - snd_bcm2835_playback_hw.buffer_bytes_max);
58 -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip)
60 - struct snd_pcm *pcm;
63 - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
67 - pcm->private_data = chip;
68 - pcm->nonatomic = true;
69 - strcpy(pcm->name, "bcm2835 IEC958/HDMI");
70 - chip->pcm_spdif = pcm;
71 - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
72 - &snd_bcm2835_playback_spdif_ops);
74 - /* pre-allocation of buffers */
75 - /* NOTE: this may fail */
76 - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
77 - chip->card->dev->parent,
78 - snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max);
83 -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
85 - enum snd_bcm2835_route route,
88 - struct snd_pcm *pcm;
91 - err = snd_pcm_new(chip->card, name, 0, numchannels,
93 + err = snd_pcm_new(chip->card, name, idx, numchannels, 0, &pcm);
97 pcm->private_data = chip;
98 pcm->nonatomic = true;
99 strcpy(pcm->name, name);
101 - chip->dest = route;
103 - chip->mute = CTRL_VOL_UNMUTE;
105 + chip->dest = route;
107 + chip->mute = CTRL_VOL_UNMUTE;
110 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
111 + spdif ? &snd_bcm2835_playback_spdif_ops :
112 &snd_bcm2835_playback_ops);
114 - snd_pcm_lib_preallocate_pages_for_all(
116 - SNDRV_DMA_TYPE_DEV,
117 - chip->card->dev->parent,
118 - snd_bcm2835_playback_hw.buffer_bytes_max,
119 - snd_bcm2835_playback_hw.buffer_bytes_max);
120 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
121 + chip->card->dev->parent, 128 * 1024, 128 * 1024);
124 + chip->pcm_spdif = pcm;
130 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
131 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
132 @@ -138,17 +138,26 @@ static int bcm2835_audio_alsa_newpcm(str
136 - err = snd_bcm2835_new_pcm(chip, numchannels - 1);
137 + err = snd_bcm2835_new_pcm(chip, "bcm2835 ALSA", 0, AUDIO_DEST_AUTO,
138 + numchannels - 1, false);
142 - err = snd_bcm2835_new_spdif_pcm(chip);
143 + err = snd_bcm2835_new_pcm(chip, "bcm2835 IEC958/HDMI", 1, 0, 1, true);
150 +static int bcm2835_audio_simple_newpcm(struct bcm2835_chip *chip,
152 + enum snd_bcm2835_route route,
155 + return snd_bcm2835_new_pcm(chip, name, 0, route, numchannels, false);
158 static struct bcm2835_audio_driver bcm2835_audio_alsa = {
160 .name = "bcm2835_alsa",
161 @@ -169,7 +178,7 @@ static struct bcm2835_audio_driver bcm28
162 .shortname = "bcm2835 HDMI",
163 .longname = "bcm2835 HDMI",
165 - .newpcm = snd_bcm2835_new_simple_pcm,
166 + .newpcm = bcm2835_audio_simple_newpcm,
167 .newctl = snd_bcm2835_new_hdmi_ctl,
168 .route = AUDIO_DEST_HDMI
170 @@ -182,7 +191,7 @@ static struct bcm2835_audio_driver bcm28
171 .shortname = "bcm2835 Headphones",
172 .longname = "bcm2835 Headphones",
174 - .newpcm = snd_bcm2835_new_simple_pcm,
175 + .newpcm = bcm2835_audio_simple_newpcm,
176 .newctl = snd_bcm2835_new_headphones_ctl,
177 .route = AUDIO_DEST_HEADPHONES
179 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
180 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
181 @@ -84,12 +84,9 @@ struct bcm2835_alsa_stream {
184 int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
185 -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels);
186 -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
187 -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
189 - enum snd_bcm2835_route route,
191 +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name,
192 + int idx, enum snd_bcm2835_route route,
193 + u32 numchannels, bool spdif);
195 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
196 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);