blob: 9abed7d490a2ca23b984c6c8775d09c730797852 [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
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050017
18#define REV_SR1_0 0
19#define REV_SR2_0 1
20
21#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 Glass8a8d24b2020-12-03 16:55:23 -070026struct soc_ti_k3_plat {
Dave Gerlach3e1b59c2020-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 I837933a2020-08-05 22:44:27 +053045 case J7200:
46 family = "J7200";
47 break;
Lokesh Vutla776b79e2021-05-06 16:44:48 +053048 case AM64X:
49 family = "AM64X";
50 break;
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050051 default:
52 family = "Unknown Silicon";
53 };
54
55 return family;
56}
57
58static const char *get_rev_string(u32 idreg)
59{
60 const char *revision;
61 u32 rev;
62
63 rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
64
65 switch (rev) {
66 case REV_SR1_0:
67 revision = "1.0";
68 break;
69 case REV_SR2_0:
70 revision = "2.0";
71 break;
72 default:
73 revision = "Unknown Revision";
74 };
75
76 return revision;
77}
78
79static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
80{
Simon Glass8a8d24b2020-12-03 16:55:23 -070081 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050082
83 snprintf(buf, size, "%s", plat->family);
84
85 return 0;
86}
87
88static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
89{
Simon Glass8a8d24b2020-12-03 16:55:23 -070090 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -050091
92 snprintf(buf, size, "SR%s", plat->revision);
93
94 return 0;
95}
96
97static const struct soc_ops soc_ti_k3_ops = {
98 .get_family = soc_ti_k3_get_family,
99 .get_revision = soc_ti_k3_get_revision,
100};
101
102int soc_ti_k3_probe(struct udevice *dev)
103{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700104 struct soc_ti_k3_plat *plat = dev_get_plat(dev);
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500105 u32 idreg;
106 void *idreg_addr;
107
108 idreg_addr = dev_read_addr_ptr(dev);
109 if (!idreg_addr)
110 return -EINVAL;
111
112 idreg = readl(idreg_addr);
113
114 plat->family = get_family_string(idreg);
115 plat->revision = get_rev_string(idreg);
116
117 return 0;
118}
119
120static const struct udevice_id soc_ti_k3_ids[] = {
121 { .compatible = "ti,am654-chipid" },
122 { }
123};
124
125U_BOOT_DRIVER(soc_ti_k3) = {
126 .name = "soc_ti_k3",
127 .id = UCLASS_SOC,
128 .ops = &soc_ti_k3_ops,
129 .of_match = soc_ti_k3_ids,
130 .probe = soc_ti_k3_probe,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700131 .plat_auto = sizeof(struct soc_ti_k3_plat),
Dave Gerlach3e1b59c2020-07-15 23:39:59 -0500132};