Loading drivers/sensors/sensors_class.c +74 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,78 @@ static ssize_t sensors_fifo_max_show(struct device *dev, sensors_cdev->fifo_max_event_count); } static ssize_t sensors_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); ssize_t ret = -EINVAL; unsigned long data = 0; ret = kstrtoul(buf, 10, &data); if (ret) return ret; if (data > 1) { dev_err(dev, "Invalid value of input, input=%ld\n", data); return -EINVAL; } if (sensors_cdev->sensors_enable == NULL) { dev_err(dev, "Invalid sensor class enable handle\n"); return -EINVAL; } ret = sensors_cdev->sensors_enable(sensors_cdev, data); if (ret) return ret; sensors_cdev->enabled = data; return size; } static ssize_t sensors_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%u\n", sensors_cdev->enabled); } static ssize_t sensors_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); ssize_t ret = -EINVAL; unsigned long data = 0; ret = kstrtoul(buf, 10, &data); if (ret) return ret; /* The data unit is millisecond, the min_delay unit is microseconds. */ if ((data * 1000) < sensors_cdev->min_delay) { dev_err(dev, "Invalid value of delay, delay=%ld\n", data); return -EINVAL; } if (sensors_cdev->sensors_poll_delay == NULL) { dev_err(dev, "Invalid sensor class delay handle\n"); return -EINVAL; } ret = sensors_cdev->sensors_poll_delay(sensors_cdev, data); if (ret) return ret; sensors_cdev->delay_msec = data; return size; } static ssize_t sensors_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, "%u\n", sensors_cdev->delay_msec); } static struct device_attribute sensors_class_attrs[] = { __ATTR(name, 0444, sensors_name_show, NULL), __ATTR(vendor, 0444, sensors_vendor_show, NULL), Loading @@ -117,6 +189,8 @@ static struct device_attribute sensors_class_attrs[] = { __ATTR(min_delay, 0444, sensors_min_delay_show, NULL), __ATTR(fifo_reserved_event_count, 0444, sensors_fifo_event_show, NULL), __ATTR(fifo_max_event_count, 0444, sensors_fifo_max_show, NULL), __ATTR(enable, 0664, sensors_enable_show, sensors_enable_store), __ATTR(poll_delay, 0664, sensors_delay_show, sensors_delay_store), __ATTR_NULL, }; Loading include/linux/sensors.h +36 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,34 @@ #define SENSOR_TYPE_STEP_COUNTER 19 #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 20 /** * struct sensors_classdev - hold the sensor general parameters and APIs * @dev: The device to register. * @node: The list for the all the sensor drivers. * @name: Name of this sensor. * @vendor: The vendor of the hardware part. * @handle: The handle that identifies this sensors. * @type: The sensor type. * @max_range: The maximum range of this sensor's value in SI units. * @resolution: The smallest difference between two values reported by * this sensor. * @sensor_power: The rough estimate of this sensor's power consumption * in mA. * @min_delay: This value depends on the trigger mode: * continuous: minimum period allowed in microseconds * on-change : 0 * one-shot :-1 * special : 0, unless otherwise noted * @fifo_reserved_event_count: The number of events reserved for this sensor * in the batch mode FIFO. * @fifo_max_event_count: The maximum number of events of this sensor * that could be batched. * @enabled: Store the sensor driver enable status. * @delay_msec: Store the sensor driver delay value. The data unit is * millisecond. * @sensors_enable: The handle for enable and disable sensor. * @sensors_poll_delay: The handle for set the sensor polling delay time. */ struct sensors_classdev { struct device *dev; struct list_head node; Loading @@ -61,6 +89,13 @@ struct sensors_classdev { int min_delay; int fifo_reserved_event_count; int fifo_max_event_count; unsigned int enabled; unsigned int delay_msec; /* enable and disable the sensor handle*/ int (*sensors_enable)(struct sensors_classdev *sensors_cdev, unsigned int enabled); int (*sensors_poll_delay)(struct sensors_classdev *sensors_cdev, unsigned int delay_msec); }; extern int sensors_classdev_register(struct device *parent, Loading Loading
drivers/sensors/sensors_class.c +74 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,78 @@ static ssize_t sensors_fifo_max_show(struct device *dev, sensors_cdev->fifo_max_event_count); } static ssize_t sensors_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); ssize_t ret = -EINVAL; unsigned long data = 0; ret = kstrtoul(buf, 10, &data); if (ret) return ret; if (data > 1) { dev_err(dev, "Invalid value of input, input=%ld\n", data); return -EINVAL; } if (sensors_cdev->sensors_enable == NULL) { dev_err(dev, "Invalid sensor class enable handle\n"); return -EINVAL; } ret = sensors_cdev->sensors_enable(sensors_cdev, data); if (ret) return ret; sensors_cdev->enabled = data; return size; } static ssize_t sensors_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%u\n", sensors_cdev->enabled); } static ssize_t sensors_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sensors_classdev *sensors_cdev = dev_get_drvdata(dev); ssize_t ret = -EINVAL; unsigned long data = 0; ret = kstrtoul(buf, 10, &data); if (ret) return ret; /* The data unit is millisecond, the min_delay unit is microseconds. */ if ((data * 1000) < sensors_cdev->min_delay) { dev_err(dev, "Invalid value of delay, delay=%ld\n", data); return -EINVAL; } if (sensors_cdev->sensors_poll_delay == NULL) { dev_err(dev, "Invalid sensor class delay handle\n"); return -EINVAL; } ret = sensors_cdev->sensors_poll_delay(sensors_cdev, data); if (ret) return ret; sensors_cdev->delay_msec = data; return size; } static ssize_t sensors_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, "%u\n", sensors_cdev->delay_msec); } static struct device_attribute sensors_class_attrs[] = { __ATTR(name, 0444, sensors_name_show, NULL), __ATTR(vendor, 0444, sensors_vendor_show, NULL), Loading @@ -117,6 +189,8 @@ static struct device_attribute sensors_class_attrs[] = { __ATTR(min_delay, 0444, sensors_min_delay_show, NULL), __ATTR(fifo_reserved_event_count, 0444, sensors_fifo_event_show, NULL), __ATTR(fifo_max_event_count, 0444, sensors_fifo_max_show, NULL), __ATTR(enable, 0664, sensors_enable_show, sensors_enable_store), __ATTR(poll_delay, 0664, sensors_delay_show, sensors_delay_store), __ATTR_NULL, }; Loading
include/linux/sensors.h +36 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,34 @@ #define SENSOR_TYPE_STEP_COUNTER 19 #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 20 /** * struct sensors_classdev - hold the sensor general parameters and APIs * @dev: The device to register. * @node: The list for the all the sensor drivers. * @name: Name of this sensor. * @vendor: The vendor of the hardware part. * @handle: The handle that identifies this sensors. * @type: The sensor type. * @max_range: The maximum range of this sensor's value in SI units. * @resolution: The smallest difference between two values reported by * this sensor. * @sensor_power: The rough estimate of this sensor's power consumption * in mA. * @min_delay: This value depends on the trigger mode: * continuous: minimum period allowed in microseconds * on-change : 0 * one-shot :-1 * special : 0, unless otherwise noted * @fifo_reserved_event_count: The number of events reserved for this sensor * in the batch mode FIFO. * @fifo_max_event_count: The maximum number of events of this sensor * that could be batched. * @enabled: Store the sensor driver enable status. * @delay_msec: Store the sensor driver delay value. The data unit is * millisecond. * @sensors_enable: The handle for enable and disable sensor. * @sensors_poll_delay: The handle for set the sensor polling delay time. */ struct sensors_classdev { struct device *dev; struct list_head node; Loading @@ -61,6 +89,13 @@ struct sensors_classdev { int min_delay; int fifo_reserved_event_count; int fifo_max_event_count; unsigned int enabled; unsigned int delay_msec; /* enable and disable the sensor handle*/ int (*sensors_enable)(struct sensors_classdev *sensors_cdev, unsigned int enabled); int (*sensors_poll_delay)(struct sensors_classdev *sensors_cdev, unsigned int delay_msec); }; extern int sensors_classdev_register(struct device *parent, Loading