blob: b720131ae5df96e77a4f92a28cbe064c6592d83c [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
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;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050048 default:
49 family = "Unknown Silicon";
50 };
51
52 return family;
53}
54
Bryan Brattlof1a798db2022-01-26 16:07:33 -060055static char *j721e_rev_string_map[] = {
56 "1.0", "1.1",
57};
58
Bryan Brattlof05722fd2022-06-21 16:36:03 -050059static char *typical_rev_string_map[] = {
60 "1.0", "2.0", "3.0",
Bryan Brattlof1a798db2022-01-26 16:07:33 -060061};
62
Dave Gerlachf8f8b122020-07-15 23:39:59 -050063static const char *get_rev_string(u32 idreg)
64{
Dave Gerlachf8f8b122020-07-15 23:39:59 -050065 u32 rev;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060066 u32 soc;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050067
68 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060069 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050070
Bryan Brattlof1a798db2022-01-26 16:07:33 -060071 switch (soc) {
Andrew Davisf92ee082023-04-06 11:38:12 -050072 case JTAG_ID_PARTNO_J721E:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010073 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
Bryan Brattlof1a798db2022-01-26 16:07:33 -060074 goto bail;
75 return j721e_rev_string_map[rev];
76
Dave Gerlachf8f8b122020-07-15 23:39:59 -050077 default:
Rasmus Villemoesf5cc9232023-03-24 08:44:29 +010078 if (rev >= ARRAY_SIZE(typical_rev_string_map))
Bryan Brattlof05722fd2022-06-21 16:36:03 -050079 goto bail;
80 return typical_rev_string_map[rev];
Dave Gerlachf8f8b122020-07-15 23:39:59 -050081 };
82
Bryan Brattlof1a798db2022-01-26 16:07:33 -060083bail:
84 return "Unknown Revision";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050085}
86
87static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
88{
Simon Glassb75b15b2020-12-03 16:55:23 -070089 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-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 Glassb75b15b2020-12-03 16:55:23 -070098 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-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 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 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 Glassb75b15b2020-12-03 16:55:23 -0700139 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500140};