Skip to content

Commit afe38ce

Browse files
Ley Foon Tandinguyen702
authored andcommitted
FogBugz #143478: drivers/misc: Add sysid from arch to drivers
Add sysid driver. The Altera Sysid component is generally part of an FPGA design. The component can be hotplugged when the FPGA is reconfigured. This patch fixes the driver to support the component being hotplugged. Usage: cat /sys/bus/platform/devices/[addr.sysid]/sysid/id cat /sys/bus/platform/devices/[addr.sysid]/sysid/timestamp v2: - Updated license header - Removed ID and timestamp from documentation v3: - Removed ID and timestamp from optional properties in documentation Signed-off-by: Ley Foon Tan <[email protected]>
1 parent f22d5d1 commit afe38ce

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Altera Sysid IP core driver
2+
3+
Required properties:
4+
- compatible: altr,sysid-1.0
5+
6+
Example:
7+
8+
sysid_qsys: sysid@0x10000 {
9+
compatible = "altr,sysid-1.0";
10+
reg = < 0x10000 0x00000008 >;
11+
};

drivers/misc/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ config PVPANIC
472472
a paravirtualized device provided by QEMU; it lets a virtual machine
473473
(guest) communicate panic events to the host.
474474

475+
config ALTERA_SYSID
476+
tristate "Altera System ID"
477+
help
478+
This enables Altera System ID soft core driver.
479+
475480
source "drivers/misc/c2port/Kconfig"
476481
source "drivers/misc/eeprom/Kconfig"
477482
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ obj-y += ti-st/
4242
obj-y += lis3lv02d/
4343
obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
4444
obj-$(CONFIG_ALTERA_HWMUTEX) += altera_hwmutex.o
45+
obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o
4546
obj-$(CONFIG_INTEL_MEI) += mei/
4647
obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
4748
obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o

drivers/misc/altera_sysid.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright Altera Corporation (C) 2013.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
* Credit:
17+
* Walter Goossens
18+
*/
19+
20+
#include <linux/kernel.h>
21+
#include <linux/module.h>
22+
#include <linux/device.h>
23+
#include <linux/platform_device.h>
24+
#include <linux/slab.h>
25+
#include <linux/io.h>
26+
#include <linux/of.h>
27+
28+
#define DRV_NAME "altera_sysid"
29+
30+
struct altera_sysid {
31+
void __iomem *regs;
32+
};
33+
34+
/* System ID Registers*/
35+
#define SYSID_REG_ID (0x0)
36+
#define SYSID_REG_TIMESTAMP (0x4)
37+
38+
static ssize_t altera_sysid_show_id(struct device *dev,
39+
struct device_attribute *attr, char *buf)
40+
{
41+
struct altera_sysid *sysid = dev_get_drvdata(dev);
42+
43+
return sprintf(buf, "%u\n", readl(sysid->regs + SYSID_REG_ID));
44+
}
45+
46+
static ssize_t altera_sysid_show_timestamp(struct device *dev,
47+
struct device_attribute *attr, char *buf)
48+
{
49+
unsigned int reg;
50+
struct tm timestamp;
51+
struct altera_sysid *sysid = dev_get_drvdata(dev);
52+
53+
reg = readl(sysid->regs + SYSID_REG_TIMESTAMP);
54+
55+
time64_to_tm(reg, 0, &timestamp);
56+
57+
return sprintf(buf, "%u (%u-%u-%u %u:%u:%u UTC)\n", reg,
58+
(unsigned int)(timestamp.tm_year + 1900),
59+
timestamp.tm_mon + 1, timestamp.tm_mday, timestamp.tm_hour,
60+
timestamp.tm_min, timestamp.tm_sec);
61+
}
62+
63+
static DEVICE_ATTR(id, S_IRUGO, altera_sysid_show_id, NULL);
64+
static DEVICE_ATTR(timestamp, S_IRUGO, altera_sysid_show_timestamp, NULL);
65+
66+
static struct attribute *altera_sysid_attrs[] = {
67+
&dev_attr_id.attr,
68+
&dev_attr_timestamp.attr,
69+
NULL,
70+
};
71+
72+
struct attribute_group altera_sysid_attr_group = {
73+
.name = "sysid",
74+
.attrs = altera_sysid_attrs,
75+
};
76+
77+
static int altera_sysid_probe(struct platform_device *pdev)
78+
{
79+
struct altera_sysid *sysid;
80+
struct resource *regs;
81+
82+
sysid = devm_kzalloc(&pdev->dev, sizeof(struct altera_sysid),
83+
GFP_KERNEL);
84+
if (!sysid)
85+
return -ENOMEM;
86+
87+
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88+
if (!regs)
89+
return -ENXIO;
90+
91+
sysid->regs = devm_ioremap_resource(&pdev->dev, regs);
92+
if (IS_ERR(sysid->regs))
93+
return PTR_ERR(sysid->regs);
94+
95+
platform_set_drvdata(pdev, sysid);
96+
97+
return sysfs_create_group(&pdev->dev.kobj, &altera_sysid_attr_group);
98+
}
99+
100+
static int altera_sysid_remove(struct platform_device *pdev)
101+
{
102+
sysfs_remove_group(&pdev->dev.kobj, &altera_sysid_attr_group);
103+
104+
platform_set_drvdata(pdev, NULL);
105+
return 0;
106+
}
107+
108+
static const struct of_device_id altera_sysid_match[] = {
109+
{ .compatible = "altr,sysid-1.0" },
110+
{ /* Sentinel */ }
111+
};
112+
113+
MODULE_DEVICE_TABLE(of, altera_sysid_match);
114+
115+
static struct platform_driver altera_sysid_platform_driver = {
116+
.driver = {
117+
.name = DRV_NAME,
118+
.owner = THIS_MODULE,
119+
.of_match_table = of_match_ptr(altera_sysid_match),
120+
},
121+
.probe = altera_sysid_probe,
122+
.remove = altera_sysid_remove,
123+
};
124+
125+
static int __init altera_sysid_init(void)
126+
{
127+
return platform_driver_register(&altera_sysid_platform_driver);
128+
}
129+
130+
static void __exit altera_sysid_exit(void)
131+
{
132+
platform_driver_unregister(&altera_sysid_platform_driver);
133+
}
134+
135+
module_init(altera_sysid_init);
136+
module_exit(altera_sysid_exit);
137+
138+
MODULE_AUTHOR("Ley Foon Tan <[email protected]>");
139+
MODULE_LICENSE("GPL v2");
140+
MODULE_DESCRIPTION("Altera System ID driver");
141+
MODULE_ALIAS("platform:" DRV_NAME);

0 commit comments

Comments
 (0)