@@ -562,107 +562,125 @@ static int sw_configure(const struct device *dev,
562562static int sw_port_on (const struct device * dev )
563563{
564564 const struct sw_config * config = dev -> config ;
565-
566- gpio_pin_set_dt (& config -> clk , 1 );
565+ int ret ;
567566
568567 if (config -> dnoe .port ) {
569- gpio_pin_set_dt (& config -> dnoe , 1 );
568+ ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_ACTIVE );
569+ if (ret ) {
570+ return ret ;
571+ }
570572 }
571573
572574 if (config -> dout .port ) {
573- gpio_pin_set_dt (& config -> dout , 1 );
574- } else {
575- int ret ;
576-
577- ret = gpio_pin_configure_dt (& config -> dio , GPIO_OUTPUT_ACTIVE );
575+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
578576 if (ret ) {
579577 return ret ;
580578 }
581579 }
582580
583- if (config -> noe .port ) {
584- gpio_pin_set_dt (& config -> noe , 1 );
585- }
586- if (config -> reset .port ) {
587- gpio_pin_set_dt (& config -> reset , 1 );
588- }
589-
590- return 0 ;
591- }
592-
593- static int sw_port_off (const struct device * dev )
594- {
595- const struct sw_config * config = dev -> config ;
596-
597- if (config -> dnoe .port ) {
598- gpio_pin_set_dt (& config -> dnoe , 0 );
581+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
582+ if (ret ) {
583+ return ret ;
599584 }
600585
601- if (config -> dout .port ) {
602- gpio_pin_set_dt (& config -> dout , 0 );
603- } else {
604- int ret ;
605-
606- ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
586+ if (config -> noe .port ) {
587+ ret = gpio_pin_configure_dt (& config -> noe , GPIO_OUTPUT_ACTIVE );
607588 if (ret ) {
608589 return ret ;
609590 }
610591 }
611592
612- if (config -> noe .port ) {
613- gpio_pin_set_dt (& config -> noe , 0 );
593+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
594+ if (ret ) {
595+ return ret ;
614596 }
615- if (config -> reset .port ) {
616- gpio_pin_set_dt (& config -> reset , 1 );
597+
598+ ret = gpio_pin_configure_dt (& config -> reset , GPIO_OUTPUT_ACTIVE );
599+ if (ret ) {
600+ return ret ;
617601 }
618602
619603 return 0 ;
620604}
621605
622- static int sw_gpio_init (const struct device * dev )
606+ static int sw_port_off (const struct device * dev )
623607{
624608 const struct sw_config * config = dev -> config ;
625- struct sw_cfg_data * sw_data = dev -> data ;
626609 int ret ;
627610
628- ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
629- if (ret ) {
630- return ret ;
631- }
611+ /* If there is a transceiver connected to IO, pins should always be driven. */
612+ if (config -> dnoe .port ) {
613+ ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_INACTIVE );
614+ if (ret ) {
615+ return ret ;
616+ }
632617
633- ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
634- if (ret ) {
635- return ret ;
636- }
618+ if (config -> dout .port ) {
619+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
620+ if (ret ) {
621+ return ret ;
622+ }
623+ }
637624
638- if (config -> dout .port ) {
639- ret = gpio_pin_configure_dt (& config -> dout , GPIO_OUTPUT_ACTIVE );
625+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_INPUT );
640626 if (ret ) {
641627 return ret ;
642628 }
643- }
629+ } else {
630+ if (config -> dout .port ) {
631+ ret = gpio_pin_configure_dt (& config -> dout , GPIO_DISCONNECTED );
632+ if (ret ) {
633+ return ret ;
634+ }
635+ }
644636
645- if (config -> dnoe .port ) {
646- ret = gpio_pin_configure_dt (& config -> dnoe , GPIO_OUTPUT_INACTIVE );
637+ ret = gpio_pin_configure_dt (& config -> dio , GPIO_DISCONNECTED );
647638 if (ret ) {
648639 return ret ;
649640 }
650641 }
651642
643+ /* If there is a transceiver connected to CLK, pins should always be driven. */
652644 if (config -> noe .port ) {
653645 ret = gpio_pin_configure_dt (& config -> noe , GPIO_OUTPUT_INACTIVE );
654646 if (ret ) {
655647 return ret ;
656648 }
649+
650+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_OUTPUT_ACTIVE );
651+ if (ret ) {
652+ return ret ;
653+ }
654+
655+ } else {
656+ ret = gpio_pin_configure_dt (& config -> clk , GPIO_DISCONNECTED );
657+ if (ret ) {
658+ return ret ;
659+ }
657660 }
658661
659662 if (config -> reset .port ) {
660- ret = gpio_pin_configure_dt (& config -> reset , GPIO_OUTPUT_ACTIVE );
663+ ret = gpio_pin_configure_dt (& config -> reset , GPIO_DISCONNECTED );
661664 if (ret ) {
662665 return ret ;
663666 }
664667 }
665668
669+ return 0 ;
670+ }
671+
672+ static int sw_gpio_init (const struct device * dev )
673+ {
674+ const struct sw_config * config = dev -> config ;
675+ struct sw_cfg_data * sw_data = dev -> data ;
676+ int ret ;
677+
678+ /* start with the port turned off */
679+ ret = sw_port_off (dev );
680+ if (ret ) {
681+ return ret ;
682+ }
683+
666684 sw_data -> turnaround = 1U ;
667685 sw_data -> data_phase = false;
668686 sw_data -> fast_clock = false;
0 commit comments