board_detect.h 6.9 KB

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