blob: 7ac67cb4899fe699de5bd872e32133738853e206 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chandan Nath1c959692011-10-14 02:58:22 +00002/*
3 * sys_info.c
4 *
5 * System information functions
6 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05007 * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/
Chandan Nath1c959692011-10-14 02:58:22 +00008 *
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 Nath1c959692011-10-14 02:58:22 +000012 */
13
Simon Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Chandan Nath1c959692011-10-14 02:58:22 +000015#include <asm/io.h>
16#include <asm/arch/sys_proto.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/clock.h>
Tom Rini52437072013-08-30 16:28:46 -040019#include <power/tps65910.h>
Igor Grinbergd5e635e2014-11-05 13:29:54 +020020#include <linux/compiler.h>
Chandan Nath1c959692011-10-14 02:58:22 +000021
22struct ctrl_stat *cstat = (struct ctrl_stat *)CTRL_BASE;
23
24/**
25 * get_cpu_rev(void) - extract rev info
26 */
27u32 get_cpu_rev(void)
28{
29 u32 id;
30 u32 rev;
31
32 id = readl(DEVICE_ID);
33 rev = (id >> 28) & 0xff;
34
35 return rev;
36}
37
38/**
39 * get_cpu_type(void) - extract cpu info
40 */
41u32 get_cpu_type(void)
42{
43 u32 id = 0;
44 u32 partnum;
45
46 id = readl(DEVICE_ID);
47 partnum = (id >> 12) & 0xffff;
48
49 return partnum;
50}
51
52/**
Chandan Nath1c959692011-10-14 02:58:22 +000053 * get_sysboot_value(void) - return SYS_BOOT[4:0]
54 */
55u32 get_sysboot_value(void)
56{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090057 return readl(&cstat->statusreg) & SYSBOOT_MASK;
Chandan Nath1c959692011-10-14 02:58:22 +000058}
59
Lokesh Vutla6302e532017-05-05 12:59:10 +053060u32 get_sys_clk_index(void)
61{
62 struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
63 u32 ind = readl(&ctrl->statusreg);
64
65#ifdef CONFIG_AM43XX
66 u32 src;
67 src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT;
68 if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */
69 return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >>
70 CTRL_CRYSTAL_FREQ_SELECTION_SHIFT);
71 else /* Value read from SYS BOOT pins */
72#endif
73 return ((ind & CTRL_SYSBOOT_15_14_MASK) >>
74 CTRL_SYSBOOT_15_14_SHIFT);
75}
76
Chandan Nath1c959692011-10-14 02:58:22 +000077#ifdef CONFIG_DISPLAY_CPUINFO
Sergey Alyoshin8e796c42014-05-22 11:56:03 +040078static char *cpu_revs[] = {
79 "1.0",
80 "2.0",
81 "2.1"};
82
Tero Kristo21bc35e2017-03-16 09:48:54 +020083static char *cpu_revs_am43xx[] = {
84 "1.0",
85 "1.1",
86 "1.2"};
Sergey Alyoshin8e796c42014-05-22 11:56:03 +040087
88static char *dev_types[] = {
89 "TST",
90 "EMU",
91 "HS",
92 "GP"};
93
Chandan Nath1c959692011-10-14 02:58:22 +000094/**
95 * Print CPU information
96 */
97int print_cpuinfo(void)
98{
Sergey Alyoshin8e796c42014-05-22 11:56:03 +040099 char *cpu_s, *sec_s, *rev_s;
Tero Kristo21bc35e2017-03-16 09:48:54 +0200100 char **cpu_rev_arr = cpu_revs;
Chandan Nath1c959692011-10-14 02:58:22 +0000101
102 switch (get_cpu_type()) {
103 case AM335X:
104 cpu_s = "AM335X";
105 break;
Matt Porter691fbe32013-03-15 10:07:06 +0000106 case TI81XX:
107 cpu_s = "TI81XX";
108 break;
Lokesh Vutla72996bf2016-10-04 09:34:50 +0530109 case AM437X:
110 cpu_s = "AM437X";
Tero Kristo21bc35e2017-03-16 09:48:54 +0200111 cpu_rev_arr = cpu_revs_am43xx;
Lokesh Vutla72996bf2016-10-04 09:34:50 +0530112 break;
Chandan Nath1c959692011-10-14 02:58:22 +0000113 default:
Sergey Alyoshin8e796c42014-05-22 11:56:03 +0400114 cpu_s = "Unknown CPU type";
Chandan Nath1c959692011-10-14 02:58:22 +0000115 break;
116 }
117
Sergey Alyoshin8e796c42014-05-22 11:56:03 +0400118 if (get_cpu_rev() < ARRAY_SIZE(cpu_revs))
Tero Kristo21bc35e2017-03-16 09:48:54 +0200119 rev_s = cpu_rev_arr[get_cpu_rev()];
Sergey Alyoshin8e796c42014-05-22 11:56:03 +0400120 else
121 rev_s = "?";
122
123 if (get_device_type() < ARRAY_SIZE(dev_types))
124 sec_s = dev_types[get_device_type()];
125 else
Chandan Nath1c959692011-10-14 02:58:22 +0000126 sec_s = "?";
Chandan Nath1c959692011-10-14 02:58:22 +0000127
Lokesh Vutla72996bf2016-10-04 09:34:50 +0530128 printf("CPU : %s-%s rev %s\n", cpu_s, sec_s, rev_s);
Chandan Nath1c959692011-10-14 02:58:22 +0000129
130 return 0;
131}
132#endif /* CONFIG_DISPLAY_CPUINFO */
Tom Rini52437072013-08-30 16:28:46 -0400133
134#ifdef CONFIG_AM33XX
135int am335x_get_efuse_mpu_max_freq(struct ctrl_dev *cdev)
136{
137 int sil_rev;
138
139 sil_rev = readl(&cdev->deviceid) >> 28;
140
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530141 if (sil_rev == 0) {
142 /* No efuse in PG 1.0. Use max speed */
143 return MPUPLL_M_720;
144 } else if (sil_rev >= 1) {
Tom Rini52437072013-08-30 16:28:46 -0400145 /* Check what the efuse says our max speed is. */
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530146 int efuse_arm_mpu_max_freq, package_type;
Tom Rini52437072013-08-30 16:28:46 -0400147 efuse_arm_mpu_max_freq = readl(&cdev->efuse_sma);
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530148 package_type = (efuse_arm_mpu_max_freq & PACKAGE_TYPE_MASK) >>
149 PACKAGE_TYPE_SHIFT;
150
151 /* PG 2.0, efuse may not be set. */
152 if (package_type == PACKAGE_TYPE_UNDEFINED || package_type ==
153 PACKAGE_TYPE_RESERVED)
154 return MPUPLL_M_800;
155
Tom Rini52437072013-08-30 16:28:46 -0400156 switch ((efuse_arm_mpu_max_freq & DEVICE_ID_MASK)) {
157 case AM335X_ZCZ_1000:
158 return MPUPLL_M_1000;
159 case AM335X_ZCZ_800:
160 return MPUPLL_M_800;
161 case AM335X_ZCZ_720:
162 return MPUPLL_M_720;
163 case AM335X_ZCZ_600:
164 case AM335X_ZCE_600:
165 return MPUPLL_M_600;
166 case AM335X_ZCZ_300:
167 case AM335X_ZCE_300:
168 return MPUPLL_M_300;
169 }
170 }
171
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530172 /* unknown, use the PG1.0 max */
Tom Rini52437072013-08-30 16:28:46 -0400173 return MPUPLL_M_720;
174}
175
Felix Brack17705ac2017-10-11 18:42:23 +0200176int am335x_get_mpu_vdd(int sil_rev, int frequency)
177{
178 int sel_mask = am335x_get_tps65910_mpu_vdd(sil_rev, frequency);
179
180 switch (sel_mask) {
181 case TPS65910_OP_REG_SEL_1_3_2_5:
182 return 1325000;
183 case TPS65910_OP_REG_SEL_1_2_0:
184 return 1200000;
185 case TPS65910_OP_REG_SEL_1_1_0:
186 return 1100000;
187 default:
188 return 1262500;
189 }
190}
191
Tom Rini52437072013-08-30 16:28:46 -0400192int am335x_get_tps65910_mpu_vdd(int sil_rev, int frequency)
193{
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530194 /* For PG2.0 and later, we have one set of values. */
195 if (sil_rev >= 1) {
Tom Rini52437072013-08-30 16:28:46 -0400196 switch (frequency) {
197 case MPUPLL_M_1000:
198 return TPS65910_OP_REG_SEL_1_3_2_5;
199 case MPUPLL_M_800:
200 return TPS65910_OP_REG_SEL_1_2_6;
201 case MPUPLL_M_720:
202 return TPS65910_OP_REG_SEL_1_2_0;
203 case MPUPLL_M_600:
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530204 case MPUPLL_M_500:
Tom Rini52437072013-08-30 16:28:46 -0400205 case MPUPLL_M_300:
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530206 return TPS65910_OP_REG_SEL_1_1_0;
Tom Rini52437072013-08-30 16:28:46 -0400207 }
208 }
209
Lokesh Vutla1bda3732017-05-05 12:59:08 +0530210 /* Default to PG1.0 values. */
211 return TPS65910_OP_REG_SEL_1_2_6;
Tom Rini52437072013-08-30 16:28:46 -0400212}
213#endif