Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2017 BayLibre, SAS
0003  * Author: Neil Armstrong <narmstrong@baylibre.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0+
0006  */
0007 
0008 #include <linux/io.h>
0009 #include <linux/of.h>
0010 #include <linux/of_address.h>
0011 #include <linux/of_platform.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/slab.h>
0014 #include <linux/sys_soc.h>
0015 #include <linux/bitfield.h>
0016 #include <linux/regmap.h>
0017 #include <linux/mfd/syscon.h>
0018 
0019 #define AO_SEC_SD_CFG8      0xe0
0020 #define AO_SEC_SOCINFO_OFFSET   AO_SEC_SD_CFG8
0021 
0022 #define SOCINFO_MAJOR   GENMASK(31, 24)
0023 #define SOCINFO_PACK    GENMASK(23, 16)
0024 #define SOCINFO_MINOR   GENMASK(15, 8)
0025 #define SOCINFO_MISC    GENMASK(7, 0)
0026 
0027 static const struct meson_gx_soc_id {
0028     const char *name;
0029     unsigned int id;
0030 } soc_ids[] = {
0031     { "GXBB", 0x1f },
0032     { "GXTVBB", 0x20 },
0033     { "GXL", 0x21 },
0034     { "GXM", 0x22 },
0035     { "TXL", 0x23 },
0036     { "TXLX", 0x24 },
0037     { "AXG", 0x25 },
0038     { "GXLX", 0x26 },
0039     { "TXHD", 0x27 },
0040     { "G12A", 0x28 },
0041     { "G12B", 0x29 },
0042     { "SM1", 0x2b },
0043     { "A1", 0x2c },
0044 };
0045 
0046 static const struct meson_gx_package_id {
0047     const char *name;
0048     unsigned int major_id;
0049     unsigned int pack_id;
0050     unsigned int pack_mask;
0051 } soc_packages[] = {
0052     { "S905", 0x1f, 0, 0x20 }, /* pack_id != 0x20 */
0053     { "S905H", 0x1f, 0x3, 0xf }, /* pack_id & 0xf == 0x3 */
0054     { "S905M", 0x1f, 0x20, 0xf0 }, /* pack_id == 0x20 */
0055     { "S905D", 0x21, 0, 0xf0 },
0056     { "S905X", 0x21, 0x80, 0xf0 },
0057     { "S905W", 0x21, 0xa0, 0xf0 },
0058     { "S905L", 0x21, 0xc0, 0xf0 },
0059     { "S905M2", 0x21, 0xe0, 0xf0 },
0060     { "S805X", 0x21, 0x30, 0xf0 },
0061     { "S805Y", 0x21, 0xb0, 0xf0 },
0062     { "S912", 0x22, 0, 0x0 }, /* Only S912 is known for GXM */
0063     { "962X", 0x24, 0x10, 0xf0 },
0064     { "962E", 0x24, 0x20, 0xf0 },
0065     { "A113X", 0x25, 0x37, 0xff },
0066     { "A113D", 0x25, 0x22, 0xff },
0067     { "S905D2", 0x28, 0x10, 0xf0 },
0068     { "S905Y2", 0x28, 0x30, 0xf0 },
0069     { "S905X2", 0x28, 0x40, 0xf0 },
0070     { "A311D", 0x29, 0x10, 0xf0 },
0071     { "S922X", 0x29, 0x40, 0xf0 },
0072     { "S905D3", 0x2b, 0x4, 0xf5 },
0073     { "S905X3", 0x2b, 0x5, 0xf5 },
0074     { "S905X3", 0x2b, 0x10, 0x3f },
0075     { "S905D3", 0x2b, 0x30, 0x3f },
0076     { "A113L", 0x2c, 0x0, 0xf8 },
0077 };
0078 
0079 static inline unsigned int socinfo_to_major(u32 socinfo)
0080 {
0081     return FIELD_GET(SOCINFO_MAJOR, socinfo);
0082 }
0083 
0084 static inline unsigned int socinfo_to_minor(u32 socinfo)
0085 {
0086     return FIELD_GET(SOCINFO_MINOR, socinfo);
0087 }
0088 
0089 static inline unsigned int socinfo_to_pack(u32 socinfo)
0090 {
0091     return FIELD_GET(SOCINFO_PACK, socinfo);
0092 }
0093 
0094 static inline unsigned int socinfo_to_misc(u32 socinfo)
0095 {
0096     return FIELD_GET(SOCINFO_MISC, socinfo);
0097 }
0098 
0099 static const char *socinfo_to_package_id(u32 socinfo)
0100 {
0101     unsigned int pack = socinfo_to_pack(socinfo);
0102     unsigned int major = socinfo_to_major(socinfo);
0103     int i;
0104 
0105     for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) {
0106         if (soc_packages[i].major_id == major &&
0107             soc_packages[i].pack_id ==
0108                 (pack & soc_packages[i].pack_mask))
0109             return soc_packages[i].name;
0110     }
0111 
0112     return "Unknown";
0113 }
0114 
0115 static const char *socinfo_to_soc_id(u32 socinfo)
0116 {
0117     unsigned int id = socinfo_to_major(socinfo);
0118     int i;
0119 
0120     for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) {
0121         if (soc_ids[i].id == id)
0122             return soc_ids[i].name;
0123     }
0124 
0125     return "Unknown";
0126 }
0127 
0128 static int __init meson_gx_socinfo_init(void)
0129 {
0130     struct soc_device_attribute *soc_dev_attr;
0131     struct soc_device *soc_dev;
0132     struct device_node *np;
0133     struct regmap *regmap;
0134     unsigned int socinfo;
0135     struct device *dev;
0136     int ret;
0137 
0138     /* look up for chipid node */
0139     np = of_find_compatible_node(NULL, NULL, "amlogic,meson-gx-ao-secure");
0140     if (!np)
0141         return -ENODEV;
0142 
0143     /* check if interface is enabled */
0144     if (!of_device_is_available(np)) {
0145         of_node_put(np);
0146         return -ENODEV;
0147     }
0148 
0149     /* check if chip-id is available */
0150     if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
0151         of_node_put(np);
0152         return -ENODEV;
0153     }
0154 
0155     /* node should be a syscon */
0156     regmap = syscon_node_to_regmap(np);
0157     of_node_put(np);
0158     if (IS_ERR(regmap)) {
0159         pr_err("%s: failed to get regmap\n", __func__);
0160         return -ENODEV;
0161     }
0162 
0163     ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo);
0164     if (ret < 0)
0165         return ret;
0166 
0167     if (!socinfo) {
0168         pr_err("%s: invalid chipid value\n", __func__);
0169         return -EINVAL;
0170     }
0171 
0172     soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
0173     if (!soc_dev_attr)
0174         return -ENODEV;
0175 
0176     soc_dev_attr->family = "Amlogic Meson";
0177 
0178     np = of_find_node_by_path("/");
0179     of_property_read_string(np, "model", &soc_dev_attr->machine);
0180     of_node_put(np);
0181 
0182     soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x:%x - %x:%x",
0183                        socinfo_to_major(socinfo),
0184                        socinfo_to_minor(socinfo),
0185                        socinfo_to_pack(socinfo),
0186                        socinfo_to_misc(socinfo));
0187     soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s (%s)",
0188                      socinfo_to_soc_id(socinfo),
0189                      socinfo_to_package_id(socinfo));
0190 
0191     soc_dev = soc_device_register(soc_dev_attr);
0192     if (IS_ERR(soc_dev)) {
0193         kfree(soc_dev_attr->revision);
0194         kfree_const(soc_dev_attr->soc_id);
0195         kfree(soc_dev_attr);
0196         return PTR_ERR(soc_dev);
0197     }
0198     dev = soc_device_to_device(soc_dev);
0199 
0200     dev_info(dev, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected\n",
0201             soc_dev_attr->soc_id,
0202             socinfo_to_major(socinfo),
0203             socinfo_to_minor(socinfo),
0204             socinfo_to_pack(socinfo),
0205             socinfo_to_misc(socinfo));
0206 
0207     return 0;
0208 }
0209 device_initcall(meson_gx_socinfo_init);