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 | |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 11 | #include <asm/arch/hardware.h> |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 14 | struct soc_ti_k3_plat { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 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) { |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 27 | case JTAG_ID_PARTNO_AM65X: |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 28 | family = "AM65X"; |
| 29 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 30 | case JTAG_ID_PARTNO_J721E: |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 31 | family = "J721E"; |
| 32 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 33 | case JTAG_ID_PARTNO_J7200: |
Kishon Vijay Abraham I | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 34 | family = "J7200"; |
| 35 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 36 | case JTAG_ID_PARTNO_AM64X: |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 37 | family = "AM64X"; |
| 38 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 39 | case JTAG_ID_PARTNO_J721S2: |
David Huang | f993adb | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 40 | family = "J721S2"; |
| 41 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 42 | case JTAG_ID_PARTNO_AM62X: |
Suman Anna | 4298ee7 | 2022-05-25 13:38:41 +0530 | [diff] [blame] | 43 | family = "AM62X"; |
| 44 | break; |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 45 | case JTAG_ID_PARTNO_AM62AX: |
Bryan Brattlof | e38025c | 2022-11-03 19:13:54 -0500 | [diff] [blame] | 46 | family = "AM62AX"; |
| 47 | break; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 48 | default: |
| 49 | family = "Unknown Silicon"; |
| 50 | }; |
| 51 | |
| 52 | return family; |
| 53 | } |
| 54 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 55 | static char *j721e_rev_string_map[] = { |
| 56 | "1.0", "1.1", |
| 57 | }; |
| 58 | |
Bryan Brattlof | 10c8baf | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 59 | static char *typical_rev_string_map[] = { |
| 60 | "1.0", "2.0", "3.0", |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 61 | }; |
| 62 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 63 | static const char *get_rev_string(u32 idreg) |
| 64 | { |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 65 | u32 rev; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 66 | u32 soc; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 67 | |
| 68 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 69 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 70 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 71 | switch (soc) { |
Andrew Davis | 677a1e2 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 72 | case JTAG_ID_PARTNO_J721E: |
Rasmus Villemoes | 45981a9 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 73 | if (rev >= ARRAY_SIZE(j721e_rev_string_map)) |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 74 | goto bail; |
| 75 | return j721e_rev_string_map[rev]; |
| 76 | |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 77 | default: |
Rasmus Villemoes | 45981a9 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 78 | if (rev >= ARRAY_SIZE(typical_rev_string_map)) |
Bryan Brattlof | 10c8baf | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 79 | goto bail; |
| 80 | return typical_rev_string_map[rev]; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 81 | }; |
| 82 | |
Bryan Brattlof | 708f54f | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 83 | bail: |
| 84 | return "Unknown Revision"; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 88 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 89 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 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 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 98 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 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 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 112 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 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, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 139 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 140 | }; |