ARM: mali400: r5p2_rel0: fix Makefile & Kconfig
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / sensor / sensors_core.c
1 /* /driver/sensors/core/sensors_core.c
2  * Copyright (C) 2011 Samsung Electronics. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms 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 that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/init.h>
22 #include <linux/device.h>
23 #include <linux/fs.h>
24 #include <linux/err.h>
25
26
27 struct class *sensors_class;
28 EXPORT_SYMBOL_GPL(sensors_class);
29
30
31 /**
32  * Create sysfs interface
33  */
34 static void set_sensor_attr(struct device *dev,
35         struct device_attribute *attributes[])
36 {
37         int i;
38
39         for (i = 0 ; attributes[i] != NULL ; i++) {
40                 if ((device_create_file(dev, attributes[i])) < 0)
41                         pr_err("Create_dev_file fail(attributes[%d] )\n", i);
42         }
43 }
44
45 int sensors_register(struct device *dev, void * drvdata,
46         struct device_attribute *attributes[], char *name)
47 {
48         int ret = 0;
49
50         if (!sensors_class) {
51                 sensors_class = class_create(THIS_MODULE, "sensors");
52                 if (IS_ERR(sensors_class))
53                         return PTR_ERR(sensors_class);
54         }
55
56
57         dev = device_create(sensors_class, NULL, 0, drvdata, "%s", name);
58
59         if (IS_ERR(dev)) {
60                 ret = PTR_ERR(dev);
61                 pr_err("[SENSORS CORE] device_create failed! [%d]\n", ret);
62                 return ret;
63         }
64
65         set_sensor_attr(dev, attributes);
66
67
68         return 0;
69 }
70 EXPORT_SYMBOL_GPL(sensors_register);
71
72 void sensors_unregister(struct device *dev,struct device_attribute *attributes[])
73 {
74         int i;
75  
76     if (sensors_class != NULL) {
77         for (i = 0 ; attributes[i] != NULL ; i++)
78                         device_remove_file(dev, attributes[i]);
79         }
80 }
81 EXPORT_SYMBOL_GPL(sensors_unregister);
82
83 static int __init sensors_class_init(void)
84 {
85         pr_debug("[SENSORS CORE] sensors_class_init\n");
86         sensors_class = class_create(THIS_MODULE, "sensors");
87
88         if (IS_ERR(sensors_class))
89                 return PTR_ERR(sensors_class);
90
91         sensors_class->dev_uevent = NULL;
92
93         return 0;
94 }
95
96 static void __exit sensors_class_exit(void)
97 {
98         class_destroy(sensors_class);
99 }
100
101
102 /* exported for the APM Power driver, APM emulation */
103
104 subsys_initcall(sensors_class_init);
105 module_exit(sensors_class_exit);
106
107 MODULE_DESCRIPTION("Universal sensors core class");
108 MODULE_AUTHOR("Ryunkyun Park <ryun.park@samsung.com>");
109 MODULE_LICENSE("GPL");
110