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