blob: 8af0ac7051925887c370a4fe590b963c5307cf2b [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
11#include <asm/io.h>
12
13#define AM65X 0xbb5a
14#define J721E 0xbb64
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053015#define J7200 0xbb6d
Lokesh Vutlac6558042021-05-06 16:44:48 +053016#define AM64X 0xbb38
David Huang26457192022-01-25 20:56:36 +053017#define J721S2 0xbb75
Suman Anna3fbd35f2022-05-25 13:38:41 +053018#define AM62X 0xbb7e
Bryan Brattlof0c3a0732022-11-03 19:13:54 -050019#define AM62AX 0xbb8d
Dave Gerlachf8f8b122020-07-15 23:39:59 -050020
Dave Gerlachf8f8b122020-07-15 23:39:59 -050021#define JTAG_ID_VARIANT_SHIFT 28
22#define JTAG_ID_VARIANT_MASK (0xf << 28)
23#define JTAG_ID_PARTNO_SHIFT 12
24#define JTAG_ID_PARTNO_MASK (0xffff << 12)
25
Simon Glassb75b15b2020-12-03 16:55:23 -070026struct soc_ti_k3_plat {
Dave Gerlachf8f8b122020-07-15 23:39:59 -050027 const char *family;
28 const char *revision;
29};
30
31static const char *get_family_string(u32 idreg)
32{
33 const char *family;
34 u32 soc;
35
36 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
37
38 switch (soc) {
39 case AM65X:
40 family = "AM65X";
41 break;
42 case J721E:
43 family = "J721E";
44 break;
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053045 case J7200:
46 family = "J7200";
47 break;
Lokesh Vutlac6558042021-05-06 16:44:48 +053048 case AM64X:
49 family = "AM64X";
50 break;
David Huang26457192022-01-25 20:56:36 +053051 case J721S2:
52 family = "J721S2";
53 break;
Suman Anna3fbd35f2022-05-25 13:38:41 +053054 case AM62X:
55 family = "AM62X";
56 break;
Bryan Brattlof0c3a0732022-11-03 19:13:54 -050057 case AM62AX:
58 family = "AM62AX";
59 break;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050060 default:
61 family = "Unknown Silicon";
62 };
63
64 return family;
65}
66
Bryan Brattlof1a798db2022-01-26 16:07:33 -060067static char *j721e_rev_string_map[] = {
68 "1.0", "1.1",
69};
70
Bryan Brattlof05722fd2022-06-21 16:36:03 -050071static char *typical_rev_string_map[] = {
72 "1.0", "2.0", "3.0",
Bryan Brattlof1a798db2022-01-26 16:07:33 -060073};
74
Dave Gerlachf8f8b122020-07-15 23:39:59 -050075static const char *get_rev_string(u32 idreg)
76{
Dave Gerlachf8f8b122020-07-15 23:39:59 -050077 u32 rev;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060078 u32 soc;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050079
80 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof1a798db2022-01-26 16:07:33 -060081 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050082
Bryan Brattlof1a798db2022-01-26 16:07:33 -060083 switch (soc) {
84 case J721E:
85 if (rev > ARRAY_SIZE(j721e_rev_string_map))
86 goto bail;
87 return j721e_rev_string_map[rev];
88
Dave Gerlachf8f8b122020-07-15 23:39:59 -050089 default:
Bryan Brattlof05722fd2022-06-21 16:36:03 -050090 if (rev > ARRAY_SIZE(typical_rev_string_map))
91 goto bail;
92 return typical_rev_string_map[rev];
Dave Gerlachf8f8b122020-07-15 23:39:59 -050093 };
94
Bryan Brattlof1a798db2022-01-26 16:07:33 -060095bail:
96 return "Unknown Revision";
Dave Gerlachf8f8b122020-07-15 23:39:59 -050097}
98
99static int soc_ti_k3_get_family(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, "%s", plat->family);
104
105 return 0;
106}
107
108static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
109{
Simon Glassb75b15b2020-12-03 16:55:23 -0700110 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500111
112 snprintf(buf, size, "SR%s", plat->revision);
113
114 return 0;
115}
116
117static const struct soc_ops soc_ti_k3_ops = {
118 .get_family = soc_ti_k3_get_family,
119 .get_revision = soc_ti_k3_get_revision,
120};
121
122int soc_ti_k3_probe(struct udevice *dev)
123{
Simon Glassb75b15b2020-12-03 16:55:23 -0700124 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500125 u32 idreg;
126 void *idreg_addr;
127
128 idreg_addr = dev_read_addr_ptr(dev);
129 if (!idreg_addr)
130 return -EINVAL;
131
132 idreg = readl(idreg_addr);
133
134 plat->family = get_family_string(idreg);
135 plat->revision = get_rev_string(idreg);
136
137 return 0;
138}
139
140static const struct udevice_id soc_ti_k3_ids[] = {
141 { .compatible = "ti,am654-chipid" },
142 { }
143};
144
145U_BOOT_DRIVER(soc_ti_k3) = {
146 .name = "soc_ti_k3",
147 .id = UCLASS_SOC,
148 .ops = &soc_ti_k3_ops,
149 .of_match = soc_ti_k3_ids,
150 .probe = soc_ti_k3_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700151 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500152};