spr_misc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * (C) Copyright 2009
  3. * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <i2c.h>
  26. #include <net.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/hardware.h>
  29. #include <asm/arch/spr_xloader_table.h>
  30. #include <asm/arch/spr_defs.h>
  31. #define CPU 0
  32. #define DDR 1
  33. #define SRAM_REL 0xD2801000
  34. DECLARE_GLOBAL_DATA_PTR;
  35. static struct chip_data chip_data;
  36. int dram_init(void)
  37. {
  38. struct xloader_table *xloader_tb =
  39. (struct xloader_table *)XLOADER_TABLE_ADDRESS;
  40. struct xloader_table_1_1 *table_1_1;
  41. struct xloader_table_1_2 *table_1_2;
  42. struct chip_data *chip = &chip_data;
  43. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  44. gd->bd->bi_dram[0].size = get_ram_size(PHYS_SDRAM_1,
  45. PHYS_SDRAM_1_MAXSIZE);
  46. if (XLOADER_TABLE_VERSION_1_1 == xloader_tb->table_version) {
  47. table_1_1 = &xloader_tb->table.table_1_1;
  48. chip->dramfreq = table_1_1->ddrfreq;
  49. chip->dramtype = table_1_1->ddrtype;
  50. } else if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) {
  51. table_1_2 = &xloader_tb->table.table_1_2;
  52. chip->dramfreq = table_1_2->ddrfreq;
  53. chip->dramtype = table_1_2->ddrtype;
  54. } else {
  55. chip->dramfreq = -1;
  56. }
  57. return 0;
  58. }
  59. int misc_init_r(void)
  60. {
  61. setenv("verify", "n");
  62. #if defined(CONFIG_SPEAR_USBTTY)
  63. setenv("stdin", "usbtty");
  64. setenv("stdout", "usbtty");
  65. setenv("stderr", "usbtty");
  66. #endif
  67. return 0;
  68. }
  69. int spear_board_init(ulong mach_type)
  70. {
  71. struct xloader_table *xloader_tb =
  72. (struct xloader_table *)XLOADER_TABLE_ADDRESS;
  73. struct xloader_table_1_2 *table_1_2;
  74. struct chip_data *chip = &chip_data;
  75. gd->bd->bi_arch_number = mach_type;
  76. /* adress of boot parameters */
  77. gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
  78. /* CPU is initialized to work at 333MHz in Xloader */
  79. chip->cpufreq = 333;
  80. if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) {
  81. table_1_2 = &xloader_tb->table.table_1_2;
  82. memcpy(chip->version, table_1_2->version,
  83. sizeof(chip->version));
  84. }
  85. return 0;
  86. }
  87. int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  88. {
  89. void (*sram_setfreq) (unsigned int, unsigned int);
  90. struct chip_data *chip = &chip_data;
  91. unsigned char mac[6];
  92. unsigned int frequency;
  93. if ((argc > 3) || (argc < 2)) {
  94. cmd_usage(cmdtp);
  95. return 1;
  96. }
  97. if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
  98. frequency = simple_strtoul(argv[2], NULL, 0);
  99. if (frequency > 333) {
  100. printf("Frequency is limited to 333MHz\n");
  101. return 1;
  102. }
  103. sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
  104. if (!strcmp(argv[1], "cpufreq")) {
  105. sram_setfreq(CPU, frequency);
  106. printf("CPU frequency changed to %u\n", frequency);
  107. chip->cpufreq = frequency;
  108. } else {
  109. sram_setfreq(DDR, frequency);
  110. printf("DDR frequency changed to %u\n", frequency);
  111. chip->dramfreq = frequency;
  112. }
  113. return 0;
  114. } else if (!strcmp(argv[1], "print")) {
  115. if (chip->cpufreq == -1)
  116. printf("CPU Freq = Not Known\n");
  117. else
  118. printf("CPU Freq = %d MHz\n", chip->cpufreq);
  119. if (chip->dramfreq == -1)
  120. printf("DDR Freq = Not Known\n");
  121. else
  122. printf("DDR Freq = %d MHz\n", chip->dramfreq);
  123. if (chip->dramtype == DDRMOBILE)
  124. printf("DDR Type = MOBILE\n");
  125. else if (chip->dramtype == DDR2)
  126. printf("DDR Type = DDR2\n");
  127. else
  128. printf("DDR Type = Not Known\n");
  129. printf("Xloader Rev = %s\n", chip->version);
  130. return 0;
  131. }
  132. cmd_usage(cmdtp);
  133. return 1;
  134. }
  135. U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
  136. "configure chip",
  137. "chip_config cpufreq/ddrfreq frequency\n"
  138. "chip_config print");