^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2017 BayLibre, SAS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Author: Neil Armstrong <narmstrong@baylibre.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sys_soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/bitfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define AO_SEC_SD_CFG8 0xe0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define AO_SEC_SOCINFO_OFFSET AO_SEC_SD_CFG8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define SOCINFO_MAJOR GENMASK(31, 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define SOCINFO_PACK GENMASK(23, 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define SOCINFO_MINOR GENMASK(15, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SOCINFO_MISC GENMASK(7, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static const struct meson_gx_soc_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) } soc_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) { "GXBB", 0x1f },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) { "GXTVBB", 0x20 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { "GXL", 0x21 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) { "GXM", 0x22 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { "TXL", 0x23 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { "TXLX", 0x24 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { "AXG", 0x25 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { "GXLX", 0x26 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { "TXHD", 0x27 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { "G12A", 0x28 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { "G12B", 0x29 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { "SM1", 0x2b },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { "A1", 0x2c },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const struct meson_gx_package_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned int major_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int pack_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned int pack_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) } soc_packages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) { "S905D", 0x21, 0, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) { "S905X", 0x21, 0x80, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) { "S905W", 0x21, 0xa0, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { "S905L", 0x21, 0xc0, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { "S905M2", 0x21, 0xe0, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { "S805X", 0x21, 0x30, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { "S805Y", 0x21, 0xb0, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) { "962X", 0x24, 0x10, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) { "962E", 0x24, 0x20, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) { "A113X", 0x25, 0x37, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) { "A113D", 0x25, 0x22, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { "S905D2", 0x28, 0x10, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) { "S905X2", 0x28, 0x40, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) { "A311D", 0x29, 0x10, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { "S922X", 0x29, 0x40, 0xf0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) { "S905D3", 0x2b, 0x4, 0xf5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) { "S905X3", 0x2b, 0x5, 0xf5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) { "S905X3", 0x2b, 0x10, 0x3f },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) { "S905D3", 0x2b, 0x30, 0x3f },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { "A113L", 0x2c, 0x0, 0xf8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline unsigned int socinfo_to_major(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return FIELD_GET(SOCINFO_MAJOR, socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static inline unsigned int socinfo_to_minor(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return FIELD_GET(SOCINFO_MINOR, socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline unsigned int socinfo_to_pack(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return FIELD_GET(SOCINFO_PACK, socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static inline unsigned int socinfo_to_misc(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return FIELD_GET(SOCINFO_MISC, socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static const char *socinfo_to_package_id(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned int pack = socinfo_to_pack(socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int major = socinfo_to_major(socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (soc_packages[i].major_id == major &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) soc_packages[i].pack_id ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) (pack & soc_packages[i].pack_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return soc_packages[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static const char *socinfo_to_soc_id(u32 socinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned int id = socinfo_to_major(socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (soc_ids[i].id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return soc_ids[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int __init meson_gx_socinfo_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct soc_device_attribute *soc_dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct soc_device *soc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned int socinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* look up for chipid node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) np = of_find_compatible_node(NULL, NULL, "amlogic,meson-gx-ao-secure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* check if interface is enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!of_device_is_available(np)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* check if chip-id is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* node should be a syscon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) regmap = syscon_node_to_regmap(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_err("%s: failed to get regmap\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!socinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) pr_err("%s: invalid chipid value\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (!soc_dev_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) soc_dev_attr->family = "Amlogic Meson";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) np = of_find_node_by_path("/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) of_property_read_string(np, "model", &soc_dev_attr->machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x:%x - %x:%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) socinfo_to_major(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) socinfo_to_minor(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) socinfo_to_pack(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) socinfo_to_misc(socinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) socinfo_to_soc_id(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) socinfo_to_package_id(socinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) soc_dev = soc_device_register(soc_dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (IS_ERR(soc_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) kfree(soc_dev_attr->revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) kfree_const(soc_dev_attr->soc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) kfree(soc_dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return PTR_ERR(soc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) dev = soc_device_to_device(soc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_info(dev, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) soc_dev_attr->soc_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) socinfo_to_major(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) socinfo_to_minor(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) socinfo_to_pack(socinfo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) socinfo_to_misc(socinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) device_initcall(meson_gx_socinfo_init);