Ananda Kishore | 63c86b4 | 2014-12-02 11:24:19 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __LINUX_SENSORS_H_INCLUDED |
| 14 | #define __LINUX_SENSORS_H_INCLUDED |
| 15 | |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/rwsem.h> |
| 19 | |
| 20 | #define SENSORS_ACCELERATION_HANDLE 0 |
| 21 | #define SENSORS_MAGNETIC_FIELD_HANDLE 1 |
| 22 | #define SENSORS_ORIENTATION_HANDLE 2 |
| 23 | #define SENSORS_LIGHT_HANDLE 3 |
| 24 | #define SENSORS_PROXIMITY_HANDLE 4 |
| 25 | #define SENSORS_GYROSCOPE_HANDLE 5 |
| 26 | #define SENSORS_PRESSURE_HANDLE 6 |
| 27 | |
| 28 | #define SENSOR_TYPE_ACCELEROMETER 1 |
| 29 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD 2 |
| 30 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
| 31 | #define SENSOR_TYPE_ORIENTATION 3 |
| 32 | #define SENSOR_TYPE_GYROSCOPE 4 |
| 33 | #define SENSOR_TYPE_LIGHT 5 |
| 34 | #define SENSOR_TYPE_PRESSURE 6 |
| 35 | #define SENSOR_TYPE_TEMPERATURE 7 |
| 36 | #define SENSOR_TYPE_PROXIMITY 8 |
| 37 | #define SENSOR_TYPE_GRAVITY 9 |
| 38 | #define SENSOR_TYPE_LINEAR_ACCELERATION 10 |
| 39 | #define SENSOR_TYPE_ROTATION_VECTOR 11 |
| 40 | #define SENSOR_TYPE_RELATIVE_HUMIDITY 12 |
| 41 | #define SENSOR_TYPE_AMBIENT_TEMPERATURE 13 |
| 42 | #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 14 |
| 43 | #define SENSOR_TYPE_GAME_ROTATION_VECTOR 15 |
| 44 | #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 16 |
| 45 | #define SENSOR_TYPE_SIGNIFICANT_MOTION 17 |
| 46 | #define SENSOR_TYPE_STEP_DETECTOR 18 |
| 47 | #define SENSOR_TYPE_STEP_COUNTER 19 |
| 48 | #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 20 |
| 49 | |
| 50 | enum LIS3DH_AXIS { |
| 51 | AXIS_X = 0, |
| 52 | AXIS_Y, |
| 53 | AXIS_Z, |
| 54 | AXIS_XYZ, |
| 55 | }; |
| 56 | |
| 57 | enum LIS3DH_THRES { |
| 58 | AXIS_THRESHOLD_H = 0, |
| 59 | AXIS_THRESHOLD_L, |
| 60 | AXIS_BIAS, |
| 61 | }; |
| 62 | |
| 63 | #define AXIS_FACTOR 0 |
| 64 | #define AXIS_OFFSET 1 |
| 65 | |
| 66 | |
| 67 | struct cal_result_t { |
| 68 | union { |
| 69 | |
| 70 | struct { |
| 71 | int offset_x; /*axis offset of x axis*/ |
| 72 | int offset_y; /*axis offset of x axis*/ |
| 73 | int offset_z; /*axis offset of x axis*/ |
| 74 | }; |
| 75 | struct { |
| 76 | int threshold_h; /*proximity threshold_h*/ |
| 77 | int threshold_l; /*proximity threshold_l*/ |
| 78 | int bias; /*proximity measure data noise*/ |
| 79 | }; |
| 80 | int offset[3]; |
| 81 | }; |
| 82 | int factor; /*light sensor factor for real ligt strength*/ |
| 83 | int range; |
| 84 | struct cal_result_t *node; |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * struct sensors_classdev - hold the sensor general parameters and APIs |
| 89 | * @dev: The device to register. |
| 90 | * @node: The list for the all the sensor drivers. |
| 91 | * @name: Name of this sensor. |
| 92 | * @vendor: The vendor of the hardware part. |
| 93 | * @handle: The handle that identifies this sensors. |
| 94 | * @type: The sensor type. |
| 95 | * @max_range: The maximum range of this sensor's value in SI units. |
| 96 | * @resolution: The smallest difference between two values reported by |
| 97 | * this sensor. |
| 98 | * @sensor_power: The rough estimate of this sensor's power consumption |
| 99 | * in mA. |
| 100 | * @min_delay: This value depends on the trigger mode: |
| 101 | * continuous: minimum period allowed in microseconds |
| 102 | * on-change : 0 |
| 103 | * one-shot :-1 |
| 104 | * special : 0, unless otherwise noted |
| 105 | * @fifo_reserved_event_count: The number of events reserved for this sensor |
| 106 | * in the batch mode FIFO. |
| 107 | * @fifo_max_event_count: The maximum number of events of this sensor |
| 108 | * that could be batched. |
| 109 | * @max_delay: The slowest rate the sensor supports in millisecond. |
| 110 | * @flags: Should be '1' if the sensor is a wake up sensor. |
| 111 | * set it to '0' otherwise. |
| 112 | * @enabled: Store the sensor driver enable status. |
| 113 | * @delay_msec: Store the sensor driver delay value. The data unit is |
| 114 | * millisecond. |
| 115 | * @wakeup: Indicate if the wake up interrupt has been enabled. |
| 116 | * @max_latency: Max report latency in millisecond |
| 117 | * @sensors_enable: The handle for enable and disable sensor. |
| 118 | * @sensors_poll_delay: The handle for set the sensor polling delay time. |
| 119 | * @sensors_set_latency:Set the max report latency of the sensor. |
| 120 | * @sensors_flush: Flush sensor events in FIFO and report it to user space. |
| 121 | * @params The sensor calibrate string format params up to userspace. |
| 122 | * @cal_result The sensor calibrate parameters, cal_result is a struct for sensor. |
| 123 | */ |
| 124 | struct sensors_classdev { |
| 125 | struct device *dev; |
| 126 | struct list_head node; |
| 127 | const char *name; |
| 128 | const char *vendor; |
| 129 | int version; |
| 130 | int handle; |
| 131 | int type; |
| 132 | const char *max_range; |
| 133 | const char *resolution; |
| 134 | const char *sensor_power; |
| 135 | int min_delay; |
| 136 | int fifo_reserved_event_count; |
| 137 | int fifo_max_event_count; |
| 138 | int32_t max_delay; |
| 139 | uint32_t flags; |
| 140 | |
| 141 | unsigned int enabled; |
| 142 | unsigned int delay_msec; |
| 143 | unsigned int wakeup; |
| 144 | unsigned int max_latency; |
| 145 | char *params; |
| 146 | struct cal_result_t cal_result; |
| 147 | /* enable and disable the sensor handle*/ |
| 148 | int (*sensors_enable)(struct sensors_classdev *sensors_cdev, |
| 149 | unsigned int enabled); |
| 150 | int (*sensors_poll_delay)(struct sensors_classdev *sensors_cdev, |
| 151 | unsigned int delay_msec); |
| 152 | int (*sensors_self_test)(struct sensors_classdev *sensors_cdev); |
| 153 | int (*sensors_set_latency)(struct sensors_classdev *sensor_cdev, |
| 154 | unsigned int max_latency); |
| 155 | int (*sensors_enable_wakeup)(struct sensors_classdev *sensor_cdev, |
| 156 | unsigned int enable); |
| 157 | int (*sensors_flush)(struct sensors_classdev *sensors_cdev); |
| 158 | int (*sensors_calibrate)(struct sensors_classdev *sensor_cdev, |
| 159 | int axis, int apply_now); |
| 160 | int (*sensors_write_cal_params)(struct sensors_classdev |
| 161 | *sensor_cdev, struct cal_result_t *cal_result); |
| 162 | }; |
| 163 | |
| 164 | extern int sensors_classdev_register(struct device *parent, |
| 165 | struct sensors_classdev *sensors_cdev); |
| 166 | extern void sensors_classdev_unregister(struct sensors_classdev *sensors_cdev); |
| 167 | |
| 168 | #endif /* __LINUX_SENSORS_H_INCLUDED */ |