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