Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame^] | 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 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <i2c.h> |
| 27 | #include <net.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/arch/hardware.h> |
| 30 | #include <asm/arch/spr_xloader_table.h> |
| 31 | #include <asm/arch/spr_defs.h> |
| 32 | |
| 33 | #define CPU 0 |
| 34 | #define DDR 1 |
| 35 | #define SRAM_REL 0xD2801000 |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | static struct chip_data chip_data; |
| 39 | |
| 40 | int dram_init(void) |
| 41 | { |
| 42 | struct xloader_table *xloader_tb = |
| 43 | (struct xloader_table *)XLOADER_TABLE_ADDRESS; |
| 44 | struct xloader_table_1_1 *table_1_1; |
| 45 | struct xloader_table_1_2 *table_1_2; |
| 46 | struct chip_data *chip = &chip_data; |
| 47 | |
| 48 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 49 | gd->bd->bi_dram[0].size = get_ram_size(PHYS_SDRAM_1, |
| 50 | PHYS_SDRAM_1_MAXSIZE); |
| 51 | |
| 52 | if (XLOADER_TABLE_VERSION_1_1 == xloader_tb->table_version) { |
| 53 | table_1_1 = &xloader_tb->table.table_1_1; |
| 54 | chip->dramfreq = table_1_1->ddrfreq; |
| 55 | chip->dramtype = table_1_1->ddrtype; |
| 56 | |
| 57 | } else if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) { |
| 58 | table_1_2 = &xloader_tb->table.table_1_2; |
| 59 | chip->dramfreq = table_1_2->ddrfreq; |
| 60 | chip->dramtype = table_1_2->ddrtype; |
| 61 | } else { |
| 62 | chip->dramfreq = -1; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | int misc_init_r(void) |
| 69 | { |
| 70 | setenv("verify", "n"); |
| 71 | |
| 72 | #if defined(CONFIG_SPEAR_USBTTY) |
| 73 | setenv("stdin", "usbtty"); |
| 74 | setenv("stdout", "usbtty"); |
| 75 | setenv("stderr", "usbtty"); |
| 76 | #endif |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | int spear_board_init(ulong mach_type) |
| 81 | { |
| 82 | struct xloader_table *xloader_tb = |
| 83 | (struct xloader_table *)XLOADER_TABLE_ADDRESS; |
| 84 | struct xloader_table_1_2 *table_1_2; |
| 85 | struct chip_data *chip = &chip_data; |
| 86 | |
| 87 | gd->bd->bi_arch_number = mach_type; |
| 88 | |
| 89 | /* adress of boot parameters */ |
| 90 | gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR; |
| 91 | |
| 92 | /* CPU is initialized to work at 333MHz in Xloader */ |
| 93 | chip->cpufreq = 333; |
| 94 | |
| 95 | if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) { |
| 96 | table_1_2 = &xloader_tb->table.table_1_2; |
| 97 | memcpy(chip->version, table_1_2->version, |
| 98 | sizeof(chip->version)); |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 105 | { |
| 106 | void (*sram_setfreq) (unsigned int, unsigned int); |
| 107 | struct chip_data *chip = &chip_data; |
| 108 | unsigned char mac[6]; |
| 109 | unsigned int frequency; |
| 110 | |
| 111 | if ((argc > 3) || (argc < 2)) { |
| 112 | cmd_usage(cmdtp); |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) { |
| 117 | |
| 118 | frequency = simple_strtoul(argv[2], NULL, 0); |
| 119 | |
| 120 | if (frequency > 333) { |
| 121 | printf("Frequency is limited to 333MHz\n"); |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz); |
| 126 | |
| 127 | if (!strcmp(argv[1], "cpufreq")) { |
| 128 | sram_setfreq(CPU, frequency); |
| 129 | printf("CPU frequency changed to %u\n", frequency); |
| 130 | |
| 131 | chip->cpufreq = frequency; |
| 132 | } else { |
| 133 | sram_setfreq(DDR, frequency); |
| 134 | printf("DDR frequency changed to %u\n", frequency); |
| 135 | |
| 136 | chip->dramfreq = frequency; |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } else if (!strcmp(argv[1], "print")) { |
| 141 | |
| 142 | if (chip->cpufreq == -1) |
| 143 | printf("CPU Freq = Not Known\n"); |
| 144 | else |
| 145 | printf("CPU Freq = %d MHz\n", chip->cpufreq); |
| 146 | |
| 147 | if (chip->dramfreq == -1) |
| 148 | printf("DDR Freq = Not Known\n"); |
| 149 | else |
| 150 | printf("DDR Freq = %d MHz\n", chip->dramfreq); |
| 151 | |
| 152 | if (chip->dramtype == DDRMOBILE) |
| 153 | printf("DDR Type = MOBILE\n"); |
| 154 | else if (chip->dramtype == DDR2) |
| 155 | printf("DDR Type = DDR2\n"); |
| 156 | else |
| 157 | printf("DDR Type = Not Known\n"); |
| 158 | |
| 159 | printf("Xloader Rev = %s\n", chip->version); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | cmd_usage(cmdtp); |
| 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | U_BOOT_CMD(chip_config, 3, 1, do_chip_config, |
| 169 | "configure chip", |
| 170 | "chip_config cpufreq/ddrfreq frequency\n" |
| 171 | "chip_config print"); |