Commit 53af877fd2b509bed0ba84fc0fb2845e0c149e34

Authored by Nikita Kiryanov
Committed by Stefano Babic
1 parent e93e809f2f

compulab: eeprom: add support for obtaining product name

Introduce cl_eeprom_get_product_name() for obtaining product name
from the eeprom.

Cc: Stefano Babic <sbabic@denx.de>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

Showing 2 changed files with 36 additions and 0 deletions Side-by-side Diff

board/compulab/common/eeprom.c
... ... @@ -9,6 +9,7 @@
9 9  
10 10 #include <common.h>
11 11 #include <i2c.h>
  12 +#include "eeprom.h"
12 13  
13 14 #ifndef CONFIG_SYS_I2C_EEPROM_ADDR
14 15 # define CONFIG_SYS_I2C_EEPROM_ADDR 0x50
... ... @@ -25,6 +26,8 @@
25 26 #define BOARD_REV_OFFSET 0
26 27 #define BOARD_REV_OFFSET_LEGACY 6
27 28 #define BOARD_REV_SIZE 2
  29 +#define PRODUCT_NAME_OFFSET 128
  30 +#define PRODUCT_NAME_SIZE 16
28 31 #define MAC_ADDR_OFFSET 4
29 32 #define MAC_ADDR_OFFSET_LEGACY 0
30 33  
... ... @@ -151,4 +154,31 @@
151 154  
152 155 return board_rev;
153 156 };
  157 +
  158 +/*
  159 + * Routine: cl_eeprom_get_board_rev
  160 + * Description: read system revision from eeprom
  161 + *
  162 + * @buf: buffer to store the product name
  163 + * @eeprom_bus: i2c bus num of the eeprom
  164 + *
  165 + * @return: 0 on success, < 0 on failure
  166 + */
  167 +int cl_eeprom_get_product_name(uchar *buf, uint eeprom_bus)
  168 +{
  169 + int err;
  170 +
  171 + if (buf == NULL)
  172 + return -EINVAL;
  173 +
  174 + err = cl_eeprom_setup(eeprom_bus);
  175 + if (err)
  176 + return err;
  177 +
  178 + err = cl_eeprom_read(PRODUCT_NAME_OFFSET, buf, PRODUCT_NAME_SIZE);
  179 + if (!err) /* Protect ourselves from invalid data (unterminated str) */
  180 + buf[PRODUCT_NAME_SIZE - 1] = '\0';
  181 +
  182 + return err;
  183 +}
board/compulab/common/eeprom.h
... ... @@ -9,10 +9,12 @@
9 9  
10 10 #ifndef _EEPROM_
11 11 #define _EEPROM_
  12 +#include <errno.h>
12 13  
13 14 #ifdef CONFIG_SYS_I2C
14 15 int cl_eeprom_read_mac_addr(uchar *buf, uint eeprom_bus);
15 16 u32 cl_eeprom_get_board_rev(uint eeprom_bus);
  17 +int cl_eeprom_get_product_name(uchar *buf, uint eeprom_bus);
16 18 #else
17 19 static inline int cl_eeprom_read_mac_addr(uchar *buf, uint eeprom_bus)
18 20 {
... ... @@ -21,6 +23,10 @@
21 23 static inline u32 cl_eeprom_get_board_rev(uint eeprom_bus)
22 24 {
23 25 return 0;
  26 +}
  27 +static inline int cl_eeprom_get_product_name(uchar *buf, uint eeprom_bus)
  28 +{
  29 + return -ENOSYS;
24 30 }
25 31 #endif
26 32