Skip to content

Commit b0936ae

Browse files
maxd-nordicnashif
authored andcommitted
drivers: dp: swdp_bitbang: power optimization
This patch changes GPIO initialization to be in PORT_OFF state by default. Also, if no transceiver is attached to the signals, the GPIOs are configured to be disconnected to preserve power. I tested this on a prototype board where we are going to have a debugger in a low-power context. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent 8746a2a commit b0936ae

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

drivers/dp/swdp_bitbang.c

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -568,107 +568,125 @@ static int sw_configure(const struct device *dev,
568568
static int sw_port_on(const struct device *dev)
569569
{
570570
const struct sw_config *config = dev->config;
571-
572-
gpio_pin_set_dt(&config->clk, 1);
571+
int ret;
573572

574573
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+
}
576578
}
577579

578580
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);
584582
if (ret) {
585583
return ret;
586584
}
587585
}
588586

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;
605590
}
606591

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);
613594
if (ret) {
614595
return ret;
615596
}
616597
}
617598

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;
620602
}
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;
623607
}
624608

625609
return 0;
626610
}
627611

628-
static int sw_gpio_init(const struct device *dev)
612+
static int sw_port_off(const struct device *dev)
629613
{
630614
const struct sw_config *config = dev->config;
631-
struct sw_cfg_data *sw_data = dev->data;
632615
int ret;
633616

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+
}
638623

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+
}
643630

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);
646632
if (ret) {
647633
return ret;
648634
}
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+
}
650642

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);
653644
if (ret) {
654645
return ret;
655646
}
656647
}
657648

649+
/* If there is a transceiver connected to CLK, pins should always be driven. */
658650
if (config->noe.port) {
659651
ret = gpio_pin_configure_dt(&config->noe, GPIO_OUTPUT_INACTIVE);
660652
if (ret) {
661653
return ret;
662654
}
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+
}
663666
}
664667

665668
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);
667670
if (ret) {
668671
return ret;
669672
}
670673
}
671674

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+
672690
sw_data->turnaround = 1U;
673691
sw_data->data_phase = false;
674692
sw_data->fast_clock = false;

0 commit comments

Comments
 (0)