8da7d941620c5e998e30f7852636f5a0099104c5
[openwrt/staging/chunkeey.git] /
1 From 706f9b2b95a2fff44f92deada99545036c249658 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/806] staging: bcm2835-audio: Simplify PCM creation helpers
5
6 commit 74470ffeb9aed5548654cfca881bf1d7469fe9c4 upstream.
7
8 All three functions to create PCM objects are fairly resemble, and can
9 be unified to a single common helper.
10
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>
14 ---
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(-)
19
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
23 };
24
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)
30 {
31 struct snd_pcm *pcm;
32 int err;
33
34 - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm);
35 - if (err < 0)
36 - return err;
37 - pcm->private_data = chip;
38 - pcm->nonatomic = true;
39 - strcpy(pcm->name, "bcm2835 ALSA");
40 - chip->pcm = pcm;
41 - chip->dest = AUDIO_DEST_AUTO;
42 - chip->volume = 0;
43 - chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
44 - /* set operators */
45 - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
46 - &snd_bcm2835_playback_ops);
47 -
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);
54 -
55 - return 0;
56 -}
57 -
58 -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip)
59 -{
60 - struct snd_pcm *pcm;
61 - int err;
62 -
63 - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
64 - if (err < 0)
65 - return err;
66 -
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);
73 -
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);
79 -
80 - return 0;
81 -}
82 -
83 -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
84 - const char *name,
85 - enum snd_bcm2835_route route,
86 - u32 numchannels)
87 -{
88 - struct snd_pcm *pcm;
89 - int err;
90 -
91 - err = snd_pcm_new(chip->card, name, 0, numchannels,
92 - 0, &pcm);
93 + err = snd_pcm_new(chip->card, name, idx, numchannels, 0, &pcm);
94 if (err)
95 return err;
96
97 pcm->private_data = chip;
98 pcm->nonatomic = true;
99 strcpy(pcm->name, name);
100 - chip->pcm = pcm;
101 - chip->dest = route;
102 - chip->volume = 0;
103 - chip->mute = CTRL_VOL_UNMUTE;
104 + if (!spdif) {
105 + chip->dest = route;
106 + chip->volume = 0;
107 + chip->mute = CTRL_VOL_UNMUTE;
108 + }
109
110 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
111 + spdif ? &snd_bcm2835_playback_spdif_ops :
112 &snd_bcm2835_playback_ops);
113
114 - snd_pcm_lib_preallocate_pages_for_all(
115 - pcm,
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);
122
123 + if (spdif)
124 + chip->pcm_spdif = pcm;
125 + else
126 + chip->pcm = pcm;
127 return 0;
128 }
129 -
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
133 {
134 int err;
135
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);
139 if (err)
140 return err;
141
142 - err = snd_bcm2835_new_spdif_pcm(chip);
143 + err = snd_bcm2835_new_pcm(chip, "bcm2835 IEC958/HDMI", 1, 0, 1, true);
144 if (err)
145 return err;
146
147 return 0;
148 }
149
150 +static int bcm2835_audio_simple_newpcm(struct bcm2835_chip *chip,
151 + const char *name,
152 + enum snd_bcm2835_route route,
153 + u32 numchannels)
154 +{
155 + return snd_bcm2835_new_pcm(chip, name, 0, route, numchannels, false);
156 +}
157 +
158 static struct bcm2835_audio_driver bcm2835_audio_alsa = {
159 .driver = {
160 .name = "bcm2835_alsa",
161 @@ -169,7 +178,7 @@ static struct bcm2835_audio_driver bcm28
162 .shortname = "bcm2835 HDMI",
163 .longname = "bcm2835 HDMI",
164 .minchannels = 1,
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
169 };
170 @@ -182,7 +191,7 @@ static struct bcm2835_audio_driver bcm28
171 .shortname = "bcm2835 Headphones",
172 .longname = "bcm2835 Headphones",
173 .minchannels = 1,
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
178 };
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 {
182 };
183
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,
188 - const char *name,
189 - enum snd_bcm2835_route route,
190 - u32 numchannels);
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);
194
195 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
196 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);