]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
siemens: eeprom: simplify setup & read
authorEnrico Leto <enrico.leto@siemens.com>
Wed, 24 Jan 2024 14:43:50 +0000 (15:43 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 5 Feb 2024 18:32:48 +0000 (13:32 -0500)
Since we have boards using the driver model or not for i2c, use abstraction
function to probe the i2c, check the EEPROM and read from EEPROM.

Signed-off-by: Enrico Leto <enrico.leto@siemens.com>
13 files changed:
board/siemens/capricorn/Makefile
board/siemens/common/board.c
board/siemens/common/eeprom.c [new file with mode: 0644]
board/siemens/common/eeprom.h
board/siemens/common/factoryset.c
board/siemens/draco/Makefile
board/siemens/draco/board.c
board/siemens/draco/mux.c
board/siemens/pxm2/Makefile
board/siemens/pxm2/board.c
board/siemens/pxm2/mux.c
board/siemens/rut/Makefile
board/siemens/rut/board.c

index d5846cc8e3cbfb6678a331cd654ce961fe23f72b..4dafac10829032b7d03fdf37f0715dd8f770f403 100644 (file)
@@ -4,6 +4,7 @@
 #
 
 obj-y += board.o
+obj-y += ../common/eeprom.o
 
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
index 420c496581600bf6c980f6aa3b81cd4c77c4e9ac..e412858c4a9775970f9510269d1110ec1e606462 100644 (file)
@@ -29,7 +29,6 @@
 #include <asm/io.h>
 #include <asm/emif.h>
 #include <asm/gpio.h>
-#include <i2c.h>
 #include <miiphy.h>
 #include <cpsw.h>
 #include <watchdog.h>
@@ -39,6 +38,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+
 #ifdef CONFIG_SPL_BUILD
 void set_uart_mux_conf(void)
 {
@@ -49,12 +49,13 @@ void set_mux_conf_regs(void)
 {
        /* Initalize the board header */
        enable_i2c0_pin_mux();
-       i2c_set_bus_num(0);
 
        /* enable early the console */
        gd->baudrate = CONFIG_BAUDRATE;
        serial_init();
        gd->have_console = 1;
+
+       siemens_ee_setup();
        if (read_eeprom() < 0)
                puts("Could not get board ID.\n");
 
@@ -79,8 +80,7 @@ int board_init(void)
 #if defined(CONFIG_HW_WATCHDOG)
        hw_watchdog_init();
 #endif /* defined(CONFIG_HW_WATCHDOG) */
-       i2c_set_bus_num(0);
-       if (read_eeprom() < 0)
+       if (siemens_ee_setup() < 0)
                puts("Could not get board ID.\n");
 #ifdef CONFIG_MACH_TYPE
        gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
diff --git a/board/siemens/common/eeprom.c b/board/siemens/common/eeprom.c
new file mode 100644 (file)
index 0000000..fc93df9
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *
+ * Read EEPROM data
+ * (C) Copyright 2024 Siemens AG
+ */
+
+#include <dm/uclass.h>
+#include <i2c.h>
+#include "eeprom.h"
+
+#if CONFIG_IS_ENABLED(DM_I2C)
+static struct udevice *i2c_dev;
+#endif
+
+/* Probe I2C and set-up EEPROM */
+int siemens_ee_setup(void)
+{
+#if CONFIG_IS_ENABLED(DM_I2C)
+       struct udevice *bus;
+       int ret;
+
+       ret = uclass_get_device_by_seq(UCLASS_I2C, SIEMENS_EE_I2C_BUS, &bus);
+       if (ret)
+               goto err;
+
+       ret = dm_i2c_probe(bus, SIEMENS_EE_I2C_ADDR, 0, &i2c_dev);
+       if (ret)
+               goto err;
+       if (i2c_set_chip_offset_len(i2c_dev, 2))
+               goto err;
+#else
+       i2c_set_bus_num(SIEMENS_EE_I2C_BUS);
+       if (i2c_probe(SIEMENS_EE_I2C_ADDR))
+               goto err;
+#endif
+       return 0;
+
+err:
+       printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
+       return 1;
+}
+
+/* Read data from EEPROM */
+int siemens_ee_read_data(uint address, uchar *buffer, int len)
+{
+#if CONFIG_IS_ENABLED(DM_I2C)
+       return dm_i2c_read(i2c_dev, address, buffer, len);
+#else
+       return i2c_read(SIEMENS_EE_I2C_ADDR, address, 2, buffer, len);
+#endif
+}
index a21d42789a5cad8c418fe6ed8aa5d0e222da2494..a5ef5abbafd83af6370b4b4f6fa9bbab4874ee7d 100644 (file)
@@ -18,4 +18,7 @@
 #define SIEMENS_EE_ADDR_CHIP           0x120
 #define SIEMENS_EE_ADDR_FACTORYSET     0x400
 
+int siemens_ee_setup(void);
+int siemens_ee_read_data(uint address, uchar *buffer, int len);
+
 #endif /* _COMMON_EEPROM_H_ */
index b5befab9f52fa5d9f81881234e4ddd51d2181660..4a1277340a75f35bfd230c88d1234577cc5d55b3 100644 (file)
@@ -148,39 +148,14 @@ int factoryset_read_eeprom(int i2c_addr)
        int i, pages = 0, size = 0;
        unsigned char eeprom_buf[0x3c00], hdr[4], buf[MAX_STRING_LENGTH];
        unsigned char *cp, *cp1;
-#if CONFIG_IS_ENABLED(DM_I2C)
-       struct udevice *bus, *dev;
-       int ret;
-#endif
 
 #if defined(CONFIG_DFU_OVER_USB)
        factory_dat.usb_vendor_id = CONFIG_USB_GADGET_VENDOR_NUM;
        factory_dat.usb_product_id = CONFIG_USB_GADGET_PRODUCT_NUM;
 #endif
 
-#if CONFIG_IS_ENABLED(DM_I2C)
-       ret = uclass_get_device_by_seq(UCLASS_I2C, SIEMENS_EE_I2C_BUS, &bus);
-       if (ret)
-               goto err;
-
-       ret = dm_i2c_probe(bus, i2c_addr, 0, &dev);
-       if (ret)
-               goto err;
-
-       ret = i2c_set_chip_offset_len(dev, 2);
-       if (ret)
-               goto err;
-
-       ret = dm_i2c_read(dev, SIEMENS_EE_ADDR_FACTORYSET, hdr, sizeof(hdr));
-       if (ret)
-               goto err;
-#else
-       if (i2c_probe(i2c_addr))
-               goto err;
-
-       if (i2c_read(i2c_addr, SIEMENS_EE_ADDR_FACTORYSET, 2, hdr, sizeof(hdr)))
+       if (siemens_ee_read_data(SIEMENS_EE_ADDR_FACTORYSET, hdr, sizeof(hdr)))
                goto err;
-#endif
 
        if ((hdr[0] != 0x99) || (hdr[1] != 0x80)) {
                printf("FactorySet is not right in eeprom.\n");
@@ -201,33 +176,16 @@ int factoryset_read_eeprom(int i2c_addr)
         * data after every time we got a record from eeprom
         */
        debug("Read eeprom page :\n");
-       for (i = 0; i < pages; i++) {
-#if CONFIG_IS_ENABLED(DM_I2C)
-               ret = dm_i2c_read(dev, (OFF_PG + i) * EEPR_PG_SZ,
-                                 eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ);
-               if (ret)
+       for (i = 0; i < pages; i++)
+               if (siemens_ee_read_data((OFF_PG + i) * EEPR_PG_SZ,
+                                        eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ))
                        goto err;
-#else
-               if (i2c_read(i2c_addr, (OFF_PG + i) * EEPR_PG_SZ, 2,
-                            eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ))
-                       goto err;
-#endif
-       }
 
-       if (size % EEPR_PG_SZ) {
-#if CONFIG_IS_ENABLED(DM_I2C)
-               ret = dm_i2c_read(dev, (OFF_PG + pages) * EEPR_PG_SZ,
-                                 eeprom_buf + (pages * EEPR_PG_SZ),
-                                 size % EEPR_PG_SZ);
-               if (ret)
-                       goto err;
-#else
-               if (i2c_read(i2c_addr, (OFF_PG + pages) * EEPR_PG_SZ, 2,
-                            eeprom_buf + (pages * EEPR_PG_SZ),
-                            (size % EEPR_PG_SZ)))
+       if (size % EEPR_PG_SZ)
+               if (siemens_ee_read_data((OFF_PG + pages) * EEPR_PG_SZ,
+                                        eeprom_buf + (pages * EEPR_PG_SZ),
+                                        size % EEPR_PG_SZ))
                        goto err;
-#endif
-       }
 
        /* we do below just for eeprom align */
        for (i = 0; i < size; i++)
@@ -249,9 +207,8 @@ int factoryset_read_eeprom(int i2c_addr)
 
 #if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB)
        /* get mac address for WLAN */
-       ret = get_factory_record_val(cp, size, (uchar *)"WLAN1", (uchar *)"mac",
-                                    buf, MAX_STRING_LENGTH);
-       if (ret > 0) {
+       if (get_factory_record_val(cp, size, (uchar *)"WLAN1", (uchar *)"mac",
+                                  buf, MAX_STRING_LENGTH) > 0) {
                cp1 = buf;
                for (i = 0; i < 6; i++) {
                        factory_dat.mac_wlan[i] = hextoul((char *)cp1, NULL);
index e94456ab1c3dc0955a4558d04ac119c7d004f9ac..1d0cb82bcb6c40e851055fb464ae6bf01b9e447c 100644 (file)
@@ -14,6 +14,7 @@ obj-y := mux.o
 endif
 
 obj-y  += board.o
+obj-y += ../common/eeprom.o
 ifndef CONFIG_SPL_BUILD
 obj-y += ../common/factoryset.o
 endif
index 367a300b8978e712c7adf46d1768322bb85d15fd..30ad9d7ab3acab383f00980b8909965bf31fea61 100644 (file)
@@ -138,8 +138,8 @@ static int draco_read_nand_geometry(void)
        struct am335x_nand_geometry geo;
 
        /* Read NAND geometry */
-       if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_NAND_GEO, 2,
-                    (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
+       if (siemens_ee_read_data(SIEMENS_EE_ADDR_NAND_GEO, (uchar *)&geo,
+                                sizeof(struct am335x_nand_geometry))) {
                printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
                return -EIO;
        }
@@ -155,27 +155,21 @@ static int draco_read_nand_geometry(void)
        return 0;
 }
 
+#ifdef CONFIG_SPL_BUILD
 /*
  * Read header information from EEPROM into global structure.
  */
 static int read_eeprom(void)
 {
-       /* Check if baseboard eeprom is available */
-       if (i2c_probe(SIEMENS_EE_I2C_ADDR)) {
-               printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
-               return 1;
-       }
-
-#ifdef CONFIG_SPL_BUILD
        /* Read Siemens eeprom data (DDR3) */
-       if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_DDR3, 2,
-                    (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
+       if (siemens_ee_read_data(SIEMENS_EE_ADDR_DDR3, (uchar *)&settings.ddr3,
+                                sizeof(struct ddr3_data))) {
                printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
                set_default_ddr3_timings();
        }
        /* Read Siemens eeprom data (CHIP) */
-       if (i2c_read(SIEMENS_EE_I2C_ADDR, SIEMENS_EE_ADDR_CHIP, 2,
-                    (uchar *)&settings.chip, sizeof(settings.chip)))
+       if (siemens_ee_read_data(SIEMENS_EE_ADDR_CHIP, (uchar *)&settings.chip,
+                                sizeof(settings.chip)))
                printf("Could not read chip settings\n");
 
        if (ddr3_default.magic == settings.ddr3.magic &&
@@ -199,11 +193,8 @@ static int read_eeprom(void)
        print_ddr3_timings();
 
        return draco_read_nand_geometry();
-#endif
-       return 0;
 }
 
-#ifdef CONFIG_SPL_BUILD
 static void board_init_ddr(void)
 {
 struct emif_regs draco_ddr3_emif_reg_data = {
index 2632f050336103e4febef4f4b6a06a959183f778..56d8f45c34928634a8d7caef30145a2f1baa5234 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/arch/mux.h>
 #include <asm/io.h>
 #include <i2c.h>
-#include "board.h"
+#include "eeprom.h"
 
 static struct module_pin_mux uart0_pin_mux[] = {
        {OFFSET(uart0_rxd), (MODE(0) | PULLUP_EN | RXACTIVE)},  /* UART0_RXD */
index e94456ab1c3dc0955a4558d04ac119c7d004f9ac..1d0cb82bcb6c40e851055fb464ae6bf01b9e447c 100644 (file)
@@ -14,6 +14,7 @@ obj-y := mux.o
 endif
 
 obj-y  += board.o
+obj-y += ../common/eeprom.o
 ifndef CONFIG_SPL_BUILD
 obj-y += ../common/factoryset.o
 endif
index 9e85d9b921daa7250799bb485923e950e2f312b6..16b0d3df757f99b5645d97c091618928f25392a5 100644 (file)
@@ -161,7 +161,6 @@ void spl_siemens_board_init(void)
                printf("voltage update failed\n");
        }
 }
-#endif /* if def CONFIG_SPL_BUILD */
 
 int read_eeprom(void)
 {
@@ -169,6 +168,7 @@ int read_eeprom(void)
 
        return 0;
 }
+#endif /* if def CONFIG_SPL_BUILD */
 
 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
        (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD))
index d21ef47771d184744b47873691ff8e5f58c15e55..07cf56759270ee739f6596efef791a5e02cda133 100644 (file)
@@ -17,7 +17,7 @@
 #include <asm/arch/mux.h>
 #include <asm/io.h>
 #include <i2c.h>
-#include "board.h"
+#include "eeprom.h"
 
 static struct module_pin_mux uart0_pin_mux[] = {
        {OFFSET(uart0_rxd), (MODE(0) | PULLUP_EN | RXACTIVE)},  /* UART0_RXD */
index e94456ab1c3dc0955a4558d04ac119c7d004f9ac..1d0cb82bcb6c40e851055fb464ae6bf01b9e447c 100644 (file)
@@ -14,6 +14,7 @@ obj-y := mux.o
 endif
 
 obj-y  += board.o
+obj-y += ../common/eeprom.o
 ifndef CONFIG_SPL_BUILD
 obj-y += ../common/factoryset.o
 endif
index 49318b320352f9cb3e7231434b1a6e601832f7c9..d9e84db03ef00b31196d0bebd12b747b0e29345b 100644 (file)
@@ -39,6 +39,7 @@
 #include "../common/eeprom.h"
 #include "../common/factoryset.h"
 
+#ifdef CONFIG_SPL_BUILD
 /*
  * Read header information from EEPROM into global structure.
  */
@@ -47,7 +48,6 @@ static int read_eeprom(void)
        return 0;
 }
 
-#ifdef CONFIG_SPL_BUILD
 static void board_init_ddr(void)
 {
 struct emif_regs rut_ddr3_emif_reg_data = {