blob: 965728e8185a0a2415ad9e7c9c154755c95b98d1 [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
11#include <asm/io.h>
12
13#define AM65X 0xbb5a
14#define J721E 0xbb64
Kishon Vijay Abraham I837933a2020-08-05 22:44:27 +053015#define J7200 0xbb6d
Lokesh Vutla776b79e2021-05-06 16:44:48 +053016#define AM64X 0xbb38
David Huangf993adb2022-01-25 20:56:36 +053017#define J721S2 0xbb75
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050018
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050019#define JTAG_ID_VARIANT_SHIFT 28
20#define JTAG_ID_VARIANT_MASK (0xf << 28)
21#define JTAG_ID_PARTNO_SHIFT 12
22#define JTAG_ID_PARTNO_MASK (0xffff << 12)
23
Simon Glass8a8d24b2020-12-03 16:55:23 -070024struct soc_ti_k3_plat {
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050025 const char *family;
26 const char *revision;
27};
28
29static const char *get_family_string(u32 idreg)
30{
31 const char *family;
32 u32 soc;
33
34 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
35
36 switch (soc) {
37 case AM65X:
38 family = "AM65X";
39 break;
40 case J721E:
41 family = "J721E";
42 break;
Kishon Vijay Abraham I837933a2020-08-05 22:44:27 +053043 case J7200:
44 family = "J7200";
45 break;
Lokesh Vutla776b79e2021-05-06 16:44:48 +053046 case AM64X:
47 family = "AM64X";
48 break;
David Huangf993adb2022-01-25 20:56:36 +053049 case J721S2:
50 family = "J721S2";
51 break;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050052 default:
53 family = "Unknown Silicon";
54 };
55
56 return family;
57}
58
Bryan Brattlof708f54f2022-01-26 16:07:33 -060059static char *j721e_rev_string_map[] = {
60 "1.0", "1.1",
61};
62
63static char *am65x_rev_string_map[] = {
64 "1.0", "2.0",
65};
66
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050067static const char *get_rev_string(u32 idreg)
68{
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050069 u32 rev;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060070 u32 soc;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050071
72 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
Bryan Brattlof708f54f2022-01-26 16:07:33 -060073 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050074
Bryan Brattlof708f54f2022-01-26 16:07:33 -060075 switch (soc) {
76 case J721E:
77 if (rev > ARRAY_SIZE(j721e_rev_string_map))
78 goto bail;
79 return j721e_rev_string_map[rev];
80
81 case AM65X:
82 if (rev > ARRAY_SIZE(am65x_rev_string_map))
83 goto bail;
84 return am65x_rev_string_map[rev];
85
86 case AM64X:
87 case J7200:
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050088 default:
Bryan Brattlof708f54f2022-01-26 16:07:33 -060089 if (!rev)
90 return "1.0";
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050091 };
92
Bryan Brattlof708f54f2022-01-26 16:07:33 -060093bail:
94 return "Unknown Revision";
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050095}
96
97static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
98{
Simon Glass8a8d24b2020-12-03 16:55:23 -070099 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500100
101 snprintf(buf, size, "%s", plat->family);
102
103 return 0;
104}
105
106static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
107{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700108 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500109
110 snprintf(buf, size, "SR%s", plat->revision);
111
112 return 0;
113}
114
115static const struct soc_ops soc_ti_k3_ops = {
116 .get_family = soc_ti_k3_get_family,
117 .get_revision = soc_ti_k3_get_revision,
118};
119
120int soc_ti_k3_probe(struct udevice *dev)
121{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700122 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500123 u32 idreg;
124 void *idreg_addr;
125
126 idreg_addr = dev_read_addr_ptr(dev);
127 if (!idreg_addr)
128 return -EINVAL;
129
130 idreg = readl(idreg_addr);
131
132 plat->family = get_family_string(idreg);
133 plat->revision = get_rev_string(idreg);
134
135 return 0;
136}
137
138static const struct udevice_id soc_ti_k3_ids[] = {
139 { .compatible = "ti,am654-chipid" },
140 { }
141};
142
143U_BOOT_DRIVER(soc_ti_k3) = {
144 .name = "soc_ti_k3",
145 .id = UCLASS_SOC,
146 .ops = &soc_ti_k3_ops,
147 .of_match = soc_ti_k3_ids,
148 .probe = soc_ti_k3_probe,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700149 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500150};