summaryrefstree
path: root/kernel/drivers/fingerprint/fingerprint_sysfs.c
blob: 25cc693166762fd99b4ac39418b6035245621558 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

 /*
 *  fingerprint sysfs class
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/err.h>

struct class *fingerprint_class;
EXPORT_SYMBOL_GPL(fingerprint_class);

/*
 * Create sysfs interface
 */
static void set_fingerprint_attr(struct device *dev,
	struct device_attribute *attributes[])
{
	int i;

	for (i = 0; attributes[i] != NULL; i++)
		if ((device_create_file(dev, attributes[i])) < 0)
			pr_err("%s: fail device_create_file"\
				"(dev, attributes[%d])\n", __func__, i);
}

int fingerprint_register(struct device *dev, void *drvdata,
	struct device_attribute *attributes[], char *name)
{
	int ret = 0;

	if (!fingerprint_class) {
		fingerprint_class = class_create(THIS_MODULE, "fingerprint");
		if (IS_ERR(fingerprint_class))
			return PTR_ERR(fingerprint_class);
	}

	dev = device_create(fingerprint_class, NULL, 0, drvdata, "%s", name);

	if (IS_ERR(dev)) {
		ret = PTR_ERR(dev);
		pr_err("%s: device_create failed!"\
			"[%d]\n", __func__, ret);
		return ret;
	}

	set_fingerprint_attr(dev, attributes);

	return 0;
}
EXPORT_SYMBOL_GPL(fingerprint_register);

void fingerprint_unregister(struct device *dev,
	struct device_attribute *attributes[])
{
	int i;

	for (i = 0; attributes[i] != NULL; i++)
		device_remove_file(dev, attributes[i]);
}
EXPORT_SYMBOL_GPL(fingerprint_unregister);

void destroy_fingerprint_class(void)
{
	if (fingerprint_class) {
		class_destroy(fingerprint_class);
		fingerprint_class = NULL;
	}
}
EXPORT_SYMBOL_GPL(destroy_fingerprint_class);

static int __init fingerprint_class_init(void)
{
	pr_info("%s\n", __func__);
	fingerprint_class = class_create(THIS_MODULE, "fingerprint");

	if (IS_ERR(fingerprint_class)) {
		pr_err("%s, create fingerprint_class is failed.(err=%ld)\n",
			__func__, IS_ERR(fingerprint_class));
		return PTR_ERR(fingerprint_class);
	}

	fingerprint_class->dev_uevent = NULL;

	return 0;
}

static void __exit fingerprint_class_exit(void)
{
	if (fingerprint_class) {
		class_destroy(fingerprint_class);
		fingerprint_class = NULL;
	}
}

subsys_initcall(fingerprint_class_init);
module_exit(fingerprint_class_exit);

MODULE_DESCRIPTION("fingerprint sysfs class");
MODULE_LICENSE("GPL");