#
obj-y += board.o
+obj-y += ../common/eeprom.o
ifdef CONFIG_SPL_BUILD
obj-y += spl.o
#include <asm/io.h>
#include <asm/emif.h>
#include <asm/gpio.h>
-#include <i2c.h>
#include <miiphy.h>
#include <cpsw.h>
#include <watchdog.h>
DECLARE_GLOBAL_DATA_PTR;
+
#ifdef CONFIG_SPL_BUILD
void set_uart_mux_conf(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");
#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;
--- /dev/null
+// 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
+}
#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_ */
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");
* 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++)
#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);
endif
obj-y += board.o
+obj-y += ../common/eeprom.o
ifndef CONFIG_SPL_BUILD
obj-y += ../common/factoryset.o
endif
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;
}
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 &&
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 = {
#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 */
endif
obj-y += board.o
+obj-y += ../common/eeprom.o
ifndef CONFIG_SPL_BUILD
obj-y += ../common/factoryset.o
endif
printf("voltage update failed\n");
}
}
-#endif /* if def CONFIG_SPL_BUILD */
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))
#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 */
endif
obj-y += board.o
+obj-y += ../common/eeprom.o
ifndef CONFIG_SPL_BUILD
obj-y += ../common/factoryset.o
endif
#include "../common/eeprom.h"
#include "../common/factoryset.h"
+#ifdef CONFIG_SPL_BUILD
/*
* Read header information from EEPROM into global structure.
*/
return 0;
}
-#ifdef CONFIG_SPL_BUILD
static void board_init_ddr(void)
{
struct emif_regs rut_ddr3_emif_reg_data = {