sunxi: Properly check for SATAPWR and MACPWR
PATCH 1/1 sunxi: Properly check for SATAPWR and MACPWR
The #ifdef CONFIG_xxxPWR conditionals were not working as expected, as string Kconfig symbols are always "defined" from the preprocessor's perspective. This lead to unnecessary calls to the GPIO routines, but also always added a half a second delay to wait for a SATA disk to power up. Many thanks to Peter for pointing this out!
Fix this by properly comparing the Kconfig symbols against the empty string. strcmp() would be nicer for this, but GCC does not optimise this away, probably due to our standalone compiler switches.
--- board/sunxi/board.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
board/sunxi/board.c +22 -12
@@ -265,18 +265,28 @@ int board_init(void)if (ret)return ret; -#ifdef CONFIG_SATAPWR - satapwr_pin =sunxi_name_to_gpio (CONFIG_SATAPWR ); -gpio_request (satapwr_pin,"satapwr" ); -gpio_direction_output (satapwr_pin,1 ); -/* Give attached sata device time to power-up to avoid link timeouts */ -mdelay (500 ); -#endif -#ifdef CONFIG_MACPWR - macpwr_pin =sunxi_name_to_gpio (CONFIG_MACPWR ); -gpio_request (macpwr_pin,"macpwr" ); -gpio_direction_output (macpwr_pin,1 ); -#endif +/* strcmp() would look better, but doesn't get optimised away. */ +if (CONFIG_SATAPWR [0 ]) { + satapwr_pin =sunxi_name_to_gpio (CONFIG_SATAPWR ); +if (satapwr_pin >=0 ) { +gpio_request (satapwr_pin,"satapwr" ); +gpio_direction_output (satapwr_pin,1 ); + +/* +* Give the attached SATA device time to power-up +* to avoid link timeouts +*/ +mdelay (500 ); + } + } + +if (CONFIG_MACPWR [0 ]) { + macpwr_pin =sunxi_name_to_gpio (CONFIG_MACPWR ); +if (macpwr_pin >=0 ) { +gpio_request (macpwr_pin,"macpwr" ); +gpio_direction_output (macpwr_pin,1 ); + } + }#ifdef CONFIG_DM_I2C /*
Signature · 1 line
2.17.5
Samuel Holland
maintainerPATCH 1/1 sunxi: Properly check for SATAPWR and MACPWR
Quoted 9 lines · Andre Przywara
The #ifdef
CONFIG_xxxPWRconditionals were not working as expected, as stringKconfigsymbols are always "defined" from the preprocessor's perspective. This lead to unnecessary calls to the GPIO routines, but also always added a half a second delay to wait for a SATA disk to power up. Many thanks to Peter for pointing this out!Fix this by properly comparing the
Kconfigsymbols against the empty string.strcmp()would be nicer for this, but GCC does not optimise this away, probably due to our standalone compiler switches.
Ethernet still works, and the speed-up is welcome.
Cheers,
Samuel
PATCH 1/1 sunxi: Properly check for SATAPWR and MACPWR
In reply to Andre PrzywaraQuoted 7 lines · Andre Przywara
The #ifdef
CONFIG_xxxPWRconditionals were not working as expected, as stringKconfigsymbols are always "defined" from the preprocessor's perspective. This lead to unnecessary calls to the GPIO routines, but also always added a half a second delay to wait for a SATA disk to power up. Many thanks to Peter for pointing this out!
Quoted 6 lines
Fix this by properly comparing the
Kconfigsymbols against the empty string.strcmp()would be nicer for this, but GCC does not optimise this away, probably due to our standalone compiler switches.Reported-by Peter Robinson <[email protected]>Signed-off-by Andre Przywara <[email protected]>
Tested on Pine64, Cubietruck with root fs on SATA SSD, and an orangepi_pc
Quoted 52 lines
--- board/sunxi/board.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)board/sunxi/board.c +22
-13@@ -265,18 +265,28 @@ int board_init(void)if (ret)return ret; -#ifdef CONFIG_SATAPWR - satapwr_pin =sunxi_name_to_gpio (CONFIG_SATAPWR ); -gpio_request (satapwr_pin,"satapwr" ); -gpio_direction_output (satapwr_pin,1 ); -/* Give attached sata device time to power-up to avoid link timeouts */ -mdelay (500 ); -#endif -#ifdef CONFIG_MACPWR - macpwr_pin =sunxi_name_to_gpio (CONFIG_MACPWR ); -gpio_request (macpwr_pin,"macpwr" ); -gpio_direction_output (macpwr_pin,1 ); -#endif +/* strcmp() would look better, but doesn't get optimised away. */ +if (CONFIG_SATAPWR [0 ]) { + satapwr_pin =sunxi_name_to_gpio (CONFIG_SATAPWR ); +if (satapwr_pin >=0 ) { +gpio_request (satapwr_pin,"satapwr" ); +gpio_direction_output (satapwr_pin,1 ); + +/* +* Give the attached SATA device time to power-up +* to avoid link timeouts +*/ +mdelay (500 ); + } + } + +if (CONFIG_MACPWR [0 ]) { + macpwr_pin =sunxi_name_to_gpio (CONFIG_MACPWR ); +if (macpwr_pin >=0 ) { +gpio_request (macpwr_pin,"macpwr" ); +gpio_direction_output (macpwr_pin,1 ); + } + }#ifdef CONFIG_DM_I2C /* -- 2.17.5
PATCH 1/1 sunxi: Properly check for SATAPWR and MACPWR
In reply to Andre PrzywaraDne torek, 19. januar 2021 ob 02:05:20 CET je Andre Przywara napisal(a):
Quoted 6 lines
The #ifdef
CONFIG_xxxPWRconditionals were not working as expected, as stringKconfigsymbols are always "defined" from the preprocessor's perspective. This lead to unnecessary calls to the GPIO routines, but also always added a half a second delay to wait for a SATA disk to power up. Many thanks to Peter for pointing this out!
Quoted 6 lines
Fix this by properly comparing the
Kconfigsymbols against the empty string.strcmp()would be nicer for this, but GCC does not optimise this away, probably due to our standalone compiler switches.Reported-by Peter Robinson <[email protected]>Signed-off-by Andre Przywara <[email protected]>
Nice find!
Best regards,
Jernej