video: ivybridge: Use mtrr_set_next_var() for graphics memory
[platform/kernel/u-boot.git] / drivers / soc / soc_ti_k3.c
1 // 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/arch/hardware.h>
12 #include <asm/io.h>
13
14 struct soc_ti_k3_plat {
15         const char *family;
16         const char *revision;
17 };
18
19 static 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) {
27         case JTAG_ID_PARTNO_AM65X:
28                 family = "AM65X";
29                 break;
30         case JTAG_ID_PARTNO_J721E:
31                 family = "J721E";
32                 break;
33         case JTAG_ID_PARTNO_J7200:
34                 family = "J7200";
35                 break;
36         case JTAG_ID_PARTNO_AM64X:
37                 family = "AM64X";
38                 break;
39         case JTAG_ID_PARTNO_J721S2:
40                 family = "J721S2";
41                 break;
42         case JTAG_ID_PARTNO_AM62X:
43                 family = "AM62X";
44                 break;
45         case JTAG_ID_PARTNO_AM62AX:
46                 family = "AM62AX";
47                 break;
48         default:
49                 family = "Unknown Silicon";
50         };
51
52         return family;
53 }
54
55 static char *j721e_rev_string_map[] = {
56         "1.0", "1.1",
57 };
58
59 static char *typical_rev_string_map[] = {
60         "1.0", "2.0", "3.0",
61 };
62
63 static const char *get_rev_string(u32 idreg)
64 {
65         u32 rev;
66         u32 soc;
67
68         rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
69         soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
70
71         switch (soc) {
72         case JTAG_ID_PARTNO_J721E:
73                 if (rev >= ARRAY_SIZE(j721e_rev_string_map))
74                         goto bail;
75                 return j721e_rev_string_map[rev];
76
77         default:
78                 if (rev >= ARRAY_SIZE(typical_rev_string_map))
79                         goto bail;
80                 return typical_rev_string_map[rev];
81         };
82
83 bail:
84         return "Unknown Revision";
85 }
86
87 static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size)
88 {
89         struct soc_ti_k3_plat *plat = dev_get_plat(dev);
90
91         snprintf(buf, size, "%s", plat->family);
92
93         return 0;
94 }
95
96 static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size)
97 {
98         struct soc_ti_k3_plat *plat = dev_get_plat(dev);
99
100         snprintf(buf, size, "SR%s", plat->revision);
101
102         return 0;
103 }
104
105 static 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
110 int soc_ti_k3_probe(struct udevice *dev)
111 {
112         struct soc_ti_k3_plat *plat = dev_get_plat(dev);
113         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
128 static const struct udevice_id soc_ti_k3_ids[] = {
129         { .compatible = "ti,am654-chipid" },
130         { }
131 };
132
133 U_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,
139         .plat_auto      = sizeof(struct soc_ti_k3_plat),
140 };