Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 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/io.h> |
| 12 | |
| 13 | #define AM65X 0xbb5a |
| 14 | #define J721E 0xbb64 |
Kishon Vijay Abraham I | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 15 | #define J7200 0xbb6d |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 16 | #define AM64X 0xbb38 |
David Huang | f993adb | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 17 | #define J721S2 0xbb75 |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 18 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 19 | #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 Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 24 | struct soc_ti_k3_plat { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 25 | const char *family; |
| 26 | const char *revision; |
| 27 | }; |
| 28 | |
| 29 | static 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 I | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 43 | case J7200: |
| 44 | family = "J7200"; |
| 45 | break; |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 46 | case AM64X: |
| 47 | family = "AM64X"; |
| 48 | break; |
David Huang | f993adb | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 49 | case J721S2: |
| 50 | family = "J721S2"; |
| 51 | break; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 52 | default: |
| 53 | family = "Unknown Silicon"; |
| 54 | }; |
| 55 | |
| 56 | return family; |
| 57 | } |
| 58 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 59 | static char *j721e_rev_string_map[] = { |
| 60 | "1.0", "1.1", |
| 61 | }; |
| 62 | |
| 63 | static char *am65x_rev_string_map[] = { |
| 64 | "1.0", "2.0", |
| 65 | }; |
| 66 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 67 | static const char *get_rev_string(u32 idreg) |
| 68 | { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 69 | u32 rev; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 70 | u32 soc; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 71 | |
| 72 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 73 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 74 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 75 | 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 Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 88 | default: |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 89 | if (!rev) |
| 90 | return "1.0"; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 91 | }; |
| 92 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 93 | bail: |
| 94 | return "Unknown Revision"; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 98 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 99 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 100 | |
| 101 | snprintf(buf, size, "%s", plat->family); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size) |
| 107 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 108 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 109 | |
| 110 | snprintf(buf, size, "SR%s", plat->revision); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static 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 | |
| 120 | int soc_ti_k3_probe(struct udevice *dev) |
| 121 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 122 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 123 | 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 | |
| 138 | static const struct udevice_id soc_ti_k3_ids[] = { |
| 139 | { .compatible = "ti,am654-chipid" }, |
| 140 | { } |
| 141 | }; |
| 142 | |
| 143 | U_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 Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 149 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 150 | }; |