cmd_chip_config.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <i2c.h>
  13. #include <asm/ppc4xx_config.h>
  14. #include <asm/io.h>
  15. static void print_configs(int cur_config_nr)
  16. {
  17. int i;
  18. for (i = 0; i < ppc4xx_config_count; i++) {
  19. printf("%-16s - %s", ppc4xx_config_val[i].label,
  20. ppc4xx_config_val[i].description);
  21. if (i == cur_config_nr)
  22. printf(" ***");
  23. printf("\n");
  24. }
  25. }
  26. static int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  27. {
  28. int i;
  29. int ret;
  30. int cur_config_nr = -1;
  31. u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
  32. /*
  33. * First switch to correct I2C bus. This is I2C bus 0
  34. * for all currently available 4xx derivats.
  35. */
  36. i2c_set_bus_num(0);
  37. #ifdef CONFIG_CMD_EEPROM
  38. ret = eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  39. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  40. cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  41. #else
  42. ret = i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  43. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  44. 1, cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  45. #endif
  46. if (ret) {
  47. printf("Error reading EEPROM at addr 0x%x\n",
  48. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  49. return -1;
  50. }
  51. /*
  52. * Search the current configuration
  53. */
  54. for (i = 0; i < ppc4xx_config_count; i++) {
  55. if (memcmp(cur_config, ppc4xx_config_val[i].val,
  56. CONFIG_4xx_CONFIG_BLOCKSIZE) == 0)
  57. cur_config_nr = i;
  58. }
  59. if (cur_config_nr == -1) {
  60. printf("Warning: The I2C bootstrap values don't match any"
  61. " of the available options!\n");
  62. printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
  63. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  64. for (i = 0; i < CONFIG_4xx_CONFIG_BLOCKSIZE; i++) {
  65. printf("%02x ", cur_config[i]);
  66. }
  67. printf("\n");
  68. }
  69. if (argc < 2) {
  70. printf("Available configurations (I2C address 0x%02x):\n",
  71. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  72. print_configs(cur_config_nr);
  73. return 0;
  74. }
  75. for (i = 0; i < ppc4xx_config_count; i++) {
  76. /*
  77. * Search for configuration name/label
  78. */
  79. if (strcmp(argv[1], ppc4xx_config_val[i].label) == 0) {
  80. printf("Using configuration:\n%-16s - %s\n",
  81. ppc4xx_config_val[i].label,
  82. ppc4xx_config_val[i].description);
  83. #ifdef CONFIG_CMD_EEPROM
  84. ret = eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  85. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  86. ppc4xx_config_val[i].val,
  87. CONFIG_4xx_CONFIG_BLOCKSIZE);
  88. #else
  89. ret = i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  90. CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  91. 1, ppc4xx_config_val[i].val,
  92. CONFIG_4xx_CONFIG_BLOCKSIZE);
  93. #endif
  94. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  95. if (ret) {
  96. printf("Error updating EEPROM at addr 0x%x\n",
  97. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  98. return -1;
  99. }
  100. printf("done (dump via 'i2c md %x 0.1 %x')\n",
  101. CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  102. CONFIG_4xx_CONFIG_BLOCKSIZE);
  103. printf("Reset the board for the changes to"
  104. " take effect\n");
  105. return 0;
  106. }
  107. }
  108. printf("Configuration %s not found!\n", argv[1]);
  109. print_configs(cur_config_nr);
  110. return -1;
  111. }
  112. U_BOOT_CMD(
  113. chip_config, 2, 0, do_chip_config,
  114. "program the I2C bootstrap EEPROM",
  115. "[config-label]"
  116. );