board_detect.h 7.3 KB

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