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