xref: /openbmc/u-boot/board/ti/common/board_detect.h (revision 2ac07f75)
1 /*
2  * Library to support early TI EVM EEPROM handling
3  *
4  * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 #ifndef __BOARD_DETECT_H
10 #define __BOARD_DETECT_H
11 
12 /* TI EEPROM MAGIC Header identifier */
13 #define TI_EEPROM_HEADER_MAGIC	0xEE3355AA
14 #define TI_DEAD_EEPROM_MAGIC	0xADEAD12C
15 
16 #define TI_EEPROM_HDR_NAME_LEN		8
17 #define TI_EEPROM_HDR_REV_LEN		4
18 #define TI_EEPROM_HDR_SERIAL_LEN	12
19 #define TI_EEPROM_HDR_CONFIG_LEN	32
20 #define TI_EEPROM_HDR_NO_OF_MAC_ADDR	3
21 #define TI_EEPROM_HDR_ETH_ALEN		6
22 
23 /**
24  * struct ti_am_eeprom - This structure holds data read in from the
25  *                     AM335x, AM437x, AM57xx TI EVM EEPROMs.
26  * @header: This holds the magic number
27  * @name: The name of the board
28  * @version: Board revision
29  * @serial: Board serial number
30  * @config: Reserved
31  * @mac_addr: Any MAC addresses written in the EEPROM
32  *
33  * The data is this structure is read from the EEPROM on the board.
34  * It is used for board detection which is based on name. It is used
35  * to configure specific TI boards. This allows booting of multiple
36  * TI boards with a single MLO and u-boot.
37  */
38 struct ti_am_eeprom {
39 	unsigned int header;
40 	char name[TI_EEPROM_HDR_NAME_LEN];
41 	char version[TI_EEPROM_HDR_REV_LEN];
42 	char serial[TI_EEPROM_HDR_SERIAL_LEN];
43 	char config[TI_EEPROM_HDR_CONFIG_LEN];
44 	char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
45 } __attribute__ ((__packed__));
46 
47 /**
48  * struct ti_common_eeprom - Null terminated, usable EEPROM contents.
49  * header:	Magic number
50  * @name:	NULL terminated name
51  * @version:	NULL terminated version
52  * @serial:	NULL terminated serial number
53  * @config:	NULL terminated Board specific config options
54  * @mac_addr:	MAC addresses
55  */
56 struct ti_common_eeprom {
57 	u32 header;
58 	char name[TI_EEPROM_HDR_NAME_LEN + 1];
59 	char version[TI_EEPROM_HDR_REV_LEN + 1];
60 	char serial[TI_EEPROM_HDR_SERIAL_LEN + 1];
61 	char config[TI_EEPROM_HDR_CONFIG_LEN + 1];
62 	char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
63 };
64 
65 #define TI_EEPROM_DATA ((struct ti_common_eeprom *)\
66 				OMAP_SRAM_SCRATCH_BOARD_EEPROM_START)
67 
68 /**
69  * ti_i2c_eeprom_am_get() - Consolidated eeprom data collection for AM* TI EVMs
70  * @bus_addr:	I2C bus address
71  * @dev_addr:	I2C slave address
72  *
73  * ep in SRAM is populated by the this AM generic function that consolidates
74  * the basic initialization logic common across all AM* platforms.
75  */
76 int ti_i2c_eeprom_am_get(int bus_addr, int dev_addr);
77 
78 /**
79  * board_ti_is() - Board detection logic for TI EVMs
80  * @name_tag:	Tag used in eeprom for the board
81  *
82  * Return: false if board information does not match OR eeprom wasn't read.
83  *	   true otherwise
84  */
85 bool board_ti_is(char *name_tag);
86 
87 /**
88  * board_ti_rev_is() - Compare board revision for TI EVMs
89  * @rev_tag:	Revision tag to check in eeprom
90  * @cmp_len:	How many chars to compare?
91  *
92  * NOTE: revision information is often messed up (hence the str len match) :(
93  *
94  * Return: false if board information does not match OR eeprom was'nt read.
95  *	   true otherwise
96  */
97 bool board_ti_rev_is(char *rev_tag, int cmp_len);
98 
99 /**
100  * board_ti_get_rev() - Get board revision for TI EVMs
101  *
102  * Return: NULL if eeprom was'nt read.
103  *	   Board revision otherwise
104  */
105 char *board_ti_get_rev(void);
106 
107 /**
108  * board_ti_get_config() - Get board config for TI EVMs
109  *
110  * Return: NULL if eeprom was'nt read.
111  *	   Board config otherwise
112  */
113 char *board_ti_get_config(void);
114 
115 /**
116  * board_ti_get_name() - Get board name for TI EVMs
117  *
118  * Return: NULL if eeprom was'nt read.
119  *	   Board name otherwise
120  */
121 char *board_ti_get_name(void);
122 
123 /**
124  * board_ti_get_eth_mac_addr() - Get Ethernet MAC address from EEPROM MAC list
125  * @index:	0 based index within the list of MAC addresses
126  * @mac_addr:	MAC address contained at the index is returned here
127  *
128  * Does not sanity check the mac_addr. Whatever is stored in EEPROM is returned.
129  */
130 void board_ti_get_eth_mac_addr(int index, u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]);
131 
132 /**
133  * set_board_info_env() - Setup commonly used board information environment vars
134  * @name:	Name of the board
135  *
136  * If name is NULL, default_name is used.
137  */
138 void set_board_info_env(char *name);
139 
140 #endif	/* __BOARD_DETECT_H */
141