blob: b585e47d46fe52019be674ecd36cccacb419cdd5 [file] [log] [blame]
Dave Gerlachf8f8b122020-07-15 23:39:59 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
Nishanth Menoneaa39c62023-11-01 15:56:03 -05003 * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
Dave Gerlachf8f8b122020-07-15 23:39:59 -05004 * Dave Gerlach <d-gerlach@ti.com>
5 */
6
Dave Gerlachf8f8b122020-07-15 23:39:59 -05007#include <dm.h>
8#include <soc.h>
9
Andrew Davisf92ee082023-04-06 11:38:12 -050010#include <asm/arch/hardware.h>
Dave Gerlachf8f8b122020-07-15 23:39:59 -050011#include <asm/io.h>
12
Simon Glassb75b15b2020-12-03 16:55:23 -070013struct soc_ti_k3_plat {
Dave Gerlachf8f8b122020-07-15 23:39:59 -050014 const char *family;
15 const char *revision;
16};
17
18static const char *get_family_string(u32 idreg)
19{
20 const char *family;
21 u32 soc;
22
23 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
24
25 switch (soc) {
Andrew Davisf92ee082023-04-06 11:38:12 -050026 case JTAG_ID_PARTNO_AM65X:
Dave Gerlachf8f8b122020-07-15 23:39:59 -050027 family = "AM65X";
28 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050029 case JTAG_ID_PARTNO_J721E:
Dave Gerlachf8f8b122020-07-15 23:39:59 -050030 family = "J721E";
31 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050032 case JTAG_ID_PARTNO_J7200:
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053033 family = "J7200";
34 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050035 case JTAG_ID_PARTNO_AM64X:
Lokesh Vutlac6558042021-05-06 16:44:48 +053036 family = "AM64X";
37 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050038 case JTAG_ID_PARTNO_J721S2:
David Huang26457192022-01-25 20:56:36 +053039 family = "J721S2";
40 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050041 case JTAG_ID_PARTNO_AM62X:
Suman Anna3fbd35f2022-05-25 13:38:41 +053042 family = "AM62X";
43 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050044 case JTAG_ID_PARTNO_AM62AX:
Bryan Brattlof0c3a0732022-11-03 19:13:54 -050045 family = "AM62AX";
46 break;
Apurva Nandan197dc2c2024-02-24 01:51:43 +053047 case JTAG_ID_PARTNO_J784S4:
48 family = "J784S4";
49 break;
Bryan Brattloff0f6ce12024-03-12 15:20:19 -050050 case JTAG_ID_PARTNO_AM62PX:
51 family = "AM62PX";
52 break;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050053 default:
54 family = "Unknown Silicon";
55 };
56
57 return family;
58}
59
Bryan Brattlof1a798db2022-01-26 16:07:33 -060060static char *j721e_rev_string_map[] = {
61 "1.0", "1.1",
62};
63
Bryan Brattlof05722fd2022-06-21 16:36:03 -050064static char *typical_rev_string_map[] = {
65 "1.0", "2.0", "3.0",
Bryan Brattlof1a798db2022-01-26 16:07:33 -060066};
67
Dave Gerlachf8f8b122020-07-15 23:39:59 -050068static const char *get_rev_string(u32 idreg)
69{
Dave Gerlachf8f8b122020-07-15 23:39:59 -050070 u32 rev;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060071 u32 soc;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050072
73 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060074 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050075
Bryan Brattlof1a798db2022-01-26 16:07:33 -060076 switch (soc) {
Andrew Davisf92ee082023-04-06 11:38:12 -050077 case JTAG_ID_PARTNO_J721E:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010078 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
Bryan Brattlof1a798db2022-01-26 16:07:33 -060079 goto bail;
80 return j721e_rev_string_map[rev];
81
Dave Gerlachf8f8b122020-07-15 23:39:59 -050082 default:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010083 if (rev >= ARRAY_SIZE(typical_rev_string_map))
Bryan Brattlof05722fd2022-06-21 16:36:03 -050084 goto bail;
85 return typical_rev_string_map[rev];
Dave Gerlachf8f8b122020-07-15 23:39:59 -050086 };
87
Bryan Brattlof1a798db2022-01-26 16:07:33 -060088bail:
89 return "Unknown Revision";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050090}
91
92static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
93{
Simon Glassb75b15b2020-12-03 16:55:23 -070094 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -050095
96 snprintf(buf, size, "%s", plat->family);
97
98 return 0;
99}
100
101static int soc_ti_k3_get_revision(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, "SR%s", plat->revision);
106
107 return 0;
108}
109
110static const struct soc_ops soc_ti_k3_ops = {
111 .get_family = soc_ti_k3_get_family,
112 .get_revision = soc_ti_k3_get_revision,
113};
114
115int soc_ti_k3_probe(struct udevice *dev)
116{
Simon Glassb75b15b2020-12-03 16:55:23 -0700117 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500118 u32 idreg;
119 void *idreg_addr;
120
121 idreg_addr = dev_read_addr_ptr(dev);
122 if (!idreg_addr)
123 return -EINVAL;
124
125 idreg = readl(idreg_addr);
126
127 plat->family = get_family_string(idreg);
128 plat->revision = get_rev_string(idreg);
129
130 return 0;
131}
132
133static const struct udevice_id soc_ti_k3_ids[] = {
134 { .compatible = "ti,am654-chipid" },
135 { }
136};
137
138U_BOOT_DRIVER(soc_ti_k3) = {
139 .name = "soc_ti_k3",
140 .id = UCLASS_SOC,
141 .ops = &soc_ti_k3_ops,
142 .of_match = soc_ti_k3_ids,
143 .probe = soc_ti_k3_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700144 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500145};