evm.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * evm.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <common.h>
  16. #include <errno.h>
  17. #include <asm/arch/cpu.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/common_def.h>
  20. #include <i2c.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. /*
  23. * I2C Address of on-board EEPROM
  24. */
  25. #define I2C_BASE_BOARD_ADDR 0x50
  26. #define NO_OF_MAC_ADDR 3
  27. #define ETH_ALEN 6
  28. #define NAME_LEN 8
  29. struct am335x_baseboard_id {
  30. unsigned int magic;
  31. char name[NAME_LEN];
  32. char version[4];
  33. char serial[12];
  34. char config[32];
  35. char mac_addr[NO_OF_MAC_ADDR][ETH_ALEN];
  36. };
  37. static struct am335x_baseboard_id header;
  38. static inline int board_is_bone(void)
  39. {
  40. return !strncmp(header.name, "A335BONE", NAME_LEN);
  41. }
  42. /*
  43. * Read header information from EEPROM into global structure.
  44. */
  45. int read_eeprom(void)
  46. {
  47. /* Check if baseboard eeprom is available */
  48. if (i2c_probe(I2C_BASE_BOARD_ADDR)) {
  49. printf("Could not probe the EEPROM; something fundamentally "
  50. "wrong on the I2C bus.\n");
  51. return -ENODEV;
  52. }
  53. /* read the eeprom using i2c */
  54. if (i2c_read(I2C_BASE_BOARD_ADDR, 0, 2, (uchar *)&header,
  55. sizeof(header))) {
  56. printf("Could not read the EEPROM; something fundamentally"
  57. " wrong on the I2C bus.\n");
  58. return -EIO;
  59. }
  60. if (header.magic != 0xEE3355AA) {
  61. /*
  62. * read the eeprom using i2c again,
  63. * but use only a 1 byte address
  64. */
  65. if (i2c_read(I2C_BASE_BOARD_ADDR, 0, 1, (uchar *)&header,
  66. sizeof(header))) {
  67. printf("Could not read the EEPROM; something "
  68. "fundamentally wrong on the I2C bus.\n");
  69. return -EIO;
  70. }
  71. if (header.magic != 0xEE3355AA) {
  72. printf("Incorrect magic number in EEPROM\n");
  73. return -EINVAL;
  74. }
  75. }
  76. return 0;
  77. }
  78. /*
  79. * Basic board specific setup
  80. */
  81. int board_init(void)
  82. {
  83. enable_uart0_pin_mux();
  84. enable_i2c0_pin_mux();
  85. enable_i2c1_pin_mux();
  86. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  87. if (read_eeprom() < 0)
  88. printf("Could not get board ID.\n");
  89. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  90. return 0;
  91. }