@@ -92,9 +92,6 @@ static void finish_session(struct snd_motu *motu)
9292 if (err < 0 )
9393 return ;
9494
95- amdtp_stream_stop (& motu -> tx_stream );
96- amdtp_stream_stop (& motu -> rx_stream );
97-
9895 err = snd_motu_transaction_read (motu , ISOC_COMM_CONTROL_OFFSET , & reg ,
9996 sizeof (reg ));
10097 if (err < 0 )
@@ -109,27 +106,6 @@ static void finish_session(struct snd_motu *motu)
109106 sizeof (reg ));
110107}
111108
112- static int start_isoc_ctx (struct snd_motu * motu , struct amdtp_stream * stream )
113- {
114- struct fw_iso_resources * resources ;
115- int err ;
116-
117- if (stream == & motu -> rx_stream )
118- resources = & motu -> rx_resources ;
119- else
120- resources = & motu -> tx_resources ;
121-
122- err = amdtp_stream_start (stream , resources -> channel ,
123- fw_parent_device (motu -> unit )-> max_speed );
124- if (err < 0 )
125- return err ;
126-
127- if (!amdtp_stream_wait_callback (stream , CALLBACK_TIMEOUT ))
128- return - ETIMEDOUT ;
129-
130- return 0 ;
131- }
132-
133109int snd_motu_stream_cache_packet_formats (struct snd_motu * motu )
134110{
135111 int err ;
@@ -169,6 +145,7 @@ int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate)
169145 rate = curr_rate ;
170146
171147 if (motu -> substreams_counter == 0 || curr_rate != rate ) {
148+ amdtp_domain_stop (& motu -> domain );
172149 finish_session (motu );
173150
174151 fw_iso_resources_free (& motu -> tx_resources );
@@ -234,8 +211,10 @@ int snd_motu_stream_start_duplex(struct snd_motu *motu)
234211 return 0 ;
235212
236213 if (amdtp_streaming_error (& motu -> rx_stream ) ||
237- amdtp_streaming_error (& motu -> tx_stream ))
214+ amdtp_streaming_error (& motu -> tx_stream )) {
215+ amdtp_domain_stop (& motu -> domain );
238216 finish_session (motu );
217+ }
239218
240219 if (generation != fw_parent_device (motu -> unit )-> card -> generation ) {
241220 err = fw_iso_resources_update (& motu -> rx_resources );
@@ -248,6 +227,8 @@ int snd_motu_stream_start_duplex(struct snd_motu *motu)
248227 }
249228
250229 if (!amdtp_stream_running (& motu -> rx_stream )) {
230+ int spd = fw_parent_device (motu -> unit )-> max_speed ;
231+
251232 err = ensure_packet_formats (motu );
252233 if (err < 0 )
253234 return err ;
@@ -259,40 +240,48 @@ int snd_motu_stream_start_duplex(struct snd_motu *motu)
259240 goto stop_streams ;
260241 }
261242
262- err = start_isoc_ctx (motu , & motu -> rx_stream );
263- if (err < 0 ) {
264- dev_err (& motu -> unit -> device ,
265- "fail to start IT context: %d\n" , err );
243+ err = amdtp_domain_add_stream (& motu -> domain , & motu -> tx_stream ,
244+ motu -> tx_resources .channel , spd );
245+ if (err < 0 )
266246 goto stop_streams ;
267- }
268247
269- err = motu -> spec -> protocol -> switch_fetching_mode (motu , true);
270- if (err < 0 ) {
271- dev_err (& motu -> unit -> device ,
272- "fail to enable frame fetching: %d\n" , err );
248+ err = amdtp_domain_add_stream (& motu -> domain , & motu -> rx_stream ,
249+ motu -> rx_resources .channel , spd );
250+ if (err < 0 )
251+ goto stop_streams ;
252+
253+ err = amdtp_domain_start (& motu -> domain );
254+ if (err < 0 )
255+ goto stop_streams ;
256+
257+ if (!amdtp_stream_wait_callback (& motu -> tx_stream ,
258+ CALLBACK_TIMEOUT ) ||
259+ !amdtp_stream_wait_callback (& motu -> rx_stream ,
260+ CALLBACK_TIMEOUT )) {
261+ err = - ETIMEDOUT ;
273262 goto stop_streams ;
274263 }
275- }
276264
277- if (!amdtp_stream_running (& motu -> tx_stream )) {
278- err = start_isoc_ctx (motu , & motu -> tx_stream );
265+ err = motu -> spec -> protocol -> switch_fetching_mode (motu , true);
279266 if (err < 0 ) {
280267 dev_err (& motu -> unit -> device ,
281- "fail to start IR context : %d" , err );
268+ "fail to enable frame fetching : %d\n " , err );
282269 goto stop_streams ;
283270 }
284271 }
285272
286273 return 0 ;
287274
288275stop_streams :
276+ amdtp_domain_stop (& motu -> domain );
289277 finish_session (motu );
290278 return err ;
291279}
292280
293281void snd_motu_stream_stop_duplex (struct snd_motu * motu )
294282{
295283 if (motu -> substreams_counter == 0 ) {
284+ amdtp_domain_stop (& motu -> domain );
296285 finish_session (motu );
297286
298287 fw_iso_resources_free (& motu -> tx_resources );
@@ -344,18 +333,26 @@ int snd_motu_stream_init_duplex(struct snd_motu *motu)
344333 return err ;
345334
346335 err = init_stream (motu , & motu -> rx_stream );
347- if (err < 0 )
336+ if (err < 0 ) {
348337 destroy_stream (motu , & motu -> tx_stream );
338+ return err ;
339+ }
340+
341+ err = amdtp_domain_init (& motu -> domain );
342+ if (err < 0 ) {
343+ destroy_stream (motu , & motu -> tx_stream );
344+ destroy_stream (motu , & motu -> rx_stream );
345+ }
349346
350347 return err ;
351348}
352349
353- /*
354- * This function should be called before starting streams or after stopping
355- * streams.
356- */
350+ // This function should be called before starting streams or after stopping
351+ // streams.
357352void snd_motu_stream_destroy_duplex (struct snd_motu * motu )
358353{
354+ amdtp_domain_destroy (& motu -> domain );
355+
359356 destroy_stream (motu , & motu -> rx_stream );
360357 destroy_stream (motu , & motu -> tx_stream );
361358
0 commit comments