Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79111db1 authored by Daqing Chen's avatar Daqing Chen
Browse files

input: sensors: use 16 bits output for lis3dh driver



New Android version requires accelerometer has at least
12 bits resolution, sensor HAL is updated to process data
in 16 bits format and accelerometer drivers are also required
to output 16 bits sensor data.

Change-Id: Icdd5c1e60d3d60c1fd390108ec3a2e74705eba54
Signed-off-by: default avatarDaqing Chen <chendaqing@codeaurora.org>
Signed-off-by: default avatarBingzhe Cai <bingzhec@codeaurora.org>
parent 35b060cd
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -77,10 +77,10 @@
#define LIS3DH_FIFO_SIZE	32
#define LIS3DH_TIME_MS_TO_NS	1000000L

#define SENSITIVITY_2G		1	/**	mg/LSB	*/
#define SENSITIVITY_4G		2	/**	mg/LSB	*/
#define SENSITIVITY_8G		4	/**	mg/LSB	*/
#define SENSITIVITY_16G		12	/**	mg/LSB	*/
#define SENSITIVITY_2G		1	/**	sensitivity scale	*/
#define SENSITIVITY_4G		2	/**	sensitivity scale	*/
#define SENSITIVITY_8G		4	/**	sensitivity scale	*/
#define SENSITIVITY_16G		12	/**	sensitivity scale	*/

/* Accelerometer Sensor Operating Mode */
#define LIS3DH_ACC_ENABLE	0x01
@@ -299,7 +299,7 @@ static struct sensors_classdev lis3dh_acc_cdev = {
	.handle = SENSORS_ACCELERATION_HANDLE,
	.type = SENSOR_TYPE_ACCELEROMETER,
	.max_range = "156.8",
	.resolution = "0.01",
	.resolution = "0.000598144", /* m/s^2 */
	.sensor_power = "0.01",
	.min_delay = 10000,
	.max_delay = 6400,
@@ -1083,14 +1083,9 @@ static int lis3dh_acc_get_acceleration_data(struct lis3dh_acc_data *acc,
	if (err < 0)
		return err;

	hw_d[0] = (((s16) ((acc_data[1] << 8) | acc_data[0])) >> 4);
	hw_d[1] = (((s16) ((acc_data[3] << 8) | acc_data[2])) >> 4);
	hw_d[2] = (((s16) ((acc_data[5] << 8) | acc_data[4])) >> 4);

	hw_d[0] = hw_d[0] * acc->sensitivity;
	hw_d[1] = hw_d[1] * acc->sensitivity;
	hw_d[2] = hw_d[2] * acc->sensitivity;

	hw_d[0] = (((s16) ((acc_data[1] << 8) | acc_data[0])));
	hw_d[1] = (((s16) ((acc_data[3] << 8) | acc_data[2])));
	hw_d[2] = (((s16) ((acc_data[5] << 8) | acc_data[4])));

	xyz[0] = ((acc->pdata->negate_x) ? (-hw_d[acc->pdata->axis_map_x])
		   : (hw_d[acc->pdata->axis_map_x]));
@@ -1099,6 +1094,10 @@ static int lis3dh_acc_get_acceleration_data(struct lis3dh_acc_data *acc,
	xyz[2] = ((acc->pdata->negate_z) ? (-hw_d[acc->pdata->axis_map_z])
		   : (hw_d[acc->pdata->axis_map_z]));

	xyz[0] = xyz[0] * acc->sensitivity;
	xyz[1] = xyz[1] * acc->sensitivity;
	xyz[2] = xyz[2] * acc->sensitivity;

	dev_dbg(&acc->client->dev, "%s read x=%d, y=%d, z=%d\n",
				LIS3DH_ACC_DEV_NAME, xyz[0], xyz[1], xyz[2]);
	return err;