blob: b720131ae5df96e77a4f92a28cbe064c6592d83c [file] [log] [blame]
Dave Gerlach3e1b59c2020-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
Andrew Davis677a1e22023-04-06 11:38:12 -050011#include <asm/arch/hardware.h>
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050012#include <asm/io.h>
13
Simon Glass8a8d24b2020-12-03 16:55:23 -070014struct soc_ti_k3_plat {
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050015 const char *family;
16 const char *revision;
17};
18
19static const char *get_family_string(u32 idreg)
20{
21 const char *family;
22 u32 soc;
23
24 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
25
26 switch (soc) {
Andrew Davis677a1e22023-04-06 11:38:12 -050027 case JTAG_ID_PARTNO_AM65X:
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050028 family = "AM65X";
29 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050030 case JTAG_ID_PARTNO_J721E:
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050031 family = "J721E";
32 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050033 case JTAG_ID_PARTNO_J7200:
Kishon Vijay Abraham I837933a2020-08-05 22:44:27 +053034 family = "J7200";
35 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050036 case JTAG_ID_PARTNO_AM64X:
Lokesh Vutla776b79e2021-05-06 16:44:48 +053037 family = "AM64X";
38 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050039 case JTAG_ID_PARTNO_J721S2:
David Huangf993adb2022-01-25 20:56:36 +053040 family = "J721S2";
41 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050042 case JTAG_ID_PARTNO_AM62X:
Suman Anna4298ee72022-05-25 13:38:41 +053043 family = "AM62X";
44 break;
Andrew Davis677a1e22023-04-06 11:38:12 -050045 case JTAG_ID_PARTNO_AM62AX:
Bryan Brattlofe38025c2022-11-03 19:13:54 -050046 family = "AM62AX";
47 break;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050048 default:
49 family = "Unknown Silicon";
50 };
51
52 return family;
53}
54
Bryan Brattlof708f54f2022-01-26 16:07:33 -060055static char *j721e_rev_string_map[] = {
56 "1.0", "1.1",
57};
58
Bryan Brattlof10c8baf2022-06-21 16:36:03 -050059static char *typical_rev_string_map[] = {
60 "1.0", "2.0", "3.0",
Bryan Brattlof708f54f2022-01-26 16:07:33 -060061};
62
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050063static const char *get_rev_string(u32 idreg)
64{
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050065 u32 rev;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060066 u32 soc;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050067
68 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060069 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050070
Bryan Brattlof708f54f2022-01-26 16:07:33 -060071 switch (soc) {
Andrew Davis677a1e22023-04-06 11:38:12 -050072 case JTAG_ID_PARTNO_J721E:
Rasmus Villemoes45981a92023-03-24 08:44:29 +010073 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
Bryan Brattlof708f54f2022-01-26 16:07:33 -060074 goto bail;
75 return j721e_rev_string_map[rev];
76
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050077 default:
Rasmus Villemoes45981a92023-03-24 08:44:29 +010078 if (rev >= ARRAY_SIZE(typical_rev_string_map))
Bryan Brattlof10c8baf2022-06-21 16:36:03 -050079 goto bail;
80 return typical_rev_string_map[rev];
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050081 };
82
Bryan Brattlof708f54f2022-01-26 16:07:33 -060083bail:
84 return "Unknown Revision";
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050085}
86
87static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
88{
Simon Glass8a8d24b2020-12-03 16:55:23 -070089 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050090
91 snprintf(buf, size, "%s", plat->family);
92
93 return 0;
94}
95
96static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
97{
Simon Glass8a8d24b2020-12-03 16:55:23 -070098 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050099
100 snprintf(buf, size, "SR%s", plat->revision);
101
102 return 0;
103}
104
105static const struct soc_ops soc_ti_k3_ops = {
106 .get_family = soc_ti_k3_get_family,
107 .get_revision = soc_ti_k3_get_revision,
108};
109
110int soc_ti_k3_probe(struct udevice *dev)
111{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700112 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500113 u32 idreg;
114 void *idreg_addr;
115
116 idreg_addr = dev_read_addr_ptr(dev);
117 if (!idreg_addr)
118 return -EINVAL;
119
120 idreg = readl(idreg_addr);
121
122 plat->family = get_family_string(idreg);
123 plat->revision = get_rev_string(idreg);
124
125 return 0;
126}
127
128static const struct udevice_id soc_ti_k3_ids[] = {
129 { .compatible = "ti,am654-chipid" },
130 { }
131};
132
133U_BOOT_DRIVER(soc_ti_k3) = {
134 .name = "soc_ti_k3",
135 .id = UCLASS_SOC,
136 .ops = &soc_ti_k3_ops,
137 .of_match = soc_ti_k3_ids,
138 .probe = soc_ti_k3_probe,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700139 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500140};