summaryrefslogtreecommitdiff
path: root/schulung_tools/drivers/modules/hellodriver/patch-add-sysfs.diff
blob: 3e792fb8fbe6248ce08985fc1ddab7e617a53b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--- a/hello.c	2016-06-08 20:21:26.751180497 +0200
+++ b/hello.c	2016-06-08 20:19:31.655178050 +0200
@@ -76,6 +76,30 @@ static const struct file_operations hello_fops = {
 	.write = hello_write,
 };
 
+static ssize_t major_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", MAJOR(hello_devt));
+}
+static DEVICE_ATTR_RO(major);
+
+static ssize_t minor_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct hello_dev *hello = platform_get_drvdata(pdev);
+
+	return sprintf(buf, "%d\n", hello->minor);
+}
+static DEVICE_ATTR_RO(minor);
+
+static struct attribute *hello_device_attrs[] = {
+        &dev_attr_major.attr,
+        &dev_attr_minor.attr,
+        NULL,
+};
+ATTRIBUTE_GROUPS(hello_device);
+
 static int hello_probe(struct platform_device *pdev)
 {
 	struct hello_dev *hello;
@@ -186,6 +210,8 @@ static int __init hello_init(void)
 		goto err_out1;
 	}
 
+	hello_class->dev_groups = hello_device_groups;
+
 	ret = platform_driver_register(&hello_driver);
 	if (ret != 0)
 		goto err_out2;