blob: f8495a7a7cf128f55b765d4e7cd370070f1bd28e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Lokesh Vutla35f7a972016-02-24 12:30:54 -06002/*
3 * Library to support early TI EVM EEPROM handling
4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com
Lokesh Vutla35f7a972016-02-24 12:30:54 -06006 */
7
8#ifndef __BOARD_DETECT_H
9#define __BOARD_DETECT_H
10
11/* TI EEPROM MAGIC Header identifier */
12#define TI_EEPROM_HEADER_MAGIC 0xEE3355AA
13#define TI_DEAD_EEPROM_MAGIC 0xADEAD12C
14
15#define TI_EEPROM_HDR_NAME_LEN 8
16#define TI_EEPROM_HDR_REV_LEN 4
17#define TI_EEPROM_HDR_SERIAL_LEN 12
18#define TI_EEPROM_HDR_CONFIG_LEN 32
19#define TI_EEPROM_HDR_NO_OF_MAC_ADDR 3
20#define TI_EEPROM_HDR_ETH_ALEN 6
21
22/**
23 * struct ti_am_eeprom - This structure holds data read in from the
24 * AM335x, AM437x, AM57xx TI EVM EEPROMs.
25 * @header: This holds the magic number
26 * @name: The name of the board
27 * @version: Board revision
28 * @serial: Board serial number
29 * @config: Reserved
30 * @mac_addr: Any MAC addresses written in the EEPROM
31 *
32 * The data is this structure is read from the EEPROM on the board.
33 * It is used for board detection which is based on name. It is used
34 * to configure specific TI boards. This allows booting of multiple
35 * TI boards with a single MLO and u-boot.
36 */
37struct ti_am_eeprom {
38 unsigned int header;
39 char name[TI_EEPROM_HDR_NAME_LEN];
40 char version[TI_EEPROM_HDR_REV_LEN];
41 char serial[TI_EEPROM_HDR_SERIAL_LEN];
42 char config[TI_EEPROM_HDR_CONFIG_LEN];
43 char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
44} __attribute__ ((__packed__));
45
Lokesh Vutla7c08a782016-03-08 09:18:04 +053046/* DRA7 EEPROM MAGIC Header identifier */
47#define DRA7_EEPROM_HEADER_MAGIC 0xAA5533EE
48#define DRA7_EEPROM_HDR_NAME_LEN 16
49#define DRA7_EEPROM_HDR_CONFIG_LEN 4
50
51/**
52 * struct dra7_eeprom - This structure holds data read in from the DRA7 EVM
53 * EEPROMs.
54 * @header: This holds the magic number
55 * @name: The name of the board
56 * @version_major: Board major version
57 * @version_minor: Board minor version
58 * @config: Board specific config options
59 * @emif1_size: Size of DDR attached to EMIF1
60 * @emif2_size: Size of DDR attached to EMIF2
61 *
62 * The data is this structure is read from the EEPROM on the board.
63 * It is used for board detection which is based on name. It is used
64 * to configure specific DRA7 boards. This allows booting of multiple
65 * DRA7 boards with a single MLO and u-boot.
66 */
67struct dra7_eeprom {
68 u32 header;
69 char name[DRA7_EEPROM_HDR_NAME_LEN];
70 u16 version_major;
71 u16 version_minor;
72 char config[DRA7_EEPROM_HDR_CONFIG_LEN];
73 u32 emif1_size;
74 u32 emif2_size;
75} __attribute__ ((__packed__));
76
Lokesh Vutla35f7a972016-02-24 12:30:54 -060077/**
78 * struct ti_common_eeprom - Null terminated, usable EEPROM contents.
79 * header: Magic number
80 * @name: NULL terminated name
81 * @version: NULL terminated version
82 * @serial: NULL terminated serial number
83 * @config: NULL terminated Board specific config options
84 * @mac_addr: MAC addresses
Lokesh Vutla7c08a782016-03-08 09:18:04 +053085 * @emif1_size: Size of the ddr available on emif1
86 * @emif2_size: Size of the ddr available on emif2
Lokesh Vutla35f7a972016-02-24 12:30:54 -060087 */
88struct ti_common_eeprom {
89 u32 header;
90 char name[TI_EEPROM_HDR_NAME_LEN + 1];
91 char version[TI_EEPROM_HDR_REV_LEN + 1];
92 char serial[TI_EEPROM_HDR_SERIAL_LEN + 1];
93 char config[TI_EEPROM_HDR_CONFIG_LEN + 1];
94 char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
Lokesh Vutla7c08a782016-03-08 09:18:04 +053095 u64 emif1_size;
96 u64 emif2_size;
Lokesh Vutla35f7a972016-02-24 12:30:54 -060097};
98
99#define TI_EEPROM_DATA ((struct ti_common_eeprom *)\
Lokesh Vutla5f60f412017-03-13 15:04:25 +0200100 TI_SRAM_SCRATCH_BOARD_EEPROM_START)
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600101
102/**
103 * ti_i2c_eeprom_am_get() - Consolidated eeprom data collection for AM* TI EVMs
104 * @bus_addr: I2C bus address
105 * @dev_addr: I2C slave address
106 *
107 * ep in SRAM is populated by the this AM generic function that consolidates
108 * the basic initialization logic common across all AM* platforms.
109 */
110int ti_i2c_eeprom_am_get(int bus_addr, int dev_addr);
111
112/**
Lokesh Vutla7c08a782016-03-08 09:18:04 +0530113 * ti_i2c_eeprom_dra7_get() - Consolidated eeprom data for DRA7 TI EVMs
114 * @bus_addr: I2C bus address
115 * @dev_addr: I2C slave address
116 */
117int ti_i2c_eeprom_dra7_get(int bus_addr, int dev_addr);
118
119/**
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600120 * board_ti_is() - Board detection logic for TI EVMs
121 * @name_tag: Tag used in eeprom for the board
122 *
123 * Return: false if board information does not match OR eeprom wasn't read.
124 * true otherwise
125 */
126bool board_ti_is(char *name_tag);
127
128/**
129 * board_ti_rev_is() - Compare board revision for TI EVMs
130 * @rev_tag: Revision tag to check in eeprom
131 * @cmp_len: How many chars to compare?
132 *
133 * NOTE: revision information is often messed up (hence the str len match) :(
134 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500135 * Return: false if board information does not match OR eeprom wasn't read.
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600136 * true otherwise
137 */
138bool board_ti_rev_is(char *rev_tag, int cmp_len);
139
140/**
141 * board_ti_get_rev() - Get board revision for TI EVMs
142 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500143 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600144 * Board revision otherwise
145 */
146char *board_ti_get_rev(void);
147
148/**
149 * board_ti_get_config() - Get board config for TI EVMs
150 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500151 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600152 * Board config otherwise
153 */
154char *board_ti_get_config(void);
155
156/**
157 * board_ti_get_name() - Get board name for TI EVMs
158 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500159 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600160 * Board name otherwise
161 */
162char *board_ti_get_name(void);
163
164/**
165 * board_ti_get_eth_mac_addr() - Get Ethernet MAC address from EEPROM MAC list
166 * @index: 0 based index within the list of MAC addresses
167 * @mac_addr: MAC address contained at the index is returned here
168 *
169 * Does not sanity check the mac_addr. Whatever is stored in EEPROM is returned.
170 */
171void board_ti_get_eth_mac_addr(int index, u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]);
172
173/**
Lokesh Vutla7c08a782016-03-08 09:18:04 +0530174 * board_ti_get_emif1_size() - Get size of the DDR on emif1 for TI EVMs
175 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500176 * Return: NULL if eeprom wasn't read or emif1_size is not available.
Lokesh Vutla7c08a782016-03-08 09:18:04 +0530177 */
178u64 board_ti_get_emif1_size(void);
179
180/**
181 * board_ti_get_emif2_size() - Get size of the DDR on emif2 for TI EVMs
182 *
Nishanth Menon23afc8a2016-10-11 12:39:05 -0500183 * Return: NULL if eeprom wasn't read or emif2_size is not available.
Lokesh Vutla7c08a782016-03-08 09:18:04 +0530184 */
185u64 board_ti_get_emif2_size(void);
186
187/**
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600188 * set_board_info_env() - Setup commonly used board information environment vars
189 * @name: Name of the board
190 *
191 * If name is NULL, default_name is used.
192 */
193void set_board_info_env(char *name);
194
Roger Quadros44c7d9a2017-03-14 15:04:19 +0200195/**
196 * board_ti_set_ethaddr- Sets the ethaddr environment from EEPROM
197 * @index: The first eth<index>addr environment variable to set
198 *
199 * EEPROM should be already read before calling this function.
200 * The EEPROM contains 2 MAC addresses which define the MAC address
201 * range (i.e. first and last MAC address).
202 * This function sets the ethaddr environment variable for all
203 * the available MAC addresses starting from eth<index>addr.
204 */
205void board_ti_set_ethaddr(int index);
206
Nishanth Menon27856ff2017-06-16 17:25:04 -0500207/**
Cooper Jr., Frankline1328c72017-06-16 17:25:08 -0500208 * board_ti_was_eeprom_read() - Check to see if the eeprom contents have been read
209 *
210 * This function is useful to determine if the eeprom has already been read and
211 * its contents have already been loaded into memory. It utiltzes the magic
212 * number that the header value is set to upon successful eeprom read.
213 */
214bool board_ti_was_eeprom_read(void);
215
216/**
Nishanth Menon27856ff2017-06-16 17:25:04 -0500217 * ti_i2c_eeprom_am_set() - Setup the eeprom data with predefined values
218 * @name: Name of the board
219 * @rev: Revision of the board
220 *
221 * In some cases such as in RTC-only mode, we are able to skip reading eeprom
222 * and wasting i2c based initialization time by using predefined flags for
223 * detecting what platform we are booting on. For those platforms, provide
224 * a handy function to pre-program information.
225 *
226 * NOTE: many eeprom information such as serial number, mac address etc is not
227 * available.
228 *
229 * Return: 0 if all went fine, else return error.
230 */
231int ti_i2c_eeprom_am_set(const char *name, const char *rev);
232
Lokesh Vutla35f7a972016-02-24 12:30:54 -0600233#endif /* __BOARD_DETECT_H */