common: socinfo: Use JTAD_ID register for device identification
[k3conf/k3conf.git] / common / socinfo.c
1 /*
2  * K3 SoC detection and helper apis
3  *
4  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
5  *      Lokesh Vutla <lokeshvutla@ti.com>
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
36 #include <socinfo.h>
37 #include <mmio.h>
38 #include <string.h>
39 #include <sec_proxy.h>
40 #include <soc/am65x/am65x_host_info.h>
41 #include <soc/am65x/am65x_sec_proxy_info.h>
42 #include <soc/am65x/am65x_processors_info.h>
43 #include <soc/am65x/am65x_devices_info.h>
44 #include <soc/am65x/am65x_clocks_info.h>
45 #include <soc/am65x_sr2/am65x_sr2_host_info.h>
46 #include <soc/am65x_sr2/am65x_sr2_sec_proxy_info.h>
47 #include <soc/am65x_sr2/am65x_sr2_processors_info.h>
48 #include <soc/am65x_sr2/am65x_sr2_devices_info.h>
49 #include <soc/am65x_sr2/am65x_sr2_clocks_info.h>
50 #include <soc/j721e/j721e_host_info.h>
51 #include <soc/j721e/j721e_sec_proxy_info.h>
52 #include <soc/j721e/j721e_processors_info.h>
53 #include <soc/j721e/j721e_devices_info.h>
54 #include <soc/j721e/j721e_clocks_info.h>
56 /* Assuming these addresses and definitions stay common across K3 devices */
57 #define CTRLMMR_WKUP_JTAG_DEVICE_ID     0x43000018
58 #define DEVICE_ID_FAMILY_SHIFT  26
59 #define DEVICE_ID_FAMILY_MASK   (0x3f << 26)
60 #define DEVICE_ID_BASE_SHIFT    11
61 #define DEVICE_ID_BASE_MASK     (0x1fff << 11)
62 #define DEVICE_ID_SPEED_SHIFT   6
63 #define DEVICE_ID_SPEED_MASK    (0x1f << 6)
64 #define DEVICE_ID_TEMP_SHIFT    3
65 #define DEVICE_ID_TEMP_MASK     (0x7 << 3)
67 #define CTRLMMR_WKUP_JTAG_ID            0x43000014
68 #define JTAG_ID_VARIANT_SHIFT   28
69 #define JTAG_ID_VARIANT_MASK    (0xf << 28)
70 #define JTAG_ID_PARTNO_SHIFT    12
71 #define JTAG_ID_PARTNO_MASK     (0xffff << 12)
73 #define CTRLMMR_WKUP_DIE_ID0    0x43000020
74 #define CTRLMMR_WKUP_DIE_ID1    0x43000024
75 #define CTRLMMR_WKUP_DIE_ID2    0x43000028
76 #define CTRLMMR_WKUP_DIE_ID3    0x4300002c
77 #define CTRLMMR_WKUP_DEVSTAT    0x43000030
78 #define CTRLMMR_WKUP_BOOTCFG    0x43000034
80 struct k3conf_soc_info soc_info;
82 static const char soc_revision[REV_PG_MAX + 1][SOC_REVISION_MAX_LENGTH] = {
83         [REV_SR1_0] = "1.0",
84         [REV_SR2_0] = "2.0",
85         [REV_PG_MAX] = "NULL"
86 };
88 static void am654_init(void)
89 {
90         struct ti_sci_info *sci_info = &soc_info.sci_info;
92         sci_info->host_info = am65x_host_info;
93         sci_info->num_hosts = AM65X_MAX_HOST_IDS;
94         sci_info->sp_info[MAIN_SEC_PROXY] = am65x_main_sp_info;
95         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM65X_MAIN_SEC_PROXY_THREADS;
96         sci_info->sp_info[MCU_SEC_PROXY] = am65x_mcu_sp_info;
97         sci_info->num_sp_threads[MCU_SEC_PROXY] = AM65X_MCU_SEC_PROXY_THREADS;
98         sci_info->processors_info = am65x_processors_info;
99         sci_info->num_processors = AM65X_MAX_PROCESSORS_IDS;
100         sci_info->devices_info = am65x_devices_info;
101         sci_info->num_devices = AM65X_MAX_DEVICES;
102         sci_info->clocks_info = am65x_clocks_info;
103         sci_info->num_clocks = AM65X_MAX_CLOCKS;
106 static void am654_sr2_init(void)
108         struct ti_sci_info *sci_info = &soc_info.sci_info;
110         sci_info->host_info = am65x_sr2_host_info;
111         sci_info->num_hosts = AM65X_SR2_MAX_HOST_IDS;
112         sci_info->sp_info[MAIN_SEC_PROXY] = am65x_sr2_main_sp_info;
113         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM65X_SR2_MAIN_SEC_PROXY_THREADS;
114         sci_info->sp_info[MCU_SEC_PROXY] = am65x_sr2_mcu_sp_info;
115         sci_info->num_sp_threads[MCU_SEC_PROXY] = AM65X_SR2_MCU_SEC_PROXY_THREADS;
116         sci_info->processors_info = am65x_sr2_processors_info;
117         sci_info->num_processors = AM65X_SR2_MAX_PROCESSORS_IDS;
118         sci_info->devices_info = am65x_sr2_devices_info;
119         sci_info->num_devices = AM65X_SR2_MAX_DEVICES;
120         sci_info->clocks_info = am65x_sr2_clocks_info;
121         sci_info->num_clocks = AM65X_SR2_MAX_CLOCKS;
124 static void j721e_init(void)
126         struct ti_sci_info *sci_info = &soc_info.sci_info;
128         sci_info->host_info = j721e_host_info;
129         sci_info->num_hosts = J721E_MAX_HOST_IDS;
130         sci_info->sp_info[MAIN_SEC_PROXY] = j721e_main_sp_info;
131         sci_info->num_sp_threads[MAIN_SEC_PROXY] = J721E_MAIN_SEC_PROXY_THREADS;
132         sci_info->sp_info[MCU_SEC_PROXY] = j721e_mcu_sp_info;
133         sci_info->num_sp_threads[MCU_SEC_PROXY] = J721E_MCU_SEC_PROXY_THREADS;
134         sci_info->processors_info = j721e_processors_info;
135         sci_info->num_processors = J721E_MAX_PROCESSORS_IDS;
136         sci_info->devices_info = j721e_devices_info;
137         sci_info->num_devices = J721E_MAX_DEVICES;
138         sci_info->clocks_info = j721e_clocks_info;
139         sci_info->num_clocks = J721E_MAX_CLOCKS;
142 int soc_init(uint32_t host_id)
144         char *name;
146         memset(&soc_info, 0, sizeof(soc_info));
148         soc_info.soc = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
149                         JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
150         soc_info.rev = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
151                         JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
153         switch (soc_info.soc) {
154         case AM65X:
155                 name = "AM65x";
156                 break;
157         case J721E:
158                 name = "J721E";
159                 break;
160         default:
161                 fprintf(stderr, "Unknown Silicon %d\n", soc_info.soc);
162                 return -1;
163         };
165         if (soc_info.rev > REV_PG_MAX) {
166                 fprintf(stderr, "Unknown Silicon revision %d for SoC %s\n",
167                         soc_info.rev, name);
168                 return -1;
169         }
171         strncpy(soc_info.soc_full_name, "", sizeof(soc_info.soc_full_name));
172         strcat(soc_info.soc_full_name, name);
173         strcat(soc_info.soc_full_name, " SR");
174         strcat(soc_info.soc_full_name, soc_revision[soc_info.rev]);
176         soc_info.host_id = host_id;
178         if (soc_info.soc == AM65X && soc_info.rev == REV_SR1_0)
179                 am654_init();
180         else if (soc_info.soc == AM65X && soc_info.rev == REV_SR2_0)
181                 am654_sr2_init();
182         else if (soc_info.soc == J721E)
183                 j721e_init();
185         /* ToDo: Add error if sec_proxy_init/sci_init is failed */
186         if(!k3_sec_proxy_init())
187                 if (!ti_sci_init())
188                         soc_info.ti_sci_enabled = 1;
190         return 0;
193 int soc_is_j721e(void)
195         return soc_info.soc == J721E;
198 int soc_is_am654(void)
200         return soc_info.soc == AM65X;