blob: 52b00753b5f4fd5d656d8bc18ddb418057d40bbf [file] [log] [blame]
Lokesh Vutla0bea8132016-02-24 12:30:54 -06001/*
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 */
38struct 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
Lokesh Vutlad3b98a92016-03-08 09:18:04 +053047/* DRA7 EEPROM MAGIC Header identifier */
48#define DRA7_EEPROM_HEADER_MAGIC 0xAA5533EE
49#define DRA7_EEPROM_HDR_NAME_LEN 16
50#define DRA7_EEPROM_HDR_CONFIG_LEN 4
51
52/**
53 * struct dra7_eeprom - This structure holds data read in from the DRA7 EVM
54 * EEPROMs.
55 * @header: This holds the magic number
56 * @name: The name of the board
57 * @version_major: Board major version
58 * @version_minor: Board minor version
59 * @config: Board specific config options
60 * @emif1_size: Size of DDR attached to EMIF1
61 * @emif2_size: Size of DDR attached to EMIF2
62 *
63 * The data is this structure is read from the EEPROM on the board.
64 * It is used for board detection which is based on name. It is used
65 * to configure specific DRA7 boards. This allows booting of multiple
66 * DRA7 boards with a single MLO and u-boot.
67 */
68struct dra7_eeprom {
69 u32 header;
70 char name[DRA7_EEPROM_HDR_NAME_LEN];
71 u16 version_major;
72 u16 version_minor;
73 char config[DRA7_EEPROM_HDR_CONFIG_LEN];
74 u32 emif1_size;
75 u32 emif2_size;
76} __attribute__ ((__packed__));
77
Lokesh Vutla0bea8132016-02-24 12:30:54 -060078/**
79 * struct ti_common_eeprom - Null terminated, usable EEPROM contents.
80 * header: Magic number
81 * @name: NULL terminated name
82 * @version: NULL terminated version
83 * @serial: NULL terminated serial number
84 * @config: NULL terminated Board specific config options
85 * @mac_addr: MAC addresses
Lokesh Vutlad3b98a92016-03-08 09:18:04 +053086 * @emif1_size: Size of the ddr available on emif1
87 * @emif2_size: Size of the ddr available on emif2
Lokesh Vutla0bea8132016-02-24 12:30:54 -060088 */
89struct ti_common_eeprom {
90 u32 header;
91 char name[TI_EEPROM_HDR_NAME_LEN + 1];
92 char version[TI_EEPROM_HDR_REV_LEN + 1];
93 char serial[TI_EEPROM_HDR_SERIAL_LEN + 1];
94 char config[TI_EEPROM_HDR_CONFIG_LEN + 1];
95 char mac_addr[TI_EEPROM_HDR_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
Lokesh Vutlad3b98a92016-03-08 09:18:04 +053096 u64 emif1_size;
97 u64 emif2_size;
Lokesh Vutla0bea8132016-02-24 12:30:54 -060098};
99
100#define TI_EEPROM_DATA ((struct ti_common_eeprom *)\
Lokesh Vutla63989282017-03-13 15:04:25 +0200101 TI_SRAM_SCRATCH_BOARD_EEPROM_START)
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600102
103/**
104 * ti_i2c_eeprom_am_get() - Consolidated eeprom data collection for AM* TI EVMs
105 * @bus_addr: I2C bus address
106 * @dev_addr: I2C slave address
107 *
108 * ep in SRAM is populated by the this AM generic function that consolidates
109 * the basic initialization logic common across all AM* platforms.
110 */
111int ti_i2c_eeprom_am_get(int bus_addr, int dev_addr);
112
113/**
Lokesh Vutlad3b98a92016-03-08 09:18:04 +0530114 * ti_i2c_eeprom_dra7_get() - Consolidated eeprom data for DRA7 TI EVMs
115 * @bus_addr: I2C bus address
116 * @dev_addr: I2C slave address
117 */
118int ti_i2c_eeprom_dra7_get(int bus_addr, int dev_addr);
119
120/**
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600121 * board_ti_is() - Board detection logic for TI EVMs
122 * @name_tag: Tag used in eeprom for the board
123 *
124 * Return: false if board information does not match OR eeprom wasn't read.
125 * true otherwise
126 */
127bool board_ti_is(char *name_tag);
128
129/**
130 * board_ti_rev_is() - Compare board revision for TI EVMs
131 * @rev_tag: Revision tag to check in eeprom
132 * @cmp_len: How many chars to compare?
133 *
134 * NOTE: revision information is often messed up (hence the str len match) :(
135 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500136 * Return: false if board information does not match OR eeprom wasn't read.
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600137 * true otherwise
138 */
139bool board_ti_rev_is(char *rev_tag, int cmp_len);
140
141/**
142 * board_ti_get_rev() - Get board revision for TI EVMs
143 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500144 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600145 * Board revision otherwise
146 */
147char *board_ti_get_rev(void);
148
149/**
150 * board_ti_get_config() - Get board config for TI EVMs
151 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500152 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600153 * Board config otherwise
154 */
155char *board_ti_get_config(void);
156
157/**
158 * board_ti_get_name() - Get board name for TI EVMs
159 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500160 * Return: Empty string if eeprom wasn't read.
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600161 * Board name otherwise
162 */
163char *board_ti_get_name(void);
164
165/**
166 * board_ti_get_eth_mac_addr() - Get Ethernet MAC address from EEPROM MAC list
167 * @index: 0 based index within the list of MAC addresses
168 * @mac_addr: MAC address contained at the index is returned here
169 *
170 * Does not sanity check the mac_addr. Whatever is stored in EEPROM is returned.
171 */
172void board_ti_get_eth_mac_addr(int index, u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]);
173
174/**
Lokesh Vutlad3b98a92016-03-08 09:18:04 +0530175 * board_ti_get_emif1_size() - Get size of the DDR on emif1 for TI EVMs
176 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500177 * Return: NULL if eeprom wasn't read or emif1_size is not available.
Lokesh Vutlad3b98a92016-03-08 09:18:04 +0530178 */
179u64 board_ti_get_emif1_size(void);
180
181/**
182 * board_ti_get_emif2_size() - Get size of the DDR on emif2 for TI EVMs
183 *
Nishanth Menon7774e972016-10-11 12:39:05 -0500184 * Return: NULL if eeprom wasn't read or emif2_size is not available.
Lokesh Vutlad3b98a92016-03-08 09:18:04 +0530185 */
186u64 board_ti_get_emif2_size(void);
187
188/**
Lokesh Vutla0bea8132016-02-24 12:30:54 -0600189 * set_board_info_env() - Setup commonly used board information environment vars
190 * @name: Name of the board
191 *
192 * If name is NULL, default_name is used.
193 */
194void set_board_info_env(char *name);
195
196#endif /* __BOARD_DETECT_H */