7
7
8
8
#include "oxfw.h"
9
9
10
+ struct fw_spkr {
11
+ bool mute ;
12
+ s16 volume [6 ];
13
+ s16 volume_min ;
14
+ s16 volume_max ;
15
+ };
16
+
10
17
enum control_action { CTL_READ , CTL_WRITE };
11
18
enum control_attribute {
12
19
CTL_MIN = 0x02 ,
@@ -135,8 +142,9 @@ static int spkr_mute_get(struct snd_kcontrol *control,
135
142
struct snd_ctl_elem_value * value )
136
143
{
137
144
struct snd_oxfw * oxfw = control -> private_data ;
145
+ struct fw_spkr * spkr = oxfw -> spec ;
138
146
139
- value -> value .integer .value [0 ] = !oxfw -> mute ;
147
+ value -> value .integer .value [0 ] = !spkr -> mute ;
140
148
141
149
return 0 ;
142
150
}
@@ -145,19 +153,20 @@ static int spkr_mute_put(struct snd_kcontrol *control,
145
153
struct snd_ctl_elem_value * value )
146
154
{
147
155
struct snd_oxfw * oxfw = control -> private_data ;
156
+ struct fw_spkr * spkr = oxfw -> spec ;
148
157
bool mute ;
149
158
int err ;
150
159
151
160
mute = !value -> value .integer .value [0 ];
152
161
153
- if (mute == oxfw -> mute )
162
+ if (mute == spkr -> mute )
154
163
return 0 ;
155
164
156
165
err = avc_audio_feature_mute (oxfw -> unit , oxfw -> device_info -> mute_fb_id ,
157
166
& mute , CTL_WRITE );
158
167
if (err < 0 )
159
168
return err ;
160
- oxfw -> mute = mute ;
169
+ spkr -> mute = mute ;
161
170
162
171
return 1 ;
163
172
}
@@ -166,11 +175,12 @@ static int spkr_volume_info(struct snd_kcontrol *control,
166
175
struct snd_ctl_elem_info * info )
167
176
{
168
177
struct snd_oxfw * oxfw = control -> private_data ;
178
+ struct fw_spkr * spkr = oxfw -> spec ;
169
179
170
180
info -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
171
181
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 ;
174
184
175
185
return 0 ;
176
186
}
@@ -181,10 +191,11 @@ static int spkr_volume_get(struct snd_kcontrol *control,
181
191
struct snd_ctl_elem_value * value )
182
192
{
183
193
struct snd_oxfw * oxfw = control -> private_data ;
194
+ struct fw_spkr * spkr = oxfw -> spec ;
184
195
unsigned int i ;
185
196
186
197
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 ];
188
199
189
200
return 0 ;
190
201
}
@@ -193,14 +204,15 @@ static int spkr_volume_put(struct snd_kcontrol *control,
193
204
struct snd_ctl_elem_value * value )
194
205
{
195
206
struct snd_oxfw * oxfw = control -> private_data ;
207
+ struct fw_spkr * spkr = oxfw -> spec ;
196
208
unsigned int i , changed_channels ;
197
209
bool equal_values = true;
198
210
s16 volume ;
199
211
int err ;
200
212
201
213
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 )
204
216
return - EINVAL ;
205
217
if (value -> value .integer .value [i ] !=
206
218
value -> value .integer .value [0 ])
@@ -210,7 +222,7 @@ static int spkr_volume_put(struct snd_kcontrol *control,
210
222
changed_channels = 0 ;
211
223
for (i = 0 ; i < oxfw -> device_info -> mixer_channels ; ++ i )
212
224
if (value -> value .integer .value [channel_map [i ]] !=
213
- oxfw -> volume [i ])
225
+ spkr -> volume [i ])
214
226
changed_channels |= 1 << (i + 1 );
215
227
216
228
if (equal_values && changed_channels != 0 )
@@ -227,7 +239,7 @@ static int spkr_volume_put(struct snd_kcontrol *control,
227
239
return err ;
228
240
}
229
241
if (i > 0 )
230
- oxfw -> volume [i - 1 ] = volume ;
242
+ spkr -> volume [i - 1 ] = volume ;
231
243
}
232
244
233
245
return changed_channels != 0 ;
@@ -251,30 +263,38 @@ int snd_oxfw_add_spkr(struct snd_oxfw *oxfw)
251
263
.put = spkr_volume_put ,
252
264
},
253
265
};
266
+ struct fw_spkr * spkr ;
254
267
unsigned int i , first_ch ;
255
268
int err ;
256
269
270
+ spkr = kzalloc (sizeof (struct fw_spkr ), GFP_KERNEL );
271
+ if (spkr == NULL )
272
+ return - ENOMEM ;
273
+ oxfw -> spec = spkr ;
274
+
257
275
err = avc_audio_feature_volume (oxfw -> unit ,
258
276
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 );
260
279
if (err < 0 )
261
280
return err ;
262
281
err = avc_audio_feature_volume (oxfw -> unit ,
263
282
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 );
265
285
if (err < 0 )
266
286
return err ;
267
287
268
288
err = avc_audio_feature_mute (oxfw -> unit , oxfw -> device_info -> mute_fb_id ,
269
- & oxfw -> mute , CTL_READ );
289
+ & spkr -> mute , CTL_READ );
270
290
if (err < 0 )
271
291
return err ;
272
292
273
293
first_ch = oxfw -> device_info -> mixer_channels == 1 ? 0 : 1 ;
274
294
for (i = 0 ; i < oxfw -> device_info -> mixer_channels ; ++ i ) {
275
295
err = avc_audio_feature_volume (oxfw -> unit ,
276
296
oxfw -> device_info -> volume_fb_id ,
277
- & oxfw -> volume [i ],
297
+ & spkr -> volume [i ],
278
298
first_ch + i , CTL_CURRENT , CTL_READ );
279
299
if (err < 0 )
280
300
return err ;
0 commit comments