|
|
|
@ -0,0 +1,175 @@
|
|
|
|
|
/* Copyright (c) 2013, The Linux Foundation. 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 and
|
|
|
|
|
* only 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
|
#include <linux/sensors.h>
|
|
|
|
|
|
|
|
|
|
static struct class *sensors_class;
|
|
|
|
|
|
|
|
|
|
DECLARE_RWSEM(sensors_list_lock);
|
|
|
|
|
LIST_HEAD(sensors_list);
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_name_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", sensors_cdev->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_vendor_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", sensors_cdev->vendor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_version_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", sensors_cdev->version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_handle_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", sensors_cdev->handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_type_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", sensors_cdev->type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_max_range_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", sensors_cdev->max_range);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_resolution_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", sensors_cdev->resolution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_power_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", sensors_cdev->sensor_power);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_min_delay_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", sensors_cdev->min_delay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_fifo_event_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n",
|
|
|
|
|
sensors_cdev->fifo_reserved_event_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t sensors_fifo_max_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev);
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n",
|
|
|
|
|
sensors_cdev->fifo_max_event_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct device_attribute sensors_class_attrs[] = {
|
|
|
|
|
__ATTR(name, 0644, sensors_name_show, NULL),
|
|
|
|
|
__ATTR(vendor, 0644, sensors_vendor_show, NULL),
|
|
|
|
|
__ATTR(version, 0644, sensors_version_show, NULL),
|
|
|
|
|
__ATTR(handle, 0644, sensors_handle_show, NULL),
|
|
|
|
|
__ATTR(type, 0644, sensors_type_show, NULL),
|
|
|
|
|
__ATTR(max_range, 0644, sensors_max_range_show, NULL),
|
|
|
|
|
__ATTR(resolution, 0644, sensors_resolution_show, NULL),
|
|
|
|
|
__ATTR(sensor_power, 0644, sensors_power_show, NULL),
|
|
|
|
|
__ATTR(min_delay, 0644, sensors_min_delay_show, NULL),
|
|
|
|
|
__ATTR(fifo_reserved_event_count, 0644, sensors_fifo_event_show, NULL),
|
|
|
|
|
__ATTR(fifo_max_event_count, 0644, sensors_fifo_max_show, NULL),
|
|
|
|
|
__ATTR_NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sensors_classdev_register - register a new object of sensors_classdev class.
|
|
|
|
|
* @parent: The device to register.
|
|
|
|
|
* @sensors_cdev: the sensors_classdev structure for this device.
|
|
|
|
|
*/
|
|
|
|
|
int sensors_classdev_register(struct device *parent,
|
|
|
|
|
struct sensors_classdev *sensors_cdev)
|
|
|
|
|
{
|
|
|
|
|
sensors_cdev->dev = device_create(sensors_class, parent, 0,
|
|
|
|
|
sensors_cdev, "%s", sensors_cdev->name);
|
|
|
|
|
if (IS_ERR(sensors_cdev->dev))
|
|
|
|
|
return PTR_ERR(sensors_cdev->dev);
|
|
|
|
|
|
|
|
|
|
down_write(&sensors_list_lock);
|
|
|
|
|
list_add_tail(&sensors_cdev->node, &sensors_list);
|
|
|
|
|
up_write(&sensors_list_lock);
|
|
|
|
|
|
|
|
|
|
pr_debug("Registered sensors device: %s\n",
|
|
|
|
|
sensors_cdev->name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(sensors_classdev_register);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sensors_classdev_unregister - unregister a object of sensors class.
|
|
|
|
|
* @sensors_cdev: the sensor device to unregister
|
|
|
|
|
* Unregister a previously registered via sensors_classdev_register object.
|
|
|
|
|
*/
|
|
|
|
|
void sensors_classdev_unregister(struct sensors_classdev *sensors_cdev)
|
|
|
|
|
{
|
|
|
|
|
device_unregister(sensors_cdev->dev);
|
|
|
|
|
down_write(&sensors_list_lock);
|
|
|
|
|
list_del(&sensors_cdev->node);
|
|
|
|
|
up_write(&sensors_list_lock);
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(sensors_classdev_unregister);
|
|
|
|
|
|
|
|
|
|
static int __init sensors_init(void)
|
|
|
|
|
{
|
|
|
|
|
sensors_class = class_create(THIS_MODULE, "sensors");
|
|
|
|
|
if (IS_ERR(sensors_class))
|
|
|
|
|
return PTR_ERR(sensors_class);
|
|
|
|
|
sensors_class->dev_attrs = sensors_class_attrs;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void __exit sensors_exit(void)
|
|
|
|
|
{
|
|
|
|
|
class_destroy(sensors_class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subsys_initcall(sensors_init);
|
|
|
|
|
module_exit(sensors_exit);
|