@@ -438,63 +438,41 @@ static int i2s_mcux_config(const struct device *dev, enum i2s_dir dir,
438
438
const struct i2s_mcux_config * dev_cfg = dev -> config ;
439
439
I2S_Type * base = (I2S_Type * )dev_cfg -> base ;
440
440
struct i2s_dev_data * dev_data = dev -> data ;
441
+ enum i2s_state * tx_state = & (dev_data -> tx .state );
442
+ enum i2s_state * rx_state = & (dev_data -> rx .state );
443
+ uint8_t word_size_bits = i2s_cfg -> word_size ;
444
+ uint8_t num_words = i2s_cfg -> channels ;
441
445
sai_transceiver_t config ;
446
+ int ret = - EINVAL ;
442
447
uint32_t mclk ;
443
- /*num_words is frame size*/
444
- uint8_t num_words = i2s_cfg -> channels ;
445
- uint8_t word_size_bits = i2s_cfg -> word_size ;
446
448
447
449
if ((dev_data -> tx .state != I2S_STATE_NOT_READY ) &&
448
450
(dev_data -> tx .state != I2S_STATE_READY ) &&
449
451
(dev_data -> rx .state != I2S_STATE_NOT_READY ) &&
450
452
(dev_data -> rx .state != I2S_STATE_READY )) {
451
453
LOG_ERR ("invalid state tx(%u) rx(%u)" , dev_data -> tx .state , dev_data -> rx .state );
452
- if (dir == I2S_DIR_TX ) {
453
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
454
- } else {
455
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
456
- }
457
- return - EINVAL ;
454
+ goto invalid_config ;
458
455
}
459
456
460
457
if (i2s_cfg -> frame_clk_freq == 0U ) {
461
458
LOG_ERR ("Invalid frame_clk_freq %u" , i2s_cfg -> frame_clk_freq );
462
- if (dir == I2S_DIR_TX ) {
463
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
464
- } else {
465
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
466
- }
467
- return 0 ;
459
+ goto invalid_config ;
468
460
}
469
461
470
462
if (word_size_bits < SAI_WORD_SIZE_BITS_MIN || word_size_bits > SAI_WORD_SIZE_BITS_MAX ) {
471
463
LOG_ERR ("Unsupported I2S word size %u" , word_size_bits );
472
- if (dir == I2S_DIR_TX ) {
473
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
474
- } else {
475
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
476
- }
477
- return - EINVAL ;
464
+ goto invalid_config ;
478
465
}
479
466
480
467
if (num_words < SAI_WORD_PER_FRAME_MIN || num_words > SAI_WORD_PER_FRAME_MAX ) {
481
468
LOG_ERR ("Unsupported words length %u" , num_words );
482
- if (dir == I2S_DIR_TX ) {
483
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
484
- } else {
485
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
486
- }
487
- return - EINVAL ;
469
+ goto invalid_config ;
488
470
}
489
471
490
472
if ((i2s_cfg -> options & I2S_OPT_PINGPONG ) == I2S_OPT_PINGPONG ) {
491
473
LOG_ERR ("Ping-pong mode not supported" );
492
- if (dir == I2S_DIR_TX ) {
493
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
494
- } else {
495
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
496
- }
497
- return - ENOTSUP ;
474
+ ret = - ENOTSUP ;
475
+ goto invalid_config ;
498
476
}
499
477
500
478
memset (& config , 0 , sizeof (config ));
@@ -552,12 +530,8 @@ static int i2s_mcux_config(const struct device *dev, enum i2s_dir dir,
552
530
break ;
553
531
default :
554
532
LOG_ERR ("Unsupported I2S data format" );
555
- if (dir == I2S_DIR_TX ) {
556
- dev_data -> tx .state = I2S_STATE_NOT_READY ;
557
- } else {
558
- dev_data -> rx .state = I2S_STATE_NOT_READY ;
559
- }
560
- return - EINVAL ;
533
+ ret = - EINVAL ;
534
+ goto invalid_config ;
561
535
}
562
536
563
537
/* sync mode configurations */
@@ -669,6 +643,14 @@ static int i2s_mcux_config(const struct device *dev, enum i2s_dir dir,
669
643
}
670
644
671
645
return 0 ;
646
+
647
+ invalid_config :
648
+ if (dir == I2S_DIR_TX ) {
649
+ * tx_state = I2S_STATE_NOT_READY ;
650
+ } else if (dir == I2S_DIR_RX ) {
651
+ * rx_state = I2S_STATE_NOT_READY ;
652
+ }
653
+ return ret ;
672
654
}
673
655
674
656
const struct i2s_config * i2s_mcux_config_get (const struct device * dev , enum i2s_dir dir )
0 commit comments