Skip to content

Commit 40540de

Browse files
takaswietiwai
authored andcommitted
ALSA: oxfw: move model-specific members from common structure
Currently, 'struct snd_oxfw' has some members for models supported by old firewire-speakers driver, while these members are useless to the other models. This commit allocates new memory block and moves these members to model-specific structure. Signed-off-by: Takashi Sakamoto <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent c582cc6 commit 40540de

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

sound/firewire/oxfw/oxfw-spkr.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
#include "oxfw.h"
99

10+
struct fw_spkr {
11+
bool mute;
12+
s16 volume[6];
13+
s16 volume_min;
14+
s16 volume_max;
15+
};
16+
1017
enum control_action { CTL_READ, CTL_WRITE };
1118
enum control_attribute {
1219
CTL_MIN = 0x02,
@@ -135,8 +142,9 @@ static int spkr_mute_get(struct snd_kcontrol *control,
135142
struct snd_ctl_elem_value *value)
136143
{
137144
struct snd_oxfw *oxfw = control->private_data;
145+
struct fw_spkr *spkr = oxfw->spec;
138146

139-
value->value.integer.value[0] = !oxfw->mute;
147+
value->value.integer.value[0] = !spkr->mute;
140148

141149
return 0;
142150
}
@@ -145,19 +153,20 @@ static int spkr_mute_put(struct snd_kcontrol *control,
145153
struct snd_ctl_elem_value *value)
146154
{
147155
struct snd_oxfw *oxfw = control->private_data;
156+
struct fw_spkr *spkr = oxfw->spec;
148157
bool mute;
149158
int err;
150159

151160
mute = !value->value.integer.value[0];
152161

153-
if (mute == oxfw->mute)
162+
if (mute == spkr->mute)
154163
return 0;
155164

156165
err = avc_audio_feature_mute(oxfw->unit, oxfw->device_info->mute_fb_id,
157166
&mute, CTL_WRITE);
158167
if (err < 0)
159168
return err;
160-
oxfw->mute = mute;
169+
spkr->mute = mute;
161170

162171
return 1;
163172
}
@@ -166,11 +175,12 @@ static int spkr_volume_info(struct snd_kcontrol *control,
166175
struct snd_ctl_elem_info *info)
167176
{
168177
struct snd_oxfw *oxfw = control->private_data;
178+
struct fw_spkr *spkr = oxfw->spec;
169179

170180
info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
171181
info->count = oxfw->device_info->mixer_channels;
172-
info->value.integer.min = oxfw->volume_min;
173-
info->value.integer.max = oxfw->volume_max;
182+
info->value.integer.min = spkr->volume_min;
183+
info->value.integer.max = spkr->volume_max;
174184

175185
return 0;
176186
}
@@ -181,10 +191,11 @@ static int spkr_volume_get(struct snd_kcontrol *control,
181191
struct snd_ctl_elem_value *value)
182192
{
183193
struct snd_oxfw *oxfw = control->private_data;
194+
struct fw_spkr *spkr = oxfw->spec;
184195
unsigned int i;
185196

186197
for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
187-
value->value.integer.value[channel_map[i]] = oxfw->volume[i];
198+
value->value.integer.value[channel_map[i]] = spkr->volume[i];
188199

189200
return 0;
190201
}
@@ -193,14 +204,15 @@ static int spkr_volume_put(struct snd_kcontrol *control,
193204
struct snd_ctl_elem_value *value)
194205
{
195206
struct snd_oxfw *oxfw = control->private_data;
207+
struct fw_spkr *spkr = oxfw->spec;
196208
unsigned int i, changed_channels;
197209
bool equal_values = true;
198210
s16 volume;
199211
int err;
200212

201213
for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
202-
if (value->value.integer.value[i] < oxfw->volume_min ||
203-
value->value.integer.value[i] > oxfw->volume_max)
214+
if (value->value.integer.value[i] < spkr->volume_min ||
215+
value->value.integer.value[i] > spkr->volume_max)
204216
return -EINVAL;
205217
if (value->value.integer.value[i] !=
206218
value->value.integer.value[0])
@@ -210,7 +222,7 @@ static int spkr_volume_put(struct snd_kcontrol *control,
210222
changed_channels = 0;
211223
for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
212224
if (value->value.integer.value[channel_map[i]] !=
213-
oxfw->volume[i])
225+
spkr->volume[i])
214226
changed_channels |= 1 << (i + 1);
215227

216228
if (equal_values && changed_channels != 0)
@@ -227,7 +239,7 @@ static int spkr_volume_put(struct snd_kcontrol *control,
227239
return err;
228240
}
229241
if (i > 0)
230-
oxfw->volume[i - 1] = volume;
242+
spkr->volume[i - 1] = volume;
231243
}
232244

233245
return changed_channels != 0;
@@ -251,30 +263,38 @@ int snd_oxfw_add_spkr(struct snd_oxfw *oxfw)
251263
.put = spkr_volume_put,
252264
},
253265
};
266+
struct fw_spkr *spkr;
254267
unsigned int i, first_ch;
255268
int err;
256269

270+
spkr = kzalloc(sizeof(struct fw_spkr), GFP_KERNEL);
271+
if (spkr == NULL)
272+
return -ENOMEM;
273+
oxfw->spec = spkr;
274+
257275
err = avc_audio_feature_volume(oxfw->unit,
258276
oxfw->device_info->volume_fb_id,
259-
&oxfw->volume_min, 0, CTL_MIN, CTL_READ);
277+
&spkr->volume_min,
278+
0, CTL_MIN, CTL_READ);
260279
if (err < 0)
261280
return err;
262281
err = avc_audio_feature_volume(oxfw->unit,
263282
oxfw->device_info->volume_fb_id,
264-
&oxfw->volume_max, 0, CTL_MAX, CTL_READ);
283+
&spkr->volume_max,
284+
0, CTL_MAX, CTL_READ);
265285
if (err < 0)
266286
return err;
267287

268288
err = avc_audio_feature_mute(oxfw->unit, oxfw->device_info->mute_fb_id,
269-
&oxfw->mute, CTL_READ);
289+
&spkr->mute, CTL_READ);
270290
if (err < 0)
271291
return err;
272292

273293
first_ch = oxfw->device_info->mixer_channels == 1 ? 0 : 1;
274294
for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
275295
err = avc_audio_feature_volume(oxfw->unit,
276296
oxfw->device_info->volume_fb_id,
277-
&oxfw->volume[i],
297+
&spkr->volume[i],
278298
first_ch + i, CTL_CURRENT, CTL_READ);
279299
if (err < 0)
280300
return err;

sound/firewire/oxfw/oxfw.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ struct snd_oxfw {
6464
unsigned int midi_input_ports;
6565
unsigned int midi_output_ports;
6666

67-
bool mute;
68-
s16 volume[6];
69-
s16 volume_min;
70-
s16 volume_max;
71-
7267
int dev_lock_count;
7368
bool dev_lock_changed;
7469
wait_queue_head_t hwdep_wait;

0 commit comments

Comments
 (0)