Merge tag 'fixes-rcu-fiq-signed' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / soc / versatile / soc-realview.c
CommitLineData
a2974c9c
LW
1/*
2 * Copyright (C) 2014 Linaro Ltd.
3 *
4 * Author: Linus Walleij <linus.walleij@linaro.org>
5 *
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.
9 *
10 */
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>
19
20/* System ID in syscon */
21#define REALVIEW_SYS_ID_OFFSET 0x00
22
23static 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", },
157a1b17 29 { }
a2974c9c
LW
30};
31
32static u32 realview_coreid;
33
a2974c9c
LW
34static const char *realview_arch_str(u32 id)
35{
36 switch ((id >> 8) & 0xf) {
5d87f7a3
LW
37 case 0x04:
38 return "AHB";
a2974c9c
LW
39 case 0x05:
40 return "Multi-layer AXI";
41 default:
42 return "Unknown";
43 }
44}
45
46static ssize_t realview_get_manf(struct device *dev,
47 struct device_attribute *attr,
48 char *buf)
49{
50 return sprintf(buf, "%02x\n", realview_coreid >> 24);
51}
52
53static struct device_attribute realview_manf_attr =
54 __ATTR(manufacturer, S_IRUGO, realview_get_manf, NULL);
55
56static ssize_t realview_get_board(struct device *dev,
57 struct device_attribute *attr,
58 char *buf)
59{
fccc2b36 60 return sprintf(buf, "HBI-%03x\n", ((realview_coreid >> 16) & 0xfff));
a2974c9c
LW
61}
62
63static struct device_attribute realview_board_attr =
64 __ATTR(board, S_IRUGO, realview_get_board, NULL);
65
66static ssize_t realview_get_arch(struct device *dev,
67 struct device_attribute *attr,
68 char *buf)
69{
70 return sprintf(buf, "%s\n", realview_arch_str(realview_coreid));
71}
72
73static struct device_attribute realview_arch_attr =
74 __ATTR(fpga, S_IRUGO, realview_get_arch, NULL);
75
76static ssize_t realview_get_build(struct device *dev,
77 struct device_attribute *attr,
78 char *buf)
79{
80 return sprintf(buf, "%02x\n", (realview_coreid & 0xFF));
81}
82
83static struct device_attribute realview_build_attr =
84 __ATTR(build, S_IRUGO, realview_get_build, NULL);
85
86static int realview_soc_probe(struct platform_device *pdev)
87{
88 static struct regmap *syscon_regmap;
89 struct soc_device *soc_dev;
90 struct soc_device_attribute *soc_dev_attr;
91 struct device_node *np = pdev->dev.of_node;
92 int ret;
93
94 syscon_regmap = syscon_regmap_lookup_by_phandle(np, "regmap");
95 if (IS_ERR(syscon_regmap))
96 return PTR_ERR(syscon_regmap);
97
98 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
99 if (!soc_dev_attr)
100 return -ENOMEM;
101
102 ret = of_property_read_string(np, "compatible",
103 &soc_dev_attr->soc_id);
104 if (ret)
105 return -EINVAL;
106
107 soc_dev_attr->machine = "RealView";
108 soc_dev_attr->family = "Versatile";
109 soc_dev = soc_device_register(soc_dev_attr);
110 if (IS_ERR(soc_dev)) {
111 kfree(soc_dev_attr);
112 return -ENODEV;
113 }
114 ret = regmap_read(syscon_regmap, REALVIEW_SYS_ID_OFFSET,
115 &realview_coreid);
116 if (ret)
117 return -ENODEV;
118
119 device_create_file(soc_device_to_device(soc_dev), &realview_manf_attr);
120 device_create_file(soc_device_to_device(soc_dev), &realview_board_attr);
121 device_create_file(soc_device_to_device(soc_dev), &realview_arch_attr);
122 device_create_file(soc_device_to_device(soc_dev), &realview_build_attr);
123
fccc2b36
LW
124 dev_info(&pdev->dev, "RealView Syscon Core ID: 0x%08x, HBI-%03x\n",
125 realview_coreid,
126 ((realview_coreid >> 16) & 0xfff));
a2974c9c
LW
127 /* FIXME: add attributes for SoC to sysfs */
128 return 0;
129}
130
131static struct platform_driver realview_soc_driver = {
132 .probe = realview_soc_probe,
133 .driver = {
134 .name = "realview-soc",
135 .of_match_table = realview_soc_of_match,
136 },
137};
0159ae95 138builtin_platform_driver(realview_soc_driver);
This page took 0.14606 seconds and 5 git commands to generate.