diff options
| author | Yuval Adam <_@yuv.al> | 2017-08-30 08:25:59 +0000 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2017-08-30 08:25:59 +0000 |
| commit | 8e4bff4cab0ddac6060645b0715210484d02ff40 (patch) | |
| tree | 3a5c3024371a04692a3a6d9974d001cdff8ebf84 /drivers/sensor/sensors_core.c | |
Diffstat (limited to 'drivers/sensor/sensors_core.c')
| -rw-r--r-- | drivers/sensor/sensors_core.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/drivers/sensor/sensors_core.c b/drivers/sensor/sensors_core.c new file mode 100644 index 00000000..5a192f95 --- /dev/null +++ b/drivers/sensor/sensors_core.c @@ -0,0 +1,110 @@ +/* /driver/sensors/core/sensors_core.c + * Copyright (C) 2011 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 + */ + +#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 *sensors_class; +EXPORT_SYMBOL_GPL(sensors_class); + + +/** + * Create sysfs interface + */ +static void set_sensor_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("Create_dev_file fail(attributes[%d] )\n", i); + } +} + +int sensors_register(struct device *dev, void * drvdata, + struct device_attribute *attributes[], char *name) +{ + int ret = 0; + + if (!sensors_class) { + sensors_class = class_create(THIS_MODULE, "sensors"); + if (IS_ERR(sensors_class)) + return PTR_ERR(sensors_class); + } + + + dev = device_create(sensors_class, NULL, 0, drvdata, "%s", name); + + if (IS_ERR(dev)) { + ret = PTR_ERR(dev); + pr_err("[SENSORS CORE] device_create failed! [%d]\n", ret); + return ret; + } + + set_sensor_attr(dev, attributes); + + + return 0; +} +EXPORT_SYMBOL_GPL(sensors_register); + +void sensors_unregister(struct device *dev,struct device_attribute *attributes[]) +{ + int i; + + if (sensors_class != NULL) { + for (i = 0 ; attributes[i] != NULL ; i++) + device_remove_file(dev, attributes[i]); + } +} +EXPORT_SYMBOL_GPL(sensors_unregister); + +static int __init sensors_class_init(void) +{ + pr_debug("[SENSORS CORE] sensors_class_init\n"); + sensors_class = class_create(THIS_MODULE, "sensors"); + + if (IS_ERR(sensors_class)) + return PTR_ERR(sensors_class); + + sensors_class->dev_uevent = NULL; + + return 0; +} + +static void __exit sensors_class_exit(void) +{ + class_destroy(sensors_class); +} + + +/* exported for the APM Power driver, APM emulation */ + +subsys_initcall(sensors_class_init); +module_exit(sensors_class_exit); + +MODULE_DESCRIPTION("Universal sensors core class"); +MODULE_AUTHOR("Ryunkyun Park <ryun.park@samsung.com>"); +MODULE_LICENSE("GPL"); + |
