cmd_chip_config.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 * const argv[])
  44. {
  45. int i;
  46. int ret;
  47. int cur_config_nr = -1;
  48. u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
  49. /*
  50. * First switch to correct I2C bus. This is I2C bus 0
  51. * for all currently available 4xx derivats.
  52. */
  53. I2C_SET_BUS(0);
  54. #ifdef CONFIG_CMD_EEPROM
  55. ret = eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  56. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  57. cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  58. #else
  59. ret = i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  60. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  61. 1, cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  62. #endif
  63. if (ret) {
  64. printf("Error reading EEPROM at addr 0x%x\n",
  65. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  66. return -1;
  67. }
  68. /*
  69. * Search the current configuration
  70. */
  71. for (i = 0; i < ppc4xx_config_count; i++) {
  72. if (memcmp(cur_config, ppc4xx_config_val[i].val,
  73. CONFIG_4xx_CONFIG_BLOCKSIZE) == 0)
  74. cur_config_nr = i;
  75. }
  76. if (cur_config_nr == -1) {
  77. printf("Warning: The I2C bootstrap values don't match any"
  78. " of the available options!\n");
  79. printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
  80. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  81. for (i = 0; i < CONFIG_4xx_CONFIG_BLOCKSIZE; i++) {
  82. printf("%02x ", cur_config[i]);
  83. }
  84. printf("\n");
  85. }
  86. if (argc < 2) {
  87. printf("Available configurations (I2C address 0x%02x):\n",
  88. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  89. print_configs(cur_config_nr);
  90. return 0;
  91. }
  92. for (i = 0; i < ppc4xx_config_count; i++) {
  93. /*
  94. * Search for configuration name/label
  95. */
  96. if (strcmp(argv[1], ppc4xx_config_val[i].label) == 0) {
  97. printf("Using configuration:\n%-16s - %s\n",
  98. ppc4xx_config_val[i].label,
  99. ppc4xx_config_val[i].description);
  100. #ifdef CONFIG_CMD_EEPROM
  101. ret = eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  102. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  103. ppc4xx_config_val[i].val,
  104. CONFIG_4xx_CONFIG_BLOCKSIZE);
  105. #else
  106. ret = i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  107. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  108. 1, ppc4xx_config_val[i].val,
  109. CONFIG_4xx_CONFIG_BLOCKSIZE);
  110. #endif
  111. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  112. if (ret) {
  113. printf("Error updating EEPROM at addr 0x%x\n",
  114. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  115. return -1;
  116. }
  117. printf("done (dump via 'i2c md %x 0.1 %x')\n",
  118. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  119. CONFIG_4xx_CONFIG_BLOCKSIZE);
  120. printf("Reset the board for the changes to"
  121. " take effect\n");
  122. return 0;
  123. }
  124. }
  125. printf("Configuration %s not found!\n", argv[1]);
  126. print_configs(cur_config_nr);
  127. return -1;
  128. }
  129. U_BOOT_CMD(
  130. chip_config, 2, 0, do_chip_config,
  131. "program the I2C bootstrap EEPROM",
  132. "[config-label]"
  133. );