siemens: eeprom: simplify setup & read

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>
This commit is contained in:
Enrico Leto
2024-01-24 15:43:50 +01:00
committed by Tom Rini
parent 5ae54613eb
commit e9ef9a1377
13 changed files with 84 additions and 77 deletions

View File

@@ -4,6 +4,7 @@
#
obj-y += board.o
obj-y += ../common/eeprom.o
ifdef CONFIG_SPL_BUILD
obj-y += spl.o

View 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;

View File

@@ -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
}

View 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_ */

View File

@@ -148,40 +148,15 @@ 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)
if (siemens_ee_read_data(SIEMENS_EE_ADDR_FACTORYSET, hdr, sizeof(hdr)))
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)))
goto err;
#endif
if ((hdr[0] != 0x99) || (hdr[1] != 0x80)) {
printf("FactorySet is not right in eeprom.\n");
return 1;
@@ -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)
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;
#else
if (i2c_read(i2c_addr, (OFF_PG + pages) * EEPR_PG_SZ, 2,
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);

View 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

View 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 = {

View 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 */

View 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

View 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))

View 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 */

View 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

View 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 = {