ARM: ux500: call ux500_setup_id later
[deliverable/linux.git] / arch / arm / mach-ux500 / id.c
index 1e81e990044b527a003682b1f2fe7e76bd5a7113..983004d0fef20bc6f419e96358410f7015cada0b 100644 (file)
@@ -8,6 +8,9 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/random.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
 
 #include <asm/cputype.h>
 #include <asm/tlbflush.h>
 #include "setup.h"
 
 #include "db8500-regs.h"
-#include "id.h"
 
-struct dbx500_asic_id dbx500_id;
+/**
+ * struct dbx500_asic_id - fields of the ASIC ID
+ * @process: the manufacturing process, 0x40 is 40 nm 0x00 is "standard"
+ * @partnumber: hithereto 0x8500 for DB8500
+ * @revision: version code in the series
+ */
+struct dbx500_asic_id {
+       u16     partnumber;
+       u8      revision;
+       u8      process;
+};
+
+static struct dbx500_asic_id dbx500_id;
 
 static unsigned int __init ux500_read_asicid(phys_addr_t addr)
 {
-       phys_addr_t base = addr & ~0xfff;
-       struct map_desc desc = {
-               .virtual        = (unsigned long)UX500_VIRT_ROM,
-               .pfn            = __phys_to_pfn(base),
-               .length         = SZ_16K,
-               .type           = MT_DEVICE,
-       };
+       void __iomem *virt = ioremap(addr, 4);
+       unsigned int asicid;
 
-       iotable_init(&desc, 1);
+       if (!virt)
+               return 0;
 
-       /* As in devicemaps_init() */
-       local_flush_tlb_all();
-       flush_cache_all();
+       asicid = readl(virt);
+       iounmap(virt);
 
-       return readl(UX500_VIRT_ROM + (addr & 0xfff));
+       return asicid;
 }
 
 static void ux500_print_soc_info(unsigned int asicid)
 {
-       unsigned int rev = dbx500_revision();
+       unsigned int rev = dbx500_id.revision;
 
-       pr_info("DB%4x ", dbx500_partnumber());
+       pr_info("DB%4x ", dbx500_id.partnumber);
 
        if (rev == 0x01)
                pr_cont("Early Drop");
@@ -72,7 +81,7 @@ static unsigned int partnumber(unsigned int asicid)
  * DB9540      0x413fc090      0xFFFFDBF4              0x009540xx
  */
 
-void __init ux500_setup_id(void)
+static void __init ux500_setup_id(void)
 {
        unsigned int cpuid = read_cpuid_id();
        unsigned int asicid = 0;
@@ -105,7 +114,7 @@ void __init ux500_setup_id(void)
 
        if (!asicid) {
                pr_err("Unable to identify SoC\n");
-               ux500_unknown_soc();
+               BUG();
        }
 
        dbx500_id.process = asicid >> 24;
@@ -114,3 +123,91 @@ void __init ux500_setup_id(void)
 
        ux500_print_soc_info(asicid);
 }
+
+static const char * __init ux500_get_machine(void)
+{
+       return kasprintf(GFP_KERNEL, "DB%4x", dbx500_id.partnumber);
+}
+
+static const char * __init ux500_get_family(void)
+{
+       return kasprintf(GFP_KERNEL, "ux500");
+}
+
+static const char * __init ux500_get_revision(void)
+{
+       unsigned int rev = dbx500_id.revision;
+
+       if (rev == 0x01)
+               return kasprintf(GFP_KERNEL, "%s", "ED");
+       else if (rev >= 0xA0)
+               return kasprintf(GFP_KERNEL, "%d.%d",
+                                (rev >> 4) - 0xA + 1, rev & 0xf);
+
+       return kasprintf(GFP_KERNEL, "%s", "Unknown");
+}
+
+static ssize_t ux500_get_process(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       if (dbx500_id.process == 0x00)
+               return sprintf(buf, "Standard\n");
+
+       return sprintf(buf, "%02xnm\n", dbx500_id.process);
+}
+
+static const char *db8500_read_soc_id(void)
+{
+       void __iomem *uid;
+       const char *retstr;
+
+       uid = ioremap(U8500_BB_UID_BASE, 0x20);
+       if (!uid)
+               return NULL;
+       /* Throw these device-specific numbers into the entropy pool */
+       add_device_randomness(uid, 0x14);
+       retstr = kasprintf(GFP_KERNEL, "%08x%08x%08x%08x%08x",
+                        readl((u32 *)uid+0),
+                        readl((u32 *)uid+1), readl((u32 *)uid+2),
+                        readl((u32 *)uid+3), readl((u32 *)uid+4));
+       iounmap(uid);
+       return retstr;
+}
+
+static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
+{
+       soc_dev_attr->soc_id   = db8500_read_soc_id();
+       soc_dev_attr->machine  = ux500_get_machine();
+       soc_dev_attr->family   = ux500_get_family();
+       soc_dev_attr->revision = ux500_get_revision();
+}
+
+static const struct device_attribute ux500_soc_attr =
+       __ATTR(process,  S_IRUGO, ux500_get_process,  NULL);
+
+struct device * __init ux500_soc_device_init(void)
+{
+       struct device *parent;
+       struct soc_device *soc_dev;
+       struct soc_device_attribute *soc_dev_attr;
+
+       ux500_setup_id();
+
+       soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+       if (!soc_dev_attr)
+               return ERR_PTR(-ENOMEM);
+
+       soc_info_populate(soc_dev_attr);
+
+       soc_dev = soc_device_register(soc_dev_attr);
+       if (IS_ERR(soc_dev)) {
+               kfree(soc_dev_attr);
+               return NULL;
+       }
+
+       parent = soc_device_to_device(soc_dev);
+       device_create_file(parent, &ux500_soc_attr);
+
+       return parent;
+}
This page took 0.027235 seconds and 5 git commands to generate.