2 * Copyright (C) 2015 Atmel
4 * Alexandre Belloni <alexandre.belloni@free-electrons.com
5 * Boris Brezillon <boris.brezillon@free-electrons.com
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
13 #define pr_fmt(fmt) "AT91: " fmt
17 #include <linux/of_address.h>
18 #include <linux/of_platform.h>
19 #include <linux/slab.h>
20 #include <linux/sys_soc.h>
24 #define AT91_DBGU_CIDR 0x40
25 #define AT91_DBGU_CIDR_VERSION(x) ((x) & 0x1f)
26 #define AT91_DBGU_CIDR_EXT BIT(31)
27 #define AT91_DBGU_CIDR_MATCH_MASK 0x7fffffe0
28 #define AT91_DBGU_EXID 0x44
30 struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
32 struct soc_device_attribute *soc_dev_attr;
33 const struct at91_soc *soc;
34 struct soc_device *soc_dev;
35 struct device_node *np;
39 np = of_find_compatible_node(NULL, NULL, "atmel,at91rm9200-dbgu");
41 np = of_find_compatible_node(NULL, NULL,
42 "atmel,at91sam9260-dbgu");
45 pr_warn("Could not find DBGU node");
49 regs = of_iomap(np, 0);
53 pr_warn("Could not map DBGU iomem range");
57 cidr = readl(regs + AT91_DBGU_CIDR);
58 exid = readl(regs + AT91_DBGU_EXID);
62 for (soc = socs; soc->name; soc++) {
63 if (soc->cidr_match != (cidr & AT91_DBGU_CIDR_MATCH_MASK))
66 if (!(cidr & AT91_DBGU_CIDR_EXT) || soc->exid_match == exid)
71 pr_warn("Could not find matching SoC description\n");
75 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
79 soc_dev_attr->family = soc->family;
80 soc_dev_attr->soc_id = soc->name;
81 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%X",
82 AT91_DBGU_CIDR_VERSION(cidr));
83 soc_dev = soc_device_register(soc_dev_attr);
84 if (IS_ERR(soc_dev)) {
85 kfree(soc_dev_attr->revision);
87 pr_warn("Could not register SoC device\n");
92 pr_info("Detected SoC family: %s\n", soc->family);
93 pr_info("Detected SoC: %s, revision %X\n", soc->name,
94 AT91_DBGU_CIDR_VERSION(cidr));