blob: c8f7a576877538032be672cbffe65c78b31dcbf1 [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
Dave Gerlachf8f8b122020-07-15 23:39:59 -050018
19#define REV_SR1_0 0
20#define REV_SR2_0 1
21
22#define JTAG_ID_VARIANT_SHIFT 28
23#define JTAG_ID_VARIANT_MASK (0xf << 28)
24#define JTAG_ID_PARTNO_SHIFT 12
25#define JTAG_ID_PARTNO_MASK (0xffff << 12)
26
Simon Glassb75b15b2020-12-03 16:55:23 -070027struct soc_ti_k3_plat {
Dave Gerlachf8f8b122020-07-15 23:39:59 -050028 const char *family;
29 const char *revision;
30};
31
32static const char *get_family_string(u32 idreg)
33{
34 const char *family;
35 u32 soc;
36
37 soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
38
39 switch (soc) {
40 case AM65X:
41 family = "AM65X";
42 break;
43 case J721E:
44 family = "J721E";
45 break;
Kishon Vijay Abraham I6e7f5ae2020-08-05 22:44:27 +053046 case J7200:
47 family = "J7200";
48 break;
Lokesh Vutlac6558042021-05-06 16:44:48 +053049 case AM64X:
50 family = "AM64X";
51 break;
David Huang26457192022-01-25 20:56:36 +053052 case J721S2:
53 family = "J721S2";
54 break;
Dave Gerlachf8f8b122020-07-15 23:39:59 -050055 default:
56 family = "Unknown Silicon";
57 };
58
59 return family;
60}
61
62static const char *get_rev_string(u32 idreg)
63{
64 const char *revision;
65 u32 rev;
66
67 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
68
69 switch (rev) {
70 case REV_SR1_0:
71 revision = "1.0";
72 break;
73 case REV_SR2_0:
74 revision = "2.0";
75 break;
76 default:
77 revision = "Unknown Revision";
78 };
79
80 return revision;
81}
82
83static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
84{
Simon Glassb75b15b2020-12-03 16:55:23 -070085 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -050086
87 snprintf(buf, size, "%s", plat->family);
88
89 return 0;
90}
91
92static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
93{
Simon Glassb75b15b2020-12-03 16:55:23 -070094 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -050095
96 snprintf(buf, size, "SR%s", plat->revision);
97
98 return 0;
99}
100
101static const struct soc_ops soc_ti_k3_ops = {
102 .get_family = soc_ti_k3_get_family,
103 .get_revision = soc_ti_k3_get_revision,
104};
105
106int soc_ti_k3_probe(struct udevice *dev)
107{
Simon Glassb75b15b2020-12-03 16:55:23 -0700108 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500109 u32 idreg;
110 void *idreg_addr;
111
112 idreg_addr = dev_read_addr_ptr(dev);
113 if (!idreg_addr)
114 return -EINVAL;
115
116 idreg = readl(idreg_addr);
117
118 plat->family = get_family_string(idreg);
119 plat->revision = get_rev_string(idreg);
120
121 return 0;
122}
123
124static const struct udevice_id soc_ti_k3_ids[] = {
125 { .compatible = "ti,am654-chipid" },
126 { }
127};
128
129U_BOOT_DRIVER(soc_ti_k3) = {
130 .name = "soc_ti_k3",
131 .id = UCLASS_SOC,
132 .ops = &soc_ti_k3_ops,
133 .of_match = soc_ti_k3_ids,
134 .probe = soc_ti_k3_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700135 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlachf8f8b122020-07-15 23:39:59 -0500136};