]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - k3conf/k3conf.git/blob - common/socinfo.c
94b2610947116eb6ade7b32e5241b81d62c009a9
[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/j721e/j721e_host_info.h>
43 /* Assuming these addresses and definitions stay common across K3 devices */
44 #define CTRLMMR_WKUP_JTAG_DEVICE_ID     0x43000018
45 #define DEVICE_ID_FAMILY_SHIFT  26
46 #define DEVICE_ID_FAMILY_MASK   (0x3f << 26)
47 #define DEVICE_ID_BASE_SHIFT    11
48 #define DEVICE_ID_BASE_MASK     (0x1fff << 11)
49 #define DEVICE_ID_SPEED_SHIFT   6
50 #define DEVICE_ID_SPEED_MASK    (0x1f << 6)
51 #define DEVICE_ID_TEMP_SHIFT    3
52 #define DEVICE_ID_TEMP_MASK     (0x7 << 3)
54 #define CTRLMMR_WKUP_JTAG_ID            0x43000014
55 #define JTAG_ID_VARIANT_SHIFT   28
56 #define JTAG_ID_VARIANT_MASK    (0xf << 28)
57 #define JTAG_ID_PARTNO_SHIFT    12
58 #define JTAG_ID_PARTNO_MASK     (0x7ff << 1)
60 #define CTRLMMR_WKUP_DIE_ID0    0x43000020
61 #define CTRLMMR_WKUP_DIE_ID1    0x43000024
62 #define CTRLMMR_WKUP_DIE_ID2    0x43000028
63 #define CTRLMMR_WKUP_DIE_ID3    0x4300002c
64 #define CTRLMMR_WKUP_DEVSTAT    0x43000030
65 #define CTRLMMR_WKUP_BOOTCFG    0x43000034
67 struct k3conf_soc_info soc_info;
69 static const char soc_name[K3_MAX + 1][SOC_NAME_MAX_LENGTH] = {
70         [AM654] = "AM654",
71         [J721E] = "J721E",
72         [K3_MAX] = "UNKNOWN"
73 };
75 static const char soc_revision[REV_PG_MAX + 1][SOC_REVISION_MAX_LENGTH] = {
76         [REV_PG1_0] = "1.0",
77         [REV_PG2_0] = "2.0",
78         [REV_PG_MAX] = "NULL"
79 };
81 static void am654_init(void)
82 {
83         struct ti_sci_info *sci_info = &soc_info.sci_info;
85         sci_info->host_info = am65x_host_info;
86         sci_info->num_hosts = AM65X_MAX_HOST_IDS;
87 }
89 static void j721e_init(void)
90 {
91         struct ti_sci_info *sci_info = &soc_info.sci_info;
93         sci_info->host_info = j721e_host_info;
94         sci_info->num_hosts = J721E_MAX_HOST_IDS;
95 }
97 int soc_init(void)
98 {
99         memset(&soc_info, 0, sizeof(soc_info));
101         soc_info.soc = (mmio_read_32(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
102                         DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
103         soc_info.rev = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
104                         JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
106         if (soc_info.soc > K3_MAX || !soc_name[soc_info.soc]) {
107                 fprintf(stderr, "Unknown Silicon %d\n", soc_info.soc);
108                 return -1;
109         }
110         if (soc_info.rev > REV_PG_MAX) {
111                 fprintf(stderr, "Unknown Silicon revision %d for SoC %s\n",
112                         soc_info.rev, soc_name[soc_info.soc]);
113                 return -1;
114         }
116         strncpy(soc_info.soc_full_name, "", sizeof(soc_info.soc_full_name));
117         strcat(soc_info.soc_full_name, soc_name[soc_info.soc]);
118         strcat(soc_info.soc_full_name, " PG");
119         strcat(soc_info.soc_full_name, soc_revision[soc_info.rev]);
121         soc_info.host_id = DEFAULT_HOST_ID;
123         if (soc_info.soc == AM654)
124                 am654_init();
125         else if (soc_info.soc == J721E)
126                 j721e_init();
128         /* ToDo: Add error if sec_proxy_init/sci_init is failed */
129         if(!k3_sec_proxy_init())
130                 if (!ti_sci_init())
131                         soc_info.ti_sci_enabled = 1;
133         return 0;
136 int soc_is_j721e(void)
138         return soc_info.soc == J721E;
141 int soc_is_am654(void)
143         return soc_info.soc == AM654;