]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
liebherr: btt: shrink spl_board_init
authorRasmus Villemoes <ravi@prevas.dk>
Thu, 23 Oct 2025 08:47:59 +0000 (10:47 +0200)
committerFabio Estevam <festevam@gmail.com>
Thu, 30 Oct 2025 15:39:12 +0000 (12:39 -0300)
This board is very tight on space in SPL; in fact with my compiler it
ends up just exactly on the wrong side:

spl/u-boot-spl.bin exceeds file size limit:
  limit:  0xa000 bytes
  actual: 0xa014 bytes
  excess: 0x14 bytes

The repeated "lookup and request" pattern in spl_board_init() suggests
a low-hanging fruit for reducing the code size. This reduces the
object size of spl/board/liebherr/btt/btt.o by 300 bytes.

I've left the lack of error handling as-is; there isn't really
anything to do if it fails, so I suppose the printfs are the best that
can be done.

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
board/liebherr/btt/btt.c

index e05e333ac7eea339973078b79f0cd8c99bbac42d..c4b6c37e4959be56f8c678c940f33a42c66f71f0 100644 (file)
@@ -110,10 +110,23 @@ static int spi_load_boot_info(void)
 #define BTT_MONITORING_DEVICE_TIMEOUT 100
 static int rescue_val;
 
+static void lookup_and_request(struct gpio_desc *desc, const char *name, const char *label)
+{
+       int ret;
+
+       ret = dm_gpio_lookup_name(name, desc);
+       if (ret)
+               printf("Cannot get %s\n", name);
+
+       ret = dm_gpio_request(desc, label);
+       if (ret)
+               printf("Cannot request %s\n", name);
+}
+
 void spl_board_init(void)
 {
        struct gpio_desc phy_rst, boot, rescue, wifi_en, bt_en;
-       int ret, i;
+       int i;
 
        /*
         * On the new HW version of BTTC/3 (with LAN8720ai PHY) the !RST pin
@@ -125,14 +138,7 @@ void spl_board_init(void)
         * to set the RESET pin to HIGH after 100us, so there was no need to
         * set it explicitly.
         */
-       ret = dm_gpio_lookup_name("GPIO4_12", &phy_rst);
-       if (ret)
-               printf("Cannot get GPIO4_12\n");
-
-       ret = dm_gpio_request(&phy_rst, "phy-rst");
-       if (ret)
-               printf("Cannot request GPIO4_12\n");
-
+       lookup_and_request(&phy_rst, "GPIO4_12", "phy-rst");
        dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
 
        /*
@@ -140,14 +146,7 @@ void spl_board_init(void)
         * it is directly connected to Jody module without any externa pull up
         * down register.
         */
-       ret = dm_gpio_lookup_name("GPIO0_27", &wifi_en);
-       if (ret)
-               printf("Cannot get GPIO0_27\n");
-
-       ret = dm_gpio_request(&wifi_en, "wifi-en");
-       if (ret)
-               printf("Cannot request GPIO0_27\n");
-
+       lookup_and_request(&wifi_en, "GPIO0_27", "wifi-en");
        dm_gpio_set_dir_flags(&wifi_en, GPIOD_IS_OUT | GPIOD_ACTIVE_LOW |
                              GPIOD_IS_OUT_ACTIVE);
 
@@ -157,36 +156,15 @@ void spl_board_init(void)
         * time this pin is set to HIGH). However, the manual recommends setting
         * it high from LOW state.
         */
-       ret = dm_gpio_lookup_name("GPIO3_27", &bt_en);
-       if (ret)
-               printf("Cannot get GPIO3_27\n");
-
-       ret = dm_gpio_request(&bt_en, "bt-en");
-       if (ret)
-               printf("Cannot request GPIO3_27\n");
-
+       lookup_and_request(&bt_en, "GPIO3_27", "bt-en");
        dm_gpio_set_dir_flags(&bt_en, GPIOD_IS_OUT | GPIOD_ACTIVE_LOW |
                              GPIOD_IS_OUT_ACTIVE);
 
        /* 'boot' and 'rescue' pins */
-       ret = dm_gpio_lookup_name("GPIO4_9", &boot);
-       if (ret)
-               printf("Cannot get GPIO4_9\n");
-
-       ret = dm_gpio_request(&boot, "boot");
-       if (ret)
-               printf("Cannot request GPIO4_9\n");
-
+       lookup_and_request(&boot, "GPIO4_9", "boot");
        dm_gpio_set_dir_flags(&boot, GPIOD_IS_IN);
 
-       ret = dm_gpio_lookup_name("GPIO4_11", &rescue);
-       if (ret)
-               printf("Cannot get GPIO4_11\n");
-
-       ret = dm_gpio_request(&rescue, "rescue");
-       if (ret)
-               printf("Cannot request GPIO4_11\n");
-
+       lookup_and_request(&rescue, "GPIO4_11", "rescue");
        dm_gpio_set_dir_flags(&rescue, GPIOD_IS_IN);
 
        /* Wait for ready signal from system "monitoring" device */