Skip to content

Commit bfb10c5

Browse files
Ley Foon TanDinh Nguyen
authored andcommitted
FogBugz #143478: drivers/misc: Move sysid from arch to drivers
Add sysid driver. 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 f068398 commit bfb10c5

File tree

4 files changed

+164
-6
lines changed

4 files changed

+164
-6
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,6 @@ config SRAM
517517
the genalloc API. It is supposed to be used for small on-chip SRAM
518518
areas found on many SoCs.
519519

520-
config ALTERA_HWMUTEX
521-
tristate "Altera Hardware Mutex"
522-
help
523-
This option enables device driver support for Altera Hardware Mutex.
524-
Say Y here if you want to use the Altera hardware mutex support.
525-
526520
config VEXPRESS_SYSCFG
527521
bool "Versatile Express System Configuration driver"
528522
depends on VEXPRESS_CONFIG
@@ -810,6 +804,17 @@ config PANEL_BOOT_MESSAGE
810804
An empty message will only clear the display at driver init time. Any other
811805
printf()-formatted message is valid with newline and escape codes.
812806

807+
config ALTERA_HWMUTEX
808+
tristate "Altera Hardware Mutex"
809+
help
810+
This option enables device driver support for Altera Hardware Mutex.
811+
Say Y here if you want to use the Altera hardware mutex support.
812+
813+
config ALTERA_SYSID
814+
tristate "Altera System ID"
815+
help
816+
This enables Altera System ID soft core driver.
817+
813818
source "drivers/misc/c2port/Kconfig"
814819
source "drivers/misc/eeprom/Kconfig"
815820
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ obj-y += lis3lv02d/
4848
obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
4949
obj-$(CONFIG_ALTERA_STAPL) += altera-stapl/
5050
obj-$(CONFIG_ALTERA_HWMUTEX) += altera_hwmutex.o
51+
obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o
5152
obj-$(CONFIG_INTEL_MEI) += mei/
5253
obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
5354
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+
time_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_request_and_ioremap(&pdev->dev, regs);
92+
if (!sysid->regs)
93+
return -ENOMEM;
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+
.remove = altera_sysid_remove,
122+
};
123+
124+
static int __init altera_sysid_init(void)
125+
{
126+
return platform_driver_probe(&altera_sysid_platform_driver,
127+
altera_sysid_probe);
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)