blob: fc93df91d524b7cfb77d6116e56d5f326b2eca33 [file] [log] [blame]
Enrico Leto32f433f2024-01-24 15:43:50 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 *
4 * Read EEPROM data
5 * (C) Copyright 2024 Siemens AG
6 */
7
8#include <dm/uclass.h>
9#include <i2c.h>
10#include "eeprom.h"
11
12#if CONFIG_IS_ENABLED(DM_I2C)
13static struct udevice *i2c_dev;
14#endif
15
16/* Probe I2C and set-up EEPROM */
17int siemens_ee_setup(void)
18{
19#if CONFIG_IS_ENABLED(DM_I2C)
20 struct udevice *bus;
21 int ret;
22
23 ret = uclass_get_device_by_seq(UCLASS_I2C, SIEMENS_EE_I2C_BUS, &bus);
24 if (ret)
25 goto err;
26
27 ret = dm_i2c_probe(bus, SIEMENS_EE_I2C_ADDR, 0, &i2c_dev);
28 if (ret)
29 goto err;
30 if (i2c_set_chip_offset_len(i2c_dev, 2))
31 goto err;
32#else
33 i2c_set_bus_num(SIEMENS_EE_I2C_BUS);
34 if (i2c_probe(SIEMENS_EE_I2C_ADDR))
35 goto err;
36#endif
37 return 0;
38
39err:
40 printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
41 return 1;
42}
43
44/* Read data from EEPROM */
45int siemens_ee_read_data(uint address, uchar *buffer, int len)
46{
47#if CONFIG_IS_ENABLED(DM_I2C)
48 return dm_i2c_read(i2c_dev, address, buffer, len);
49#else
50 return i2c_read(SIEMENS_EE_I2C_ADDR, address, 2, buffer, len);
51#endif
52}