Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) ST-Ericsson SA 2010
0004  *
0005  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/io.h>
0011 #include <linux/module.h>
0012 #include <linux/random.h>
0013 #include <linux/slab.h>
0014 #include <linux/of.h>
0015 #include <linux/of_address.h>
0016 #include <linux/sys_soc.h>
0017 
0018 #include <asm/cputype.h>
0019 #include <asm/tlbflush.h>
0020 #include <asm/cacheflush.h>
0021 #include <asm/mach/map.h>
0022 
0023 /**
0024  * struct dbx500_asic_id - fields of the ASIC ID
0025  * @process: the manufacturing process, 0x40 is 40 nm 0x00 is "standard"
0026  * @partnumber: hithereto 0x8500 for DB8500
0027  * @revision: version code in the series
0028  */
0029 struct dbx500_asic_id {
0030     u16 partnumber;
0031     u8  revision;
0032     u8  process;
0033 };
0034 
0035 static struct dbx500_asic_id dbx500_id;
0036 
0037 static unsigned int __init ux500_read_asicid(phys_addr_t addr)
0038 {
0039     void __iomem *virt = ioremap(addr, 4);
0040     unsigned int asicid;
0041 
0042     if (!virt)
0043         return 0;
0044 
0045     asicid = readl(virt);
0046     iounmap(virt);
0047 
0048     return asicid;
0049 }
0050 
0051 static void ux500_print_soc_info(unsigned int asicid)
0052 {
0053     unsigned int rev = dbx500_id.revision;
0054 
0055     pr_info("DB%4x ", dbx500_id.partnumber);
0056 
0057     if (rev == 0x01)
0058         pr_cont("Early Drop");
0059     else if (rev >= 0xA0)
0060         pr_cont("v%d.%d" , (rev >> 4) - 0xA + 1, rev & 0xf);
0061     else
0062         pr_cont("Unknown");
0063 
0064     pr_cont(" [%#010x]\n", asicid);
0065 }
0066 
0067 static unsigned int partnumber(unsigned int asicid)
0068 {
0069     return (asicid >> 8) & 0xffff;
0070 }
0071 
0072 /*
0073  * SOC      MIDR        ASICID ADDRESS      ASICID VALUE
0074  * DB8500ed 0x410fc090  0x9001FFF4      0x00850001
0075  * DB8500v1 0x411fc091  0x9001FFF4      0x008500A0
0076  * DB8500v1.1   0x411fc091  0x9001FFF4      0x008500A1
0077  * DB8500v2 0x412fc091  0x9001DBF4      0x008500B0
0078  * DB8520v2.2   0x412fc091  0x9001DBF4      0x008500B2
0079  * DB5500v1 0x412fc091  0x9001FFF4      0x005500A0
0080  * DB9540   0x413fc090  0xFFFFDBF4      0x009540xx
0081  */
0082 
0083 static void __init ux500_setup_id(void)
0084 {
0085     unsigned int cpuid = read_cpuid_id();
0086     unsigned int asicid = 0;
0087     phys_addr_t addr = 0;
0088 
0089     switch (cpuid) {
0090     case 0x410fc090: /* DB8500ed */
0091     case 0x411fc091: /* DB8500v1 */
0092         addr = 0x9001FFF4;
0093         break;
0094 
0095     case 0x412fc091: /* DB8520 / DB8500v2 / DB5500v1 */
0096         asicid = ux500_read_asicid(0x9001DBF4);
0097         if (partnumber(asicid) == 0x8500 ||
0098             partnumber(asicid) == 0x8520)
0099             /* DB8500v2 */
0100             break;
0101 
0102         /* DB5500v1 */
0103         addr = 0x9001FFF4;
0104         break;
0105 
0106     case 0x413fc090: /* DB9540 */
0107         addr = 0xFFFFDBF4;
0108         break;
0109     }
0110 
0111     if (addr)
0112         asicid = ux500_read_asicid(addr);
0113 
0114     if (!asicid) {
0115         pr_err("Unable to identify SoC\n");
0116         BUG();
0117     }
0118 
0119     dbx500_id.process = asicid >> 24;
0120     dbx500_id.partnumber = partnumber(asicid);
0121     dbx500_id.revision = asicid & 0xff;
0122 
0123     ux500_print_soc_info(asicid);
0124 }
0125 
0126 static const char * __init ux500_get_machine(void)
0127 {
0128     return kasprintf(GFP_KERNEL, "DB%4x", dbx500_id.partnumber);
0129 }
0130 
0131 static const char * __init ux500_get_family(void)
0132 {
0133     return kasprintf(GFP_KERNEL, "ux500");
0134 }
0135 
0136 static const char * __init ux500_get_revision(void)
0137 {
0138     unsigned int rev = dbx500_id.revision;
0139 
0140     if (rev == 0x01)
0141         return kasprintf(GFP_KERNEL, "%s", "ED");
0142     else if (rev >= 0xA0)
0143         return kasprintf(GFP_KERNEL, "%d.%d",
0144                  (rev >> 4) - 0xA + 1, rev & 0xf);
0145 
0146     return kasprintf(GFP_KERNEL, "%s", "Unknown");
0147 }
0148 
0149 static ssize_t
0150 process_show(struct device *dev, struct device_attribute *attr, char *buf)
0151 {
0152     if (dbx500_id.process == 0x00)
0153         return sprintf(buf, "Standard\n");
0154 
0155     return sprintf(buf, "%02xnm\n", dbx500_id.process);
0156 }
0157 
0158 static DEVICE_ATTR_RO(process);
0159 
0160 static struct attribute *ux500_soc_attrs[] = {
0161     &dev_attr_process.attr,
0162     NULL
0163 };
0164 
0165 ATTRIBUTE_GROUPS(ux500_soc);
0166 
0167 static const char *db8500_read_soc_id(struct device_node *backupram)
0168 {
0169     void __iomem *base;
0170     void __iomem *uid;
0171     const char *retstr;
0172 
0173     base = of_iomap(backupram, 0);
0174     if (!base)
0175         return NULL;
0176     uid = base + 0x1fc0;
0177 
0178     /* Throw these device-specific numbers into the entropy pool */
0179     add_device_randomness(uid, 0x14);
0180     retstr = kasprintf(GFP_KERNEL, "%08x%08x%08x%08x%08x",
0181              readl((u32 *)uid+0),
0182              readl((u32 *)uid+1), readl((u32 *)uid+2),
0183              readl((u32 *)uid+3), readl((u32 *)uid+4));
0184     iounmap(base);
0185     return retstr;
0186 }
0187 
0188 static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr,
0189                      struct device_node *backupram)
0190 {
0191     soc_dev_attr->soc_id   = db8500_read_soc_id(backupram);
0192     soc_dev_attr->machine  = ux500_get_machine();
0193     soc_dev_attr->family   = ux500_get_family();
0194     soc_dev_attr->revision = ux500_get_revision();
0195     soc_dev_attr->custom_attr_group = ux500_soc_groups[0];
0196 }
0197 
0198 static int __init ux500_soc_device_init(void)
0199 {
0200     struct soc_device *soc_dev;
0201     struct soc_device_attribute *soc_dev_attr;
0202     struct device_node *backupram;
0203 
0204     backupram = of_find_compatible_node(NULL, NULL, "ste,dbx500-backupram");
0205     if (!backupram)
0206         return 0;
0207 
0208     ux500_setup_id();
0209 
0210     soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
0211     if (!soc_dev_attr) {
0212         of_node_put(backupram);
0213         return -ENOMEM;
0214     }
0215 
0216     soc_info_populate(soc_dev_attr, backupram);
0217     of_node_put(backupram);
0218 
0219     soc_dev = soc_device_register(soc_dev_attr);
0220     if (IS_ERR(soc_dev)) {
0221             kfree(soc_dev_attr);
0222         return PTR_ERR(soc_dev);
0223     }
0224 
0225     return 0;
0226 }
0227 subsys_initcall(ux500_soc_device_init);