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 |
Suman Anna | 4298ee7 | 2022-05-25 13:38:41 +0530 | [diff] [blame] | 18 | #define AM62X 0xbb7e |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 19 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 20 | #define JTAG_ID_VARIANT_SHIFT 28 |
| 21 | #define JTAG_ID_VARIANT_MASK (0xf << 28) |
| 22 | #define JTAG_ID_PARTNO_SHIFT 12 |
| 23 | #define JTAG_ID_PARTNO_MASK (0xffff << 12) |
| 24 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 25 | struct soc_ti_k3_plat { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 26 | const char *family; |
| 27 | const char *revision; |
| 28 | }; |
| 29 | |
| 30 | static const char *get_family_string(u32 idreg) |
| 31 | { |
| 32 | const char *family; |
| 33 | u32 soc; |
| 34 | |
| 35 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
| 36 | |
| 37 | switch (soc) { |
| 38 | case AM65X: |
| 39 | family = "AM65X"; |
| 40 | break; |
| 41 | case J721E: |
| 42 | family = "J721E"; |
| 43 | break; |
Kishon Vijay Abraham I | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 44 | case J7200: |
| 45 | family = "J7200"; |
| 46 | break; |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 47 | case AM64X: |
| 48 | family = "AM64X"; |
| 49 | break; |
David Huang | f993adb | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 50 | case J721S2: |
| 51 | family = "J721S2"; |
| 52 | break; |
Suman Anna | 4298ee7 | 2022-05-25 13:38:41 +0530 | [diff] [blame] | 53 | case AM62X: |
| 54 | family = "AM62X"; |
| 55 | break; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 56 | default: |
| 57 | family = "Unknown Silicon"; |
| 58 | }; |
| 59 | |
| 60 | return family; |
| 61 | } |
| 62 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 63 | static char *j721e_rev_string_map[] = { |
| 64 | "1.0", "1.1", |
| 65 | }; |
| 66 | |
Bryan Brattlof | 10c8baf | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 67 | static char *typical_rev_string_map[] = { |
| 68 | "1.0", "2.0", "3.0", |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 69 | }; |
| 70 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 71 | static const char *get_rev_string(u32 idreg) |
| 72 | { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 73 | u32 rev; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 74 | u32 soc; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 75 | |
| 76 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 77 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 78 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 79 | switch (soc) { |
| 80 | case J721E: |
| 81 | if (rev > ARRAY_SIZE(j721e_rev_string_map)) |
| 82 | goto bail; |
| 83 | return j721e_rev_string_map[rev]; |
| 84 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 85 | default: |
Bryan Brattlof | 10c8baf | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 86 | if (rev > ARRAY_SIZE(typical_rev_string_map)) |
| 87 | goto bail; |
| 88 | return typical_rev_string_map[rev]; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 91 | bail: |
| 92 | return "Unknown Revision"; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 96 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 97 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 98 | |
| 99 | snprintf(buf, size, "%s", plat->family); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size) |
| 105 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 106 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 107 | |
| 108 | snprintf(buf, size, "SR%s", plat->revision); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static const struct soc_ops soc_ti_k3_ops = { |
| 114 | .get_family = soc_ti_k3_get_family, |
| 115 | .get_revision = soc_ti_k3_get_revision, |
| 116 | }; |
| 117 | |
| 118 | int soc_ti_k3_probe(struct udevice *dev) |
| 119 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 120 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 121 | u32 idreg; |
| 122 | void *idreg_addr; |
| 123 | |
| 124 | idreg_addr = dev_read_addr_ptr(dev); |
| 125 | if (!idreg_addr) |
| 126 | return -EINVAL; |
| 127 | |
| 128 | idreg = readl(idreg_addr); |
| 129 | |
| 130 | plat->family = get_family_string(idreg); |
| 131 | plat->revision = get_rev_string(idreg); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static const struct udevice_id soc_ti_k3_ids[] = { |
| 137 | { .compatible = "ti,am654-chipid" }, |
| 138 | { } |
| 139 | }; |
| 140 | |
| 141 | U_BOOT_DRIVER(soc_ti_k3) = { |
| 142 | .name = "soc_ti_k3", |
| 143 | .id = UCLASS_SOC, |
| 144 | .ops = &soc_ti_k3_ops, |
| 145 | .of_match = soc_ti_k3_ids, |
| 146 | .probe = soc_ti_k3_probe, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 147 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 148 | }; |