Dave Gerlach | 3e1b59c | 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 | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 15 | #define J7200 0xbb6d |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 16 | #define AM64X 0xbb38 |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 17 | |
| 18 | #define REV_SR1_0 0 |
| 19 | #define REV_SR2_0 1 |
| 20 | |
| 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 | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 26 | struct soc_ti_k3_plat { |
Dave Gerlach | 3e1b59c | 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 | 837933a | 2020-08-05 22:44:27 +0530 | [diff] [blame] | 45 | case J7200: |
| 46 | family = "J7200"; |
| 47 | break; |
Lokesh Vutla | 776b79e | 2021-05-06 16:44:48 +0530 | [diff] [blame] | 48 | case AM64X: |
| 49 | family = "AM64X"; |
| 50 | break; |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 51 | default: |
| 52 | family = "Unknown Silicon"; |
| 53 | }; |
| 54 | |
| 55 | return family; |
| 56 | } |
| 57 | |
| 58 | static const char *get_rev_string(u32 idreg) |
| 59 | { |
| 60 | const char *revision; |
| 61 | u32 rev; |
| 62 | |
| 63 | rev = (idreg & JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT; |
| 64 | |
| 65 | switch (rev) { |
| 66 | case REV_SR1_0: |
| 67 | revision = "1.0"; |
| 68 | break; |
| 69 | case REV_SR2_0: |
| 70 | revision = "2.0"; |
| 71 | break; |
| 72 | default: |
| 73 | revision = "Unknown Revision"; |
| 74 | }; |
| 75 | |
| 76 | return revision; |
| 77 | } |
| 78 | |
| 79 | static int soc_ti_k3_get_family(struct udevice *dev, char *buf, int size) |
| 80 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 81 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 82 | |
| 83 | snprintf(buf, size, "%s", plat->family); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int soc_ti_k3_get_revision(struct udevice *dev, char *buf, int size) |
| 89 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 90 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 91 | |
| 92 | snprintf(buf, size, "SR%s", plat->revision); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static const struct soc_ops soc_ti_k3_ops = { |
| 98 | .get_family = soc_ti_k3_get_family, |
| 99 | .get_revision = soc_ti_k3_get_revision, |
| 100 | }; |
| 101 | |
| 102 | int soc_ti_k3_probe(struct udevice *dev) |
| 103 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 104 | struct soc_ti_k3_plat *plat = dev_get_plat(dev); |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 105 | u32 idreg; |
| 106 | void *idreg_addr; |
| 107 | |
| 108 | idreg_addr = dev_read_addr_ptr(dev); |
| 109 | if (!idreg_addr) |
| 110 | return -EINVAL; |
| 111 | |
| 112 | idreg = readl(idreg_addr); |
| 113 | |
| 114 | plat->family = get_family_string(idreg); |
| 115 | plat->revision = get_rev_string(idreg); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static const struct udevice_id soc_ti_k3_ids[] = { |
| 121 | { .compatible = "ti,am654-chipid" }, |
| 122 | { } |
| 123 | }; |
| 124 | |
| 125 | U_BOOT_DRIVER(soc_ti_k3) = { |
| 126 | .name = "soc_ti_k3", |
| 127 | .id = UCLASS_SOC, |
| 128 | .ops = &soc_ti_k3_ops, |
| 129 | .of_match = soc_ti_k3_ids, |
| 130 | .probe = soc_ti_k3_probe, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 131 | .plat_auto = sizeof(struct soc_ti_k3_plat), |
Dave Gerlach | 3e1b59c | 2020-07-15 23:39:59 -0500 | [diff] [blame] | 132 | }; |