Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * sys_info.c |
| 4 | * |
| 5 | * System information functions |
| 6 | * |
| 7 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
| 8 | * |
| 9 | * Derived from Beagle Board and 3430 SDP code by |
| 10 | * Richard Woodruff <r-woodruff2@ti.com> |
| 11 | * Syed Mohammed Khasim <khasim@ti.com> |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 15 | #include <init.h> |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/arch/cpu.h> |
| 19 | #include <asm/arch/clock.h> |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 20 | #include <power/tps65910.h> |
Igor Grinberg | d5e635e | 2014-11-05 13:29:54 +0200 | [diff] [blame] | 21 | #include <linux/compiler.h> |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 22 | |
| 23 | struct ctrl_stat *cstat = (struct ctrl_stat *)CTRL_BASE; |
| 24 | |
| 25 | /** |
| 26 | * get_cpu_rev(void) - extract rev info |
| 27 | */ |
| 28 | u32 get_cpu_rev(void) |
| 29 | { |
| 30 | u32 id; |
| 31 | u32 rev; |
| 32 | |
| 33 | id = readl(DEVICE_ID); |
| 34 | rev = (id >> 28) & 0xff; |
| 35 | |
| 36 | return rev; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * get_cpu_type(void) - extract cpu info |
| 41 | */ |
| 42 | u32 get_cpu_type(void) |
| 43 | { |
| 44 | u32 id = 0; |
| 45 | u32 partnum; |
| 46 | |
| 47 | id = readl(DEVICE_ID); |
| 48 | partnum = (id >> 12) & 0xffff; |
| 49 | |
| 50 | return partnum; |
| 51 | } |
| 52 | |
| 53 | /** |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 54 | * get_sysboot_value(void) - return SYS_BOOT[4:0] |
| 55 | */ |
| 56 | u32 get_sysboot_value(void) |
| 57 | { |
Masahiro Yamada | 04cfea5 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 58 | return readl(&cstat->statusreg) & SYSBOOT_MASK; |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Lokesh Vutla | 6302e53 | 2017-05-05 12:59:10 +0530 | [diff] [blame] | 61 | u32 get_sys_clk_index(void) |
| 62 | { |
| 63 | struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE; |
| 64 | u32 ind = readl(&ctrl->statusreg); |
| 65 | |
| 66 | #ifdef CONFIG_AM43XX |
| 67 | u32 src; |
| 68 | src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT; |
| 69 | if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */ |
| 70 | return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >> |
| 71 | CTRL_CRYSTAL_FREQ_SELECTION_SHIFT); |
| 72 | else /* Value read from SYS BOOT pins */ |
| 73 | #endif |
| 74 | return ((ind & CTRL_SYSBOOT_15_14_MASK) >> |
| 75 | CTRL_SYSBOOT_15_14_SHIFT); |
| 76 | } |
| 77 | |
| 78 | |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 79 | #ifdef CONFIG_DISPLAY_CPUINFO |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 80 | static char *cpu_revs[] = { |
| 81 | "1.0", |
| 82 | "2.0", |
| 83 | "2.1"}; |
| 84 | |
Tero Kristo | 21bc35e | 2017-03-16 09:48:54 +0200 | [diff] [blame] | 85 | static char *cpu_revs_am43xx[] = { |
| 86 | "1.0", |
| 87 | "1.1", |
| 88 | "1.2"}; |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 89 | |
| 90 | static char *dev_types[] = { |
| 91 | "TST", |
| 92 | "EMU", |
| 93 | "HS", |
| 94 | "GP"}; |
| 95 | |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 96 | /** |
| 97 | * Print CPU information |
| 98 | */ |
| 99 | int print_cpuinfo(void) |
| 100 | { |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 101 | char *cpu_s, *sec_s, *rev_s; |
Tero Kristo | 21bc35e | 2017-03-16 09:48:54 +0200 | [diff] [blame] | 102 | char **cpu_rev_arr = cpu_revs; |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 103 | |
| 104 | switch (get_cpu_type()) { |
| 105 | case AM335X: |
| 106 | cpu_s = "AM335X"; |
| 107 | break; |
Matt Porter | 691fbe3 | 2013-03-15 10:07:06 +0000 | [diff] [blame] | 108 | case TI81XX: |
| 109 | cpu_s = "TI81XX"; |
| 110 | break; |
Lokesh Vutla | 72996bf | 2016-10-04 09:34:50 +0530 | [diff] [blame] | 111 | case AM437X: |
| 112 | cpu_s = "AM437X"; |
Tero Kristo | 21bc35e | 2017-03-16 09:48:54 +0200 | [diff] [blame] | 113 | cpu_rev_arr = cpu_revs_am43xx; |
Lokesh Vutla | 72996bf | 2016-10-04 09:34:50 +0530 | [diff] [blame] | 114 | break; |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 115 | default: |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 116 | cpu_s = "Unknown CPU type"; |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 117 | break; |
| 118 | } |
| 119 | |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 120 | if (get_cpu_rev() < ARRAY_SIZE(cpu_revs)) |
Tero Kristo | 21bc35e | 2017-03-16 09:48:54 +0200 | [diff] [blame] | 121 | rev_s = cpu_rev_arr[get_cpu_rev()]; |
Sergey Alyoshin | 8e796c4 | 2014-05-22 11:56:03 +0400 | [diff] [blame] | 122 | else |
| 123 | rev_s = "?"; |
| 124 | |
| 125 | if (get_device_type() < ARRAY_SIZE(dev_types)) |
| 126 | sec_s = dev_types[get_device_type()]; |
| 127 | else |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 128 | sec_s = "?"; |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 129 | |
Lokesh Vutla | 72996bf | 2016-10-04 09:34:50 +0530 | [diff] [blame] | 130 | printf("CPU : %s-%s rev %s\n", cpu_s, sec_s, rev_s); |
Chandan Nath | 1c95969 | 2011-10-14 02:58:22 +0000 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 135 | |
| 136 | #ifdef CONFIG_AM33XX |
| 137 | int am335x_get_efuse_mpu_max_freq(struct ctrl_dev *cdev) |
| 138 | { |
| 139 | int sil_rev; |
| 140 | |
| 141 | sil_rev = readl(&cdev->deviceid) >> 28; |
| 142 | |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 143 | if (sil_rev == 0) { |
| 144 | /* No efuse in PG 1.0. Use max speed */ |
| 145 | return MPUPLL_M_720; |
| 146 | } else if (sil_rev >= 1) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 147 | /* Check what the efuse says our max speed is. */ |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 148 | int efuse_arm_mpu_max_freq, package_type; |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 149 | efuse_arm_mpu_max_freq = readl(&cdev->efuse_sma); |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 150 | package_type = (efuse_arm_mpu_max_freq & PACKAGE_TYPE_MASK) >> |
| 151 | PACKAGE_TYPE_SHIFT; |
| 152 | |
| 153 | /* PG 2.0, efuse may not be set. */ |
| 154 | if (package_type == PACKAGE_TYPE_UNDEFINED || package_type == |
| 155 | PACKAGE_TYPE_RESERVED) |
| 156 | return MPUPLL_M_800; |
| 157 | |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 158 | switch ((efuse_arm_mpu_max_freq & DEVICE_ID_MASK)) { |
| 159 | case AM335X_ZCZ_1000: |
| 160 | return MPUPLL_M_1000; |
| 161 | case AM335X_ZCZ_800: |
| 162 | return MPUPLL_M_800; |
| 163 | case AM335X_ZCZ_720: |
| 164 | return MPUPLL_M_720; |
| 165 | case AM335X_ZCZ_600: |
| 166 | case AM335X_ZCE_600: |
| 167 | return MPUPLL_M_600; |
| 168 | case AM335X_ZCZ_300: |
| 169 | case AM335X_ZCE_300: |
| 170 | return MPUPLL_M_300; |
| 171 | } |
| 172 | } |
| 173 | |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 174 | /* unknown, use the PG1.0 max */ |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 175 | return MPUPLL_M_720; |
| 176 | } |
| 177 | |
Felix Brack | 17705ac | 2017-10-11 18:42:23 +0200 | [diff] [blame] | 178 | int am335x_get_mpu_vdd(int sil_rev, int frequency) |
| 179 | { |
| 180 | int sel_mask = am335x_get_tps65910_mpu_vdd(sil_rev, frequency); |
| 181 | |
| 182 | switch (sel_mask) { |
| 183 | case TPS65910_OP_REG_SEL_1_3_2_5: |
| 184 | return 1325000; |
| 185 | case TPS65910_OP_REG_SEL_1_2_0: |
| 186 | return 1200000; |
| 187 | case TPS65910_OP_REG_SEL_1_1_0: |
| 188 | return 1100000; |
| 189 | default: |
| 190 | return 1262500; |
| 191 | } |
| 192 | } |
| 193 | |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 194 | int am335x_get_tps65910_mpu_vdd(int sil_rev, int frequency) |
| 195 | { |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 196 | /* For PG2.0 and later, we have one set of values. */ |
| 197 | if (sil_rev >= 1) { |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 198 | switch (frequency) { |
| 199 | case MPUPLL_M_1000: |
| 200 | return TPS65910_OP_REG_SEL_1_3_2_5; |
| 201 | case MPUPLL_M_800: |
| 202 | return TPS65910_OP_REG_SEL_1_2_6; |
| 203 | case MPUPLL_M_720: |
| 204 | return TPS65910_OP_REG_SEL_1_2_0; |
| 205 | case MPUPLL_M_600: |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 206 | case MPUPLL_M_500: |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 207 | case MPUPLL_M_300: |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 208 | return TPS65910_OP_REG_SEL_1_1_0; |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Lokesh Vutla | 1bda373 | 2017-05-05 12:59:08 +0530 | [diff] [blame] | 212 | /* Default to PG1.0 values. */ |
| 213 | return TPS65910_OP_REG_SEL_1_2_6; |
Tom Rini | 5243707 | 2013-08-30 16:28:46 -0400 | [diff] [blame] | 214 | } |
| 215 | #endif |