blob: a3acca4d394273aad53efd3eee200ecdda50c31b [file] [log] [blame]
Dave Gerlach3e1b59c2020-07-15 23:39:59 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
Nishanth Menona94a4072023-11-01 15:56:03 -05003 * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
Dave Gerlach3e1b59c2020-07-15 23:39:59 -05004 * Dave Gerlach <d-gerlach@ti.com>
5 */
6
Dave Gerlach3e1b59c2020-07-15 23:39:59 -05007#include <dm.h>
8#include <soc.h>
9
Andrew Davis677a1e22023-04-06 11:38:12 -050010#include <asm/arch/hardware.h>
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050011#include <asm/io.h>
12
Simon Glass8a8d24b2020-12-03 16:55:23 -070013struct soc_ti_k3_plat {
Dave Gerlach3e1b59c2020-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 Davis677a1e22023-04-06 11:38:12 -050026 case JTAG_ID_PARTNO_AM62X:
Suman Anna4298ee72022-05-25 13:38:41 +053027 family = "AM62X";
28 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050029 case JTAG_ID_PARTNO_AM62AX:
Bryan Brattlofe38025c2022-11-03 19:13:54 -050030 family = "AM62AX";
31 break;
Bryan Brattlof026c9722024-03-12 15:20:19 -050032 case JTAG_ID_PARTNO_AM62PX:
33 family = "AM62PX";
34 break;
Jayesh Choudhary6f6f2882024-06-12 14:41:11 +053035 case JTAG_ID_PARTNO_AM64X:
36 family = "AM64X";
37 break;
38 case JTAG_ID_PARTNO_AM65X:
39 family = "AM65X";
40 break;
41 case JTAG_ID_PARTNO_J7200:
42 family = "J7200";
43 break;
44 case JTAG_ID_PARTNO_J721E:
45 family = "J721E";
46 break;
47 case JTAG_ID_PARTNO_J721S2:
48 family = "J721S2";
49 break;
Jayesh Choudharyc826dee2024-06-12 14:41:12 +053050 case JTAG_ID_PARTNO_J722S:
51 family = "J722S";
52 break;
Jayesh Choudhary6f6f2882024-06-12 14:41:11 +053053 case JTAG_ID_PARTNO_J784S4:
54 family = "J784S4";
55 break;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050056 default:
57 family = "Unknown Silicon";
58 };
59
60 return family;
61}
62
Bryan Brattlof708f54f2022-01-26 16:07:33 -060063static char *j721e_rev_string_map[] = {
Neha Malcom Francis6b8df602024-07-15 16:45:50 +053064 "1.0", "1.1", "2.0",
Bryan Brattlof708f54f2022-01-26 16:07:33 -060065};
66
Bryan Brattlof10c8baf2022-06-21 16:36:03 -050067static char *typical_rev_string_map[] = {
68 "1.0", "2.0", "3.0",
Bryan Brattlof708f54f2022-01-26 16:07:33 -060069};
70
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050071static const char *get_rev_string(u32 idreg)
72{
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050073 u32 rev;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060074 u32 soc;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050075
76 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060077 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050078
Bryan Brattlof708f54f2022-01-26 16:07:33 -060079 switch (soc) {
Andrew Davis677a1e22023-04-06 11:38:12 -050080 case JTAG_ID_PARTNO_J721E:
Rasmus Villemoes45981a92023-03-24 08:44:29 +010081 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
Bryan Brattlof708f54f2022-01-26 16:07:33 -060082 goto bail;
83 return j721e_rev_string_map[rev];
84
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050085 default:
Rasmus Villemoes45981a92023-03-24 08:44:29 +010086 if (rev >= ARRAY_SIZE(typical_rev_string_map))
Bryan Brattlof10c8baf2022-06-21 16:36:03 -050087 goto bail;
88 return typical_rev_string_map[rev];
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050089 };
90
Bryan Brattlof708f54f2022-01-26 16:07:33 -060091bail:
92 return "Unknown Revision";
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050093}
94
95static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
96{
Simon Glass8a8d24b2020-12-03 16:55:23 -070097 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050098
99 snprintf(buf, size, "%s", plat->family);
100
101 return 0;
102}
103
104static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
105{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700106 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500107
108 snprintf(buf, size, "SR%s", plat->revision);
109
110 return 0;
111}
112
113static const struct soc_ops soc_ti_k3_ops = {
114 .get_family = soc_ti_k3_get_family,
115 .get_revision = soc_ti_k3_get_revision,
116};
117
118int soc_ti_k3_probe(struct udevice *dev)
119{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700120 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500121 u32 idreg;
122 void *idreg_addr;
123
124 idreg_addr = dev_read_addr_ptr(dev);
125 if (!idreg_addr)
126 return -EINVAL;
127
128 idreg = readl(idreg_addr);
129
130 plat->family = get_family_string(idreg);
131 plat->revision = get_rev_string(idreg);
132
133 return 0;
134}
135
136static const struct udevice_id soc_ti_k3_ids[] = {
137 { .compatible = "ti,am654-chipid" },
138 { }
139};
140
141U_BOOT_DRIVER(soc_ti_k3) = {
142 .name = "soc_ti_k3",
143 .id = UCLASS_SOC,
144 .ops = &soc_ti_k3_ops,
145 .of_match = soc_ti_k3_ids,
146 .probe = soc_ti_k3_probe,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700147 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500148};