usb: xhci-plat: properly handle probe deferral for devm_clk_get()
[linux/fpc-iii.git] / drivers / soc / versatile / soc-realview.c
blobc337764de86766bb5384583ec1cf13342bdb2b55
1 /*
2 * Copyright (C) 2014 Linaro Ltd.
4 * Author: Linus Walleij <linus.walleij@linaro.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/slab.h>
14 #include <linux/sys_soc.h>
15 #include <linux/platform_device.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/regmap.h>
18 #include <linux/of.h>
20 /* System ID in syscon */
21 #define REALVIEW_SYS_ID_OFFSET 0x00
23 static const struct of_device_id realview_soc_of_match[] = {
24 { .compatible = "arm,realview-eb-soc", },
25 { .compatible = "arm,realview-pb1176-soc", },
26 { .compatible = "arm,realview-pb11mp-soc", },
27 { .compatible = "arm,realview-pba8-soc", },
28 { .compatible = "arm,realview-pbx-soc", },
29 { }
32 static u32 realview_coreid;
34 static const char *realview_board_str(u32 id)
36 switch ((id >> 16) & 0xfff) {
37 case 0x0147:
38 return "HBI-0147";
39 case 0x0159:
40 return "HBI-0159";
41 default:
42 return "Unknown";
46 static const char *realview_arch_str(u32 id)
48 switch ((id >> 8) & 0xf) {
49 case 0x04:
50 return "AHB";
51 case 0x05:
52 return "Multi-layer AXI";
53 default:
54 return "Unknown";
58 static ssize_t realview_get_manf(struct device *dev,
59 struct device_attribute *attr,
60 char *buf)
62 return sprintf(buf, "%02x\n", realview_coreid >> 24);
65 static struct device_attribute realview_manf_attr =
66 __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL);
68 static ssize_t realview_get_board(struct device *dev,
69 struct device_attribute *attr,
70 char *buf)
72 return sprintf(buf, "%s\n", realview_board_str(realview_coreid));
75 static struct device_attribute realview_board_attr =
76 __ATTR(board, S_IRUGO, realview_get_board, NULL);
78 static ssize_t realview_get_arch(struct device *dev,
79 struct device_attribute *attr,
80 char *buf)
82 return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
85 static struct device_attribute realview_arch_attr =
86 __ATTR(fpga, S_IRUGO, realview_get_arch, NULL);
88 static ssize_t realview_get_build(struct device *dev,
89 struct device_attribute *attr,
90 char *buf)
92 return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
95 static struct device_attribute realview_build_attr =
96 __ATTR(build, S_IRUGO, realview_get_build, NULL);
98 static int realview_soc_probe(struct platform_device *pdev)
100 static struct regmap *syscon_regmap;
101 struct soc_device *soc_dev;
102 struct soc_device_attribute *soc_dev_attr;
103 struct device_node *np = pdev->dev.of_node;
104 int ret;
106 syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
107 if (IS_ERR(syscon_regmap))
108 return PTR_ERR(syscon_regmap);
110 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
111 if (!soc_dev_attr)
112 return -ENOMEM;
114 ret = of_property_read_string(np, "compatible",
115 &soc_dev_attr->soc_id);
116 if (ret)
117 return -EINVAL;
119 soc_dev_attr->machine = "RealView";
120 soc_dev_attr->family = "Versatile";
121 soc_dev = soc_device_register(soc_dev_attr);
122 if (IS_ERR(soc_dev)) {
123 kfree(soc_dev_attr);
124 return -ENODEV;
126 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
127 &realview_coreid);
128 if (ret)
129 return -ENODEV;
131 device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr);
132 device_create_file(soc_device_to_device(soc_dev), &realview_board_attr);
133 device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr);
134 device_create_file(soc_device_to_device(soc_dev), &realview_build_attr);
136 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x\n",
137 realview_coreid);
138 /* FIXME: add attributes for SoC to sysfs */
139 return 0;
142 static struct platform_driver realview_soc_driver = {
143 .probe = realview_soc_probe,
144 .driver = {
145 .name = "realview-soc",
146 .of_match_table = realview_soc_of_match,
149 builtin_platform_driver(realview_soc_driver);