@@ -568,107 +568,125 @@ static int sw_configure(const struct device *dev,
568
568
static int sw_port_on (const struct device * dev )
569
569
{
570
570
const struct sw_config * config = dev -> config ;
571
-
572
- gpio_pin_set_dt (& config -> clk , 1 );
571
+ int ret ;
573
572
574
573
if (config -> dnoe .port ) {
575
- gpio_pin_set_dt (& config -> dnoe , 1 );
574
+ ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_ACTIVE );
575
+ if (ret ) {
576
+ return ret ;
577
+ }
576
578
}
577
579
578
580
if (config -> dout .port ) {
579
- gpio_pin_set_dt (& config -> dout , 1 );
580
- } else {
581
- int ret ;
582
-
583
- ret = gpio_pin_configure_dt (& config -> dio , GPIO_OUTPUT_ACTIVE );
581
+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
584
582
if (ret ) {
585
583
return ret ;
586
584
}
587
585
}
588
586
589
- if (config -> noe .port ) {
590
- gpio_pin_set_dt (& config -> noe , 1 );
591
- }
592
- if (config -> reset .port ) {
593
- gpio_pin_set_dt (& config -> reset , 1 );
594
- }
595
-
596
- return 0 ;
597
- }
598
-
599
- static int sw_port_off (const struct device * dev )
600
- {
601
- const struct sw_config * config = dev -> config ;
602
-
603
- if (config -> dnoe .port ) {
604
- gpio_pin_set_dt (& config -> dnoe , 0 );
587
+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
588
+ if (ret ) {
589
+ return ret ;
605
590
}
606
591
607
- if (config -> dout .port ) {
608
- gpio_pin_set_dt (& config -> dout , 0 );
609
- } else {
610
- int ret ;
611
-
612
- ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
592
+ if (config -> noe .port ) {
593
+ ret = gpio_pin_configure_dt (& config -> noe , GPIO_OUTPUT_ACTIVE );
613
594
if (ret ) {
614
595
return ret ;
615
596
}
616
597
}
617
598
618
- if (config -> noe .port ) {
619
- gpio_pin_set_dt (& config -> noe , 0 );
599
+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
600
+ if (ret ) {
601
+ return ret ;
620
602
}
621
- if (config -> reset .port ) {
622
- gpio_pin_set_dt (& config -> reset , 1 );
603
+
604
+ ret = gpio_pin_configure_dt (& config -> reset , GPIO_OUTPUT_ACTIVE );
605
+ if (ret ) {
606
+ return ret ;
623
607
}
624
608
625
609
return 0 ;
626
610
}
627
611
628
- static int sw_gpio_init (const struct device * dev )
612
+ static int sw_port_off (const struct device * dev )
629
613
{
630
614
const struct sw_config * config = dev -> config ;
631
- struct sw_cfg_data * sw_data = dev -> data ;
632
615
int ret ;
633
616
634
- ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
635
- if (ret ) {
636
- return ret ;
637
- }
617
+ /* If there is a transceiver connected to IO, pins should always be driven. */
618
+ if (config -> dnoe .port ) {
619
+ ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_INACTIVE );
620
+ if (ret ) {
621
+ return ret ;
622
+ }
638
623
639
- ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
640
- if (ret ) {
641
- return ret ;
642
- }
624
+ if (config -> dout .port ) {
625
+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
626
+ if (ret ) {
627
+ return ret ;
628
+ }
629
+ }
643
630
644
- if (config -> dout .port ) {
645
- ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
631
+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
646
632
if (ret ) {
647
633
return ret ;
648
634
}
649
- }
635
+ } else {
636
+ if (config -> dout .port ) {
637
+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_DISCONNECTED );
638
+ if (ret ) {
639
+ return ret ;
640
+ }
641
+ }
650
642
651
- if (config -> dnoe .port ) {
652
- ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_INACTIVE );
643
+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_DISCONNECTED );
653
644
if (ret ) {
654
645
return ret ;
655
646
}
656
647
}
657
648
649
+ /* If there is a transceiver connected to CLK, pins should always be driven. */
658
650
if (config -> noe .port ) {
659
651
ret = gpio_pin_configure_dt (& config -> noe , GPIO_OUTPUT_INACTIVE );
660
652
if (ret ) {
661
653
return ret ;
662
654
}
655
+
656
+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
657
+ if (ret ) {
658
+ return ret ;
659
+ }
660
+
661
+ } else {
662
+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_DISCONNECTED );
663
+ if (ret ) {
664
+ return ret ;
665
+ }
663
666
}
664
667
665
668
if (config -> reset .port ) {
666
- ret = gpio_pin_configure_dt (& config -> reset , GPIO_OUTPUT_ACTIVE );
669
+ ret = gpio_pin_configure_dt (& config -> reset , GPIO_DISCONNECTED );
667
670
if (ret ) {
668
671
return ret ;
669
672
}
670
673
}
671
674
675
+ return 0 ;
676
+ }
677
+
678
+ static int sw_gpio_init (const struct device * dev )
679
+ {
680
+ const struct sw_config * config = dev -> config ;
681
+ struct sw_cfg_data * sw_data = dev -> data ;
682
+ int ret ;
683
+
684
+ /* start with the port turned off */
685
+ ret = sw_port_off (dev );
686
+ if (ret ) {
687
+ return ret ;
688
+ }
689
+
672
690
sw_data -> turnaround = 1U ;
673
691
sw_data -> data_phase = false;
674
692
sw_data -> fast_clock = false;
0 commit comments