blob: d176980915605d19be0090246ebcb538e42de98c [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
7#include <common.h>
8#include <dm.h>
9#include <soc.h>
10
Andrew Davisf92ee082023-04-06 11:38:12 -050011#include <asm/arch/hardware.h>
Dave Gerlachf8f8b122020-07-15 23:39:59 -050012#include <asm/io.h>
13
Simon Glassb75b15b2020-12-03 16:55:23 -070014struct soc_ti_k3_plat {
Dave Gerlachf8f8b122020-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 Davisf92ee082023-04-06 11:38:12 -050027 case JTAG_ID_PARTNO_AM65X:
Dave Gerlachf8f8b122020-07-15 23:39:59 -050028 family = "AM65X";
29 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050030 case JTAG_ID_PARTNO_J721E:
Dave Gerlachf8f8b122020-07-15 23:39:59 -050031 family = "J721E";
32 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050033 case JTAG_ID_PARTNO_J7200:
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053034 family = "J7200";
35 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050036 case JTAG_ID_PARTNO_AM64X:
Lokesh Vutlac6558042021-05-06 16:44:48 +053037 family = "AM64X";
38 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050039 case JTAG_ID_PARTNO_J721S2:
David Huang26457192022-01-25 20:56:36 +053040 family = "J721S2";
41 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050042 case JTAG_ID_PARTNO_AM62X:
Suman Anna3fbd35f2022-05-25 13:38:41 +053043 family = "AM62X";
44 break;
Andrew Davisf92ee082023-04-06 11:38:12 -050045 case JTAG_ID_PARTNO_AM62AX:
Bryan Brattlof0c3a0732022-11-03 19:13:54 -050046 family = "AM62AX";
47 break;
Apurva Nandan197dc2c2024-02-24 01:51:43 +053048 case JTAG_ID_PARTNO_J784S4:
49 family = "J784S4";
50 break;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050051 default:
52 family = "Unknown Silicon";
53 };
54
55 return family;
56}
57
Bryan Brattlof1a798db2022-01-26 16:07:33 -060058static char *j721e_rev_string_map[] = {
59 "1.0", "1.1",
60};
61
Bryan Brattlof05722fd2022-06-21 16:36:03 -050062static char *typical_rev_string_map[] = {
63 "1.0", "2.0", "3.0",
Bryan Brattlof1a798db2022-01-26 16:07:33 -060064};
65
Dave Gerlachf8f8b122020-07-15 23:39:59 -050066static const char *get_rev_string(u32 idreg)
67{
Dave Gerlachf8f8b122020-07-15 23:39:59 -050068 u32 rev;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060069 u32 soc;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050070
71 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060072 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050073
Bryan Brattlof1a798db2022-01-26 16:07:33 -060074 switch (soc) {
Andrew Davisf92ee082023-04-06 11:38:12 -050075 case JTAG_ID_PARTNO_J721E:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010076 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
Bryan Brattlof1a798db2022-01-26 16:07:33 -060077 goto bail;
78 return j721e_rev_string_map[rev];
79
Dave Gerlachf8f8b122020-07-15 23:39:59 -050080 default:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010081 if (rev >= ARRAY_SIZE(typical_rev_string_map))
Bryan Brattlof05722fd2022-06-21 16:36:03 -050082 goto bail;
83 return typical_rev_string_map[rev];
Dave Gerlachf8f8b122020-07-15 23:39:59 -050084 };
85
Bryan Brattlof1a798db2022-01-26 16:07:33 -060086bail:
87 return "Unknown Revision";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050088}
89
90static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
91{
Simon Glassb75b15b2020-12-03 16:55:23 -070092 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -050093
94 snprintf(buf, size, "%s", plat->family);
95
96 return 0;
97}
98
99static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
100{
Simon Glassb75b15b2020-12-03 16:55:23 -0700101 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500102
103 snprintf(buf, size, "SR%s", plat->revision);
104
105 return 0;
106}
107
108static const struct soc_ops soc_ti_k3_ops = {
109 .get_family = soc_ti_k3_get_family,
110 .get_revision = soc_ti_k3_get_revision,
111};
112
113int soc_ti_k3_probe(struct udevice *dev)
114{
Simon Glassb75b15b2020-12-03 16:55:23 -0700115 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500116 u32 idreg;
117 void *idreg_addr;
118
119 idreg_addr = dev_read_addr_ptr(dev);
120 if (!idreg_addr)
121 return -EINVAL;
122
123 idreg = readl(idreg_addr);
124
125 plat->family = get_family_string(idreg);
126 plat->revision = get_rev_string(idreg);
127
128 return 0;
129}
130
131static const struct udevice_id soc_ti_k3_ids[] = {
132 { .compatible = "ti,am654-chipid" },
133 { }
134};
135
136U_BOOT_DRIVER(soc_ti_k3) = {
137 .name = "soc_ti_k3",
138 .id = UCLASS_SOC,
139 .ops = &soc_ti_k3_ops,
140 .of_match = soc_ti_k3_ids,
141 .probe = soc_ti_k3_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700142 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500143};