blob: 42344145f9f6d5ecc087b85b78229b5455005570 [file] [log] [blame]
Dave Gerlachf8f8b122020-07-15 23:39:59 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
4 * Dave Gerlach <d-gerlach@ti.com>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <soc.h>
10
11#include <asm/io.h>
12
13#define AM65X 0xbb5a
14#define J721E 0xbb64
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053015#define J7200 0xbb6d
Lokesh Vutlac6558042021-05-06 16:44:48 +053016#define AM64X 0xbb38
David Huang26457192022-01-25 20:56:36 +053017#define J721S2 0xbb75
Suman Anna3fbd35f2022-05-25 13:38:41 +053018#define AM62X 0xbb7e
Dave Gerlachf8f8b122020-07-15 23:39:59 -050019
Dave Gerlachf8f8b122020-07-15 23:39:59 -050020#define JTAG_ID_VARIANT_SHIFT 28
21#define JTAG_ID_VARIANT_MASK (0xf << 28)
22#define JTAG_ID_PARTNO_SHIFT 12
23#define JTAG_ID_PARTNO_MASK (0xffff << 12)
24
Simon Glassb75b15b2020-12-03 16:55:23 -070025struct soc_ti_k3_plat {
Dave Gerlachf8f8b122020-07-15 23:39:59 -050026 const char *family;
27 const char *revision;
28};
29
30static const char *get_family_string(u32 idreg)
31{
32 const char *family;
33 u32 soc;
34
35 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
36
37 switch (soc) {
38 case AM65X:
39 family = "AM65X";
40 break;
41 case J721E:
42 family = "J721E";
43 break;
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053044 case J7200:
45 family = "J7200";
46 break;
Lokesh Vutlac6558042021-05-06 16:44:48 +053047 case AM64X:
48 family = "AM64X";
49 break;
David Huang26457192022-01-25 20:56:36 +053050 case J721S2:
51 family = "J721S2";
52 break;
Suman Anna3fbd35f2022-05-25 13:38:41 +053053 case AM62X:
54 family = "AM62X";
55 break;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050056 default:
57 family = "Unknown Silicon";
58 };
59
60 return family;
61}
62
Bryan Brattlof1a798db2022-01-26 16:07:33 -060063static char *j721e_rev_string_map[] = {
64 "1.0", "1.1",
65};
66
67static char *am65x_rev_string_map[] = {
68 "1.0", "2.0",
69};
70
Dave Gerlachf8f8b122020-07-15 23:39:59 -050071static const char *get_rev_string(u32 idreg)
72{
Dave Gerlachf8f8b122020-07-15 23:39:59 -050073 u32 rev;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060074 u32 soc;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050075
76 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060077 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050078
Bryan Brattlof1a798db2022-01-26 16:07:33 -060079 switch (soc) {
80 case J721E:
81 if (rev > ARRAY_SIZE(j721e_rev_string_map))
82 goto bail;
83 return j721e_rev_string_map[rev];
84
85 case AM65X:
86 if (rev > ARRAY_SIZE(am65x_rev_string_map))
87 goto bail;
88 return am65x_rev_string_map[rev];
89
90 case AM64X:
91 case J7200:
Dave Gerlachf8f8b122020-07-15 23:39:59 -050092 default:
Bryan Brattlof1a798db2022-01-26 16:07:33 -060093 if (!rev)
94 return "1.0";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050095 };
96
Bryan Brattlof1a798db2022-01-26 16:07:33 -060097bail:
98 return "Unknown Revision";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050099}
100
101static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
102{
Simon Glassb75b15b2020-12-03 16:55:23 -0700103 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500104
105 snprintf(buf, size, "%s", plat->family);
106
107 return 0;
108}
109
110static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
111{
Simon Glassb75b15b2020-12-03 16:55:23 -0700112 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500113
114 snprintf(buf, size, "SR%s", plat->revision);
115
116 return 0;
117}
118
119static const struct soc_ops soc_ti_k3_ops = {
120 .get_family = soc_ti_k3_get_family,
121 .get_revision = soc_ti_k3_get_revision,
122};
123
124int soc_ti_k3_probe(struct udevice *dev)
125{
Simon Glassb75b15b2020-12-03 16:55:23 -0700126 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500127 u32 idreg;
128 void *idreg_addr;
129
130 idreg_addr = dev_read_addr_ptr(dev);
131 if (!idreg_addr)
132 return -EINVAL;
133
134 idreg = readl(idreg_addr);
135
136 plat->family = get_family_string(idreg);
137 plat->revision = get_rev_string(idreg);
138
139 return 0;
140}
141
142static const struct udevice_id soc_ti_k3_ids[] = {
143 { .compatible = "ti,am654-chipid" },
144 { }
145};
146
147U_BOOT_DRIVER(soc_ti_k3) = {
148 .name = "soc_ti_k3",
149 .id = UCLASS_SOC,
150 .ops = &soc_ti_k3_ops,
151 .of_match = soc_ti_k3_ids,
152 .probe = soc_ti_k3_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700153 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500154};