xref: /openbmc/u-boot/board/ti/common/board_detect.h (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
20bea813dSLokesh Vutla /*
30bea813dSLokesh Vutla  * Library to support early TI EVM EEPROM handling
40bea813dSLokesh Vutla  *
50bea813dSLokesh Vutla  * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com
60bea813dSLokesh Vutla  */
70bea813dSLokesh Vutla 
80bea813dSLokesh Vutla #ifndef __BOARD_DETECT_H
90bea813dSLokesh Vutla #define __BOARD_DETECT_H
100bea813dSLokesh Vutla 
110bea813dSLokesh Vutla /* TI EEPROM MAGIC Header identifier */
120bea813dSLokesh Vutla #define TI_EEPROM_HEADER_MAGIC	0xEE3355AA
130bea813dSLokesh Vutla #define TI_DEAD_EEPROM_MAGIC	0xADEAD12C
140bea813dSLokesh Vutla 
150bea813dSLokesh Vutla #define TI_EEPROM_HDR_NAME_LEN		8
160bea813dSLokesh Vutla #define TI_EEPROM_HDR_REV_LEN		4
170bea813dSLokesh Vutla #define TI_EEPROM_HDR_SERIAL_LEN	12
180bea813dSLokesh Vutla #define TI_EEPROM_HDR_CONFIG_LEN	32
190bea813dSLokesh Vutla #define TI_EEPROM_HDR_NO_OF_MAC_ADDR	3
200bea813dSLokesh Vutla #define TI_EEPROM_HDR_ETH_ALEN		6
210bea813dSLokesh Vutla 
220bea813dSLokesh Vutla /**
230bea813dSLokesh Vutla  * struct ti_am_eeprom - This structure holds data read in from the
240bea813dSLokesh Vutla  *                     AM335x, AM437x, AM57xx TI EVM EEPROMs.
250bea813dSLokesh Vutla  * @header: This holds the magic number
260bea813dSLokesh Vutla  * @name: The name of the board
270bea813dSLokesh Vutla  * @version: Board revision
280bea813dSLokesh Vutla  * @serial: Board serial number
290bea813dSLokesh Vutla  * @config: Reserved
300bea813dSLokesh Vutla  * @mac_addr: Any MAC addresses written in the EEPROM
310bea813dSLokesh Vutla  *
320bea813dSLokesh Vutla  * The data is this structure is read from the EEPROM on the board.
330bea813dSLokesh Vutla  * It is used for board detection which is based on name. It is used
340bea813dSLokesh Vutla  * to configure specific TI boards. This allows booting of multiple
350bea813dSLokesh Vutla  * TI boards with a single MLO and u-boot.
360bea813dSLokesh Vutla  */
370bea813dSLokesh Vutla struct ti_am_eeprom {
380bea813dSLokesh Vutla 	unsigned int header;
390bea813dSLokesh Vutla 	char name[TI_EEPROM_HDR_NAME_LEN];
400bea813dSLokesh Vutla 	char version[TI_EEPROM_HDR_REV_LEN];
410bea813dSLokesh Vutla 	char serial[TI_EEPROM_HDR_SERIAL_LEN];
420bea813dSLokesh Vutla 	char config[TI_EEPROM_HDR_CONFIG_LEN];
430bea813dSLokesh Vutla 	char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
440bea813dSLokesh Vutla } __attribute__ ((__packed__));
450bea813dSLokesh Vutla 
46d3b98a9eSLokesh Vutla /* DRA7 EEPROM MAGIC Header identifier */
47d3b98a9eSLokesh Vutla #define DRA7_EEPROM_HEADER_MAGIC	0xAA5533EE
48d3b98a9eSLokesh Vutla #define DRA7_EEPROM_HDR_NAME_LEN	16
49d3b98a9eSLokesh Vutla #define DRA7_EEPROM_HDR_CONFIG_LEN	4
50d3b98a9eSLokesh Vutla 
51d3b98a9eSLokesh Vutla /**
52d3b98a9eSLokesh Vutla  * struct dra7_eeprom - This structure holds data read in from the DRA7 EVM
53d3b98a9eSLokesh Vutla  *			EEPROMs.
54d3b98a9eSLokesh Vutla  * @header: This holds the magic number
55d3b98a9eSLokesh Vutla  * @name: The name of the board
56d3b98a9eSLokesh Vutla  * @version_major: Board major version
57d3b98a9eSLokesh Vutla  * @version_minor: Board minor version
58d3b98a9eSLokesh Vutla  * @config: Board specific config options
59d3b98a9eSLokesh Vutla  * @emif1_size: Size of DDR attached to EMIF1
60d3b98a9eSLokesh Vutla  * @emif2_size: Size of DDR attached to EMIF2
61d3b98a9eSLokesh Vutla  *
62d3b98a9eSLokesh Vutla  * The data is this structure is read from the EEPROM on the board.
63d3b98a9eSLokesh Vutla  * It is used for board detection which is based on name. It is used
64d3b98a9eSLokesh Vutla  * to configure specific DRA7 boards. This allows booting of multiple
65d3b98a9eSLokesh Vutla  * DRA7 boards with a single MLO and u-boot.
66d3b98a9eSLokesh Vutla  */
67d3b98a9eSLokesh Vutla struct dra7_eeprom {
68d3b98a9eSLokesh Vutla 	u32 header;
69d3b98a9eSLokesh Vutla 	char name[DRA7_EEPROM_HDR_NAME_LEN];
70d3b98a9eSLokesh Vutla 	u16 version_major;
71d3b98a9eSLokesh Vutla 	u16 version_minor;
72d3b98a9eSLokesh Vutla 	char config[DRA7_EEPROM_HDR_CONFIG_LEN];
73d3b98a9eSLokesh Vutla 	u32 emif1_size;
74d3b98a9eSLokesh Vutla 	u32 emif2_size;
75d3b98a9eSLokesh Vutla } __attribute__ ((__packed__));
76d3b98a9eSLokesh Vutla 
770bea813dSLokesh Vutla /**
780bea813dSLokesh Vutla  * struct ti_common_eeprom - Null terminated, usable EEPROM contents.
790bea813dSLokesh Vutla  * header:	Magic number
800bea813dSLokesh Vutla  * @name:	NULL terminated name
810bea813dSLokesh Vutla  * @version:	NULL terminated version
820bea813dSLokesh Vutla  * @serial:	NULL terminated serial number
830bea813dSLokesh Vutla  * @config:	NULL terminated Board specific config options
840bea813dSLokesh Vutla  * @mac_addr:	MAC addresses
85d3b98a9eSLokesh Vutla  * @emif1_size:	Size of the ddr available on emif1
86d3b98a9eSLokesh Vutla  * @emif2_size:	Size of the ddr available on emif2
870bea813dSLokesh Vutla  */
880bea813dSLokesh Vutla struct ti_common_eeprom {
890bea813dSLokesh Vutla 	u32 header;
900bea813dSLokesh Vutla 	char name[TI_EEPROM_HDR_NAME_LEN + 1];
910bea813dSLokesh Vutla 	char version[TI_EEPROM_HDR_REV_LEN + 1];
920bea813dSLokesh Vutla 	char serial[TI_EEPROM_HDR_SERIAL_LEN + 1];
930bea813dSLokesh Vutla 	char config[TI_EEPROM_HDR_CONFIG_LEN + 1];
940bea813dSLokesh Vutla 	char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
95d3b98a9eSLokesh Vutla 	u64 emif1_size;
96d3b98a9eSLokesh Vutla 	u64 emif2_size;
970bea813dSLokesh Vutla };
980bea813dSLokesh Vutla 
990bea813dSLokesh Vutla #define TI_EEPROM_DATA ((struct ti_common_eeprom *)\
10063989286SLokesh Vutla 				TI_SRAM_SCRATCH_BOARD_EEPROM_START)
1010bea813dSLokesh Vutla 
1020bea813dSLokesh Vutla /**
1030bea813dSLokesh Vutla  * ti_i2c_eeprom_am_get() - Consolidated eeprom data collection for AM* TI EVMs
1040bea813dSLokesh Vutla  * @bus_addr:	I2C bus address
1050bea813dSLokesh Vutla  * @dev_addr:	I2C slave address
1060bea813dSLokesh Vutla  *
1070bea813dSLokesh Vutla  * ep in SRAM is populated by the this AM generic function that consolidates
1080bea813dSLokesh Vutla  * the basic initialization logic common across all AM* platforms.
1090bea813dSLokesh Vutla  */
1100bea813dSLokesh Vutla int ti_i2c_eeprom_am_get(int bus_addr, int dev_addr);
1110bea813dSLokesh Vutla 
1120bea813dSLokesh Vutla /**
113d3b98a9eSLokesh Vutla  * ti_i2c_eeprom_dra7_get() - Consolidated eeprom data for DRA7 TI EVMs
114d3b98a9eSLokesh Vutla  * @bus_addr:	I2C bus address
115d3b98a9eSLokesh Vutla  * @dev_addr:	I2C slave address
116d3b98a9eSLokesh Vutla  */
117d3b98a9eSLokesh Vutla int ti_i2c_eeprom_dra7_get(int bus_addr, int dev_addr);
118d3b98a9eSLokesh Vutla 
119d3b98a9eSLokesh Vutla /**
1200bea813dSLokesh Vutla  * board_ti_is() - Board detection logic for TI EVMs
1210bea813dSLokesh Vutla  * @name_tag:	Tag used in eeprom for the board
1220bea813dSLokesh Vutla  *
1230bea813dSLokesh Vutla  * Return: false if board information does not match OR eeprom wasn't read.
1240bea813dSLokesh Vutla  *	   true otherwise
1250bea813dSLokesh Vutla  */
1260bea813dSLokesh Vutla bool board_ti_is(char *name_tag);
1270bea813dSLokesh Vutla 
1280bea813dSLokesh Vutla /**
1290bea813dSLokesh Vutla  * board_ti_rev_is() - Compare board revision for TI EVMs
1300bea813dSLokesh Vutla  * @rev_tag:	Revision tag to check in eeprom
1310bea813dSLokesh Vutla  * @cmp_len:	How many chars to compare?
1320bea813dSLokesh Vutla  *
1330bea813dSLokesh Vutla  * NOTE: revision information is often messed up (hence the str len match) :(
1340bea813dSLokesh Vutla  *
1357774e97aSNishanth Menon  * Return: false if board information does not match OR eeprom wasn't read.
1360bea813dSLokesh Vutla  *	   true otherwise
1370bea813dSLokesh Vutla  */
1380bea813dSLokesh Vutla bool board_ti_rev_is(char *rev_tag, int cmp_len);
1390bea813dSLokesh Vutla 
1400bea813dSLokesh Vutla /**
1410bea813dSLokesh Vutla  * board_ti_get_rev() - Get board revision for TI EVMs
1420bea813dSLokesh Vutla  *
1437774e97aSNishanth Menon  * Return: Empty string if eeprom wasn't read.
1440bea813dSLokesh Vutla  *	   Board revision otherwise
1450bea813dSLokesh Vutla  */
1460bea813dSLokesh Vutla char *board_ti_get_rev(void);
1470bea813dSLokesh Vutla 
1480bea813dSLokesh Vutla /**
1490bea813dSLokesh Vutla  * board_ti_get_config() - Get board config for TI EVMs
1500bea813dSLokesh Vutla  *
1517774e97aSNishanth Menon  * Return: Empty string if eeprom wasn't read.
1520bea813dSLokesh Vutla  *	   Board config otherwise
1530bea813dSLokesh Vutla  */
1540bea813dSLokesh Vutla char *board_ti_get_config(void);
1550bea813dSLokesh Vutla 
1560bea813dSLokesh Vutla /**
1570bea813dSLokesh Vutla  * board_ti_get_name() - Get board name for TI EVMs
1580bea813dSLokesh Vutla  *
1597774e97aSNishanth Menon  * Return: Empty string if eeprom wasn't read.
1600bea813dSLokesh Vutla  *	   Board name otherwise
1610bea813dSLokesh Vutla  */
1620bea813dSLokesh Vutla char *board_ti_get_name(void);
1630bea813dSLokesh Vutla 
1640bea813dSLokesh Vutla /**
1650bea813dSLokesh Vutla  * board_ti_get_eth_mac_addr() - Get Ethernet MAC address from EEPROM MAC list
1660bea813dSLokesh Vutla  * @index:	0 based index within the list of MAC addresses
1670bea813dSLokesh Vutla  * @mac_addr:	MAC address contained at the index is returned here
1680bea813dSLokesh Vutla  *
1690bea813dSLokesh Vutla  * Does not sanity check the mac_addr. Whatever is stored in EEPROM is returned.
1700bea813dSLokesh Vutla  */
1710bea813dSLokesh Vutla void board_ti_get_eth_mac_addr(int index, u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]);
1720bea813dSLokesh Vutla 
1730bea813dSLokesh Vutla /**
174d3b98a9eSLokesh Vutla  * board_ti_get_emif1_size() - Get size of the DDR on emif1 for TI EVMs
175d3b98a9eSLokesh Vutla  *
1767774e97aSNishanth Menon  * Return: NULL if eeprom wasn't read or emif1_size is not available.
177d3b98a9eSLokesh Vutla  */
178d3b98a9eSLokesh Vutla u64 board_ti_get_emif1_size(void);
179d3b98a9eSLokesh Vutla 
180d3b98a9eSLokesh Vutla /**
181d3b98a9eSLokesh Vutla  * board_ti_get_emif2_size() - Get size of the DDR on emif2 for TI EVMs
182d3b98a9eSLokesh Vutla  *
1837774e97aSNishanth Menon  * Return: NULL if eeprom wasn't read or emif2_size is not available.
184d3b98a9eSLokesh Vutla  */
185d3b98a9eSLokesh Vutla u64 board_ti_get_emif2_size(void);
186d3b98a9eSLokesh Vutla 
187d3b98a9eSLokesh Vutla /**
1880bea813dSLokesh Vutla  * set_board_info_env() - Setup commonly used board information environment vars
1890bea813dSLokesh Vutla  * @name:	Name of the board
1900bea813dSLokesh Vutla  *
1910bea813dSLokesh Vutla  * If name is NULL, default_name is used.
1920bea813dSLokesh Vutla  */
1930bea813dSLokesh Vutla void set_board_info_env(char *name);
1940bea813dSLokesh Vutla 
19538f719eaSRoger Quadros /**
19638f719eaSRoger Quadros  * board_ti_set_ethaddr- Sets the ethaddr environment from EEPROM
19738f719eaSRoger Quadros  * @index: The first eth<index>addr environment variable to set
19838f719eaSRoger Quadros  *
19938f719eaSRoger Quadros  * EEPROM should be already read before calling this function.
20038f719eaSRoger Quadros  * The EEPROM contains 2 MAC addresses which define the MAC address
20138f719eaSRoger Quadros  * range (i.e. first and last MAC address).
20238f719eaSRoger Quadros  * This function sets the ethaddr environment variable for all
20338f719eaSRoger Quadros  * the available MAC addresses starting from eth<index>addr.
20438f719eaSRoger Quadros  */
20538f719eaSRoger Quadros void board_ti_set_ethaddr(int index);
20638f719eaSRoger Quadros 
207e936f997SNishanth Menon /**
20869e8d4baSCooper Jr., Franklin  * board_ti_was_eeprom_read() - Check to see if the eeprom contents have been read
20969e8d4baSCooper Jr., Franklin  *
21069e8d4baSCooper Jr., Franklin  * This function is useful to determine if the eeprom has already been read and
21169e8d4baSCooper Jr., Franklin  * its contents have already been loaded into memory. It utiltzes the magic
21269e8d4baSCooper Jr., Franklin  * number that the header value is set to upon successful eeprom read.
21369e8d4baSCooper Jr., Franklin  */
21469e8d4baSCooper Jr., Franklin bool board_ti_was_eeprom_read(void);
21569e8d4baSCooper Jr., Franklin 
21669e8d4baSCooper Jr., Franklin /**
217e936f997SNishanth Menon  * ti_i2c_eeprom_am_set() - Setup the eeprom data with predefined values
218e936f997SNishanth Menon  * @name:	Name of the board
219e936f997SNishanth Menon  * @rev:	Revision of the board
220e936f997SNishanth Menon  *
221e936f997SNishanth Menon  * In some cases such as in RTC-only mode, we are able to skip reading eeprom
222e936f997SNishanth Menon  * and wasting i2c based initialization time by using predefined flags for
223e936f997SNishanth Menon  * detecting what platform we are booting on. For those platforms, provide
224e936f997SNishanth Menon  * a handy function to pre-program information.
225e936f997SNishanth Menon  *
226e936f997SNishanth Menon  * NOTE: many eeprom information such as serial number, mac address etc is not
227e936f997SNishanth Menon  * available.
228e936f997SNishanth Menon  *
229e936f997SNishanth Menon  * Return: 0 if all went fine, else return error.
230e936f997SNishanth Menon  */
231e936f997SNishanth Menon int ti_i2c_eeprom_am_set(const char *name, const char *rev);
232e936f997SNishanth Menon 
2330bea813dSLokesh Vutla #endif	/* __BOARD_DETECT_H */
234