Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 3 | * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/ |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 4 | * Dave Gerlach <d-gerlach@ti.com> |
| 5 | */ |
| 6 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <soc.h> |
| 9 | |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 10 | #include <asm/arch/hardware.h> |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 13 | struct soc_ti_k3_plat { |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 14 | const char *family; |
| 15 | const char *revision; |
| 16 | }; |
| 17 | |
| 18 | static const char *get_family_string(u32 idreg) |
| 19 | { |
| 20 | const char *family; |
| 21 | u32 soc; |
| 22 | |
| 23 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
| 24 | |
| 25 | switch (soc) { |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 26 | case JTAG_ID_PARTNO_AM65X: |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 27 | family = "AM65X"; |
| 28 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 29 | case JTAG_ID_PARTNO_J721E: |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 30 | family = "J721E"; |
| 31 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 32 | case JTAG_ID_PARTNO_J7200: |
Kishon Vijay Abraham I | 6e7f5ae | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 33 | family = "J7200"; |
| 34 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 35 | case JTAG_ID_PARTNO_AM64X: |
Lokesh Vutla | c655804 | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 36 | family = "AM64X"; |
| 37 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 38 | case JTAG_ID_PARTNO_J721S2: |
David Huang | 2645719 | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 39 | family = "J721S2"; |
| 40 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 41 | case JTAG_ID_PARTNO_AM62X: |
Suman Anna | 3fbd35f | 2022-05-25 13:38:41 +0530 | [diff] [blame] | 42 | family = "AM62X"; |
| 43 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 44 | case JTAG_ID_PARTNO_AM62AX: |
Bryan Brattlof | 0c3a073 | 2022-11-03 19:13:54 -0500 | [diff] [blame] | 45 | family = "AM62AX"; |
| 46 | break; |
Apurva Nandan | 197dc2c | 2024-02-24 01:51:43 +0530 | [diff] [blame] | 47 | case JTAG_ID_PARTNO_J784S4: |
| 48 | family = "J784S4"; |
| 49 | break; |
Bryan Brattlof | f0f6ce1 | 2024-03-12 15:20:19 -0500 | [diff] [blame] | 50 | case JTAG_ID_PARTNO_AM62PX: |
| 51 | family = "AM62PX"; |
| 52 | break; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 53 | default: |
| 54 | family = "Unknown Silicon"; |
| 55 | }; |
| 56 | |
| 57 | return family; |
| 58 | } |
| 59 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 60 | static char *j721e_rev_string_map[] = { |
| 61 | "1.0", "1.1", |
| 62 | }; |
| 63 | |
Bryan Brattlof | 05722fd | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 64 | static char *typical_rev_string_map[] = { |
| 65 | "1.0", "2.0", "3.0", |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 68 | static const char *get_rev_string(u32 idreg) |
| 69 | { |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 70 | u32 rev; |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 71 | u32 soc; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 72 | |
| 73 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 74 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 75 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 76 | switch (soc) { |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 77 | case JTAG_ID_PARTNO_J721E: |
Rasmus Villemoes | f5cc923 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 78 | if (rev >= ARRAY_SIZE(j721e_rev_string_map)) |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 79 | goto bail; |
| 80 | return j721e_rev_string_map[rev]; |
| 81 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 82 | default: |
Rasmus Villemoes | f5cc923 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 83 | if (rev >= ARRAY_SIZE(typical_rev_string_map)) |
Bryan Brattlof | 05722fd | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 84 | goto bail; |
| 85 | return typical_rev_string_map[rev]; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 86 | }; |
| 87 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 88 | bail: |
| 89 | return "Unknown Revision"; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 93 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 94 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 95 | |
| 96 | snprintf(buf, size, "%s", plat->family); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size) |
| 102 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 103 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 104 | |
| 105 | snprintf(buf, size, "SR%s", plat->revision); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static const struct soc_ops soc_ti_k3_ops = { |
| 111 | .get_family = soc_ti_k3_get_family, |
| 112 | .get_revision = soc_ti_k3_get_revision, |
| 113 | }; |
| 114 | |
| 115 | int soc_ti_k3_probe(struct udevice *dev) |
| 116 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 117 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 118 | u32 idreg; |
| 119 | void *idreg_addr; |
| 120 | |
| 121 | idreg_addr = dev_read_addr_ptr(dev); |
| 122 | if (!idreg_addr) |
| 123 | return -EINVAL; |
| 124 | |
| 125 | idreg = readl(idreg_addr); |
| 126 | |
| 127 | plat->family = get_family_string(idreg); |
| 128 | plat->revision = get_rev_string(idreg); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static const struct udevice_id soc_ti_k3_ids[] = { |
| 134 | { .compatible = "ti,am654-chipid" }, |
| 135 | { } |
| 136 | }; |
| 137 | |
| 138 | U_BOOT_DRIVER(soc_ti_k3) = { |
| 139 | .name = "soc_ti_k3", |
| 140 | .id = UCLASS_SOC, |
| 141 | .ops = &soc_ti_k3_ops, |
| 142 | .of_match = soc_ti_k3_ids, |
| 143 | .probe = soc_ti_k3_probe, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 144 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 145 | }; |