cmd_chip_config.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * (C) Copyright 2008-2009
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * (C) Copyright 2009
  6. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. *
  26. */
  27. #include <common.h>
  28. #include <command.h>
  29. #include <i2c.h>
  30. #include <asm/ppc4xx_config.h>
  31. #include <asm/io.h>
  32. static void print_configs(int cur_config_nr)
  33. {
  34. int i;
  35. for (i = 0; i < ppc4xx_config_count; i++) {
  36. printf("%-16s - %s", ppc4xx_config_val[i].label,
  37. ppc4xx_config_val[i].description);
  38. if (i == cur_config_nr)
  39. printf(" ***");
  40. printf("\n");
  41. }
  42. }
  43. static int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  44. {
  45. int i;
  46. int ret;
  47. int cur_config_nr = -1;
  48. u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
  49. #ifdef CONFIG_CMD_EEPROM
  50. ret = eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  51. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  52. cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  53. #else
  54. ret = i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  55. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  56. 1, cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  57. #endif
  58. if (ret) {
  59. printf("Error reading EEPROM at addr 0x%x\n",
  60. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  61. return -1;
  62. }
  63. /*
  64. * Search the current configuration
  65. */
  66. for (i = 0; i < ppc4xx_config_count; i++) {
  67. if (memcmp(cur_config, ppc4xx_config_val[i].val,
  68. CONFIG_4xx_CONFIG_BLOCKSIZE) == 0)
  69. cur_config_nr = i;
  70. }
  71. if (cur_config_nr == -1) {
  72. printf("Warning: The I2C bootstrap values don't match any"
  73. " of the available options!\n");
  74. printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
  75. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  76. for (i = 0; i < CONFIG_4xx_CONFIG_BLOCKSIZE; i++) {
  77. printf("%02x ", cur_config[i]);
  78. }
  79. printf("\n");
  80. }
  81. if (argc < 2) {
  82. printf("Available configurations (I2C address 0x%02x):\n",
  83. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  84. print_configs(cur_config_nr);
  85. return 0;
  86. }
  87. for (i = 0; i < ppc4xx_config_count; i++) {
  88. /*
  89. * Search for configuration name/label
  90. */
  91. if (strcmp(argv[1], ppc4xx_config_val[i].label) == 0) {
  92. printf("Using configuration:\n%-16s - %s\n",
  93. ppc4xx_config_val[i].label,
  94. ppc4xx_config_val[i].description);
  95. #ifdef CONFIG_CMD_EEPROM
  96. ret = eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  97. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  98. ppc4xx_config_val[i].val,
  99. CONFIG_4xx_CONFIG_BLOCKSIZE);
  100. #else
  101. ret = i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  102. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  103. 1, ppc4xx_config_val[i].val,
  104. CONFIG_4xx_CONFIG_BLOCKSIZE);
  105. #endif
  106. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  107. if (ret) {
  108. printf("Error updating EEPROM at addr 0x%x\n",
  109. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  110. return -1;
  111. }
  112. printf("done (dump via 'i2c md %x 0.1 %x')\n",
  113. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  114. CONFIG_4xx_CONFIG_BLOCKSIZE);
  115. printf("Reset the board for the changes to"
  116. " take effect\n");
  117. return 0;
  118. }
  119. }
  120. printf("Configuration %s not found!\n", argv[1]);
  121. print_configs(cur_config_nr);
  122. return -1;
  123. }
  124. U_BOOT_CMD(
  125. chip_config, 2, 0, do_chip_config,
  126. "program the I2C bootstrap EEPROM",
  127. "[config-label]"
  128. );