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; |
Manorit Chawdhry | 627f78c | 2025-03-17 10:24:23 +0530 | [diff] [blame] | 21 | u32 jtag_dev_id; |
| 22 | u32 pkg; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 23 | u32 soc; |
| 24 | |
Manorit Chawdhry | 627f78c | 2025-03-17 10:24:23 +0530 | [diff] [blame] | 25 | jtag_dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID); |
| 26 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 27 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
| 28 | |
| 29 | switch (soc) { |
Jayesh Choudhary | beadd86 | 2024-06-12 14:41:11 +0530 | [diff] [blame] | 30 | case JTAG_ID_PARTNO_AM62X: |
| 31 | family = "AM62X"; |
| 32 | break; |
| 33 | case JTAG_ID_PARTNO_AM62AX: |
| 34 | family = "AM62AX"; |
| 35 | break; |
| 36 | case JTAG_ID_PARTNO_AM62PX: |
| 37 | family = "AM62PX"; |
| 38 | break; |
| 39 | case JTAG_ID_PARTNO_AM64X: |
| 40 | family = "AM64X"; |
| 41 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 42 | case JTAG_ID_PARTNO_AM65X: |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 43 | family = "AM65X"; |
| 44 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 45 | case JTAG_ID_PARTNO_J7200: |
Kishon Vijay Abraham I | 6e7f5ae | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 46 | family = "J7200"; |
| 47 | break; |
Jayesh Choudhary | beadd86 | 2024-06-12 14:41:11 +0530 | [diff] [blame] | 48 | case JTAG_ID_PARTNO_J721E: |
| 49 | family = "J721E"; |
Lokesh Vutla | c655804 | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 50 | break; |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 51 | case JTAG_ID_PARTNO_J721S2: |
David Huang | 2645719 | 2022-01-25 20:56:36 +0530 | [diff] [blame] | 52 | family = "J721S2"; |
| 53 | break; |
Jayesh Choudhary | ef18f77 | 2024-06-12 14:41:12 +0530 | [diff] [blame] | 54 | case JTAG_ID_PARTNO_J722S: |
| 55 | family = "J722S"; |
| 56 | break; |
Apurva Nandan | 197dc2c | 2024-02-24 01:51:43 +0530 | [diff] [blame] | 57 | case JTAG_ID_PARTNO_J784S4: |
Manorit Chawdhry | 627f78c | 2025-03-17 10:24:23 +0530 | [diff] [blame] | 58 | { |
| 59 | /* Keep default family as J784S4 */ |
| 60 | family = "J784S4"; |
| 61 | |
| 62 | pkg = (jtag_dev_id & JTAG_DEV_J742S2_PKG_MASK) >> JTAG_DEV_J742S2_PKG_SHIFT; |
| 63 | if (pkg == JTAG_ID_PKG_J742S2) |
| 64 | family = "J742S2"; |
| 65 | |
| 66 | break; |
| 67 | } |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 68 | default: |
| 69 | family = "Unknown Silicon"; |
| 70 | }; |
| 71 | |
| 72 | return family; |
| 73 | } |
| 74 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 75 | static char *j721e_rev_string_map[] = { |
Neha Malcom Francis | 63af59d | 2024-07-15 16:45:50 +0530 | [diff] [blame] | 76 | "1.0", "1.1", "2.0", |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 77 | }; |
| 78 | |
Bryan Brattlof | 05722fd | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 79 | static char *typical_rev_string_map[] = { |
| 80 | "1.0", "2.0", "3.0", |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 81 | }; |
| 82 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 83 | static const char *get_rev_string(u32 idreg) |
| 84 | { |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 85 | u32 rev; |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 86 | u32 soc; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 87 | |
| 88 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 89 | soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 90 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 91 | switch (soc) { |
Andrew Davis | f92ee08 | 2023-04-06 11:38:12 -0500 | [diff] [blame] | 92 | case JTAG_ID_PARTNO_J721E: |
Rasmus Villemoes | f5cc923 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 93 | if (rev >= ARRAY_SIZE(j721e_rev_string_map)) |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 94 | goto bail; |
| 95 | return j721e_rev_string_map[rev]; |
| 96 | |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 97 | default: |
Rasmus Villemoes | f5cc923 | 2023-03-24 08:44:29 +0100 | [diff] [blame] | 98 | if (rev >= ARRAY_SIZE(typical_rev_string_map)) |
Bryan Brattlof | 05722fd | 2022-06-21 16:36:03 -0500 | [diff] [blame] | 99 | goto bail; |
| 100 | return typical_rev_string_map[rev]; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 101 | }; |
| 102 | |
Bryan Brattlof | 1a798db | 2022-01-26 16:07:33 -0600 | [diff] [blame] | 103 | bail: |
| 104 | return "Unknown Revision"; |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 108 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 109 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 110 | |
| 111 | snprintf(buf, size, "%s", plat->family); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size) |
| 117 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 118 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 119 | |
| 120 | snprintf(buf, size, "SR%s", plat->revision); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static const struct soc_ops soc_ti_k3_ops = { |
| 126 | .get_family = soc_ti_k3_get_family, |
| 127 | .get_revision = soc_ti_k3_get_revision, |
| 128 | }; |
| 129 | |
| 130 | int soc_ti_k3_probe(struct udevice *dev) |
| 131 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 132 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 133 | u32 idreg; |
| 134 | void *idreg_addr; |
| 135 | |
| 136 | idreg_addr = dev_read_addr_ptr(dev); |
| 137 | if (!idreg_addr) |
| 138 | return -EINVAL; |
| 139 | |
| 140 | idreg = readl(idreg_addr); |
| 141 | |
| 142 | plat->family = get_family_string(idreg); |
| 143 | plat->revision = get_rev_string(idreg); |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static const struct udevice_id soc_ti_k3_ids[] = { |
| 149 | { .compatible = "ti,am654-chipid" }, |
| 150 | { } |
| 151 | }; |
| 152 | |
| 153 | U_BOOT_DRIVER(soc_ti_k3) = { |
| 154 | .name = "soc_ti_k3", |
| 155 | .id = UCLASS_SOC, |
| 156 | .ops = &soc_ti_k3_ops, |
| 157 | .of_match = soc_ti_k3_ids, |
| 158 | .probe = soc_ti_k3_probe, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 159 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | f8f8b12 | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 160 | }; |