Skip to content

Commit 4b5687d

Browse files
liuyx1314rkhuangtao
authored andcommitted
driver: input: sensor: convert gsensor data to match user level
Change-Id: I6c32eab3aad9da36609b7fb0fd24473e0e9ae22d Signed-off-by: Zorro Liu <lyx@rock-chips.com>
1 parent 2b30312 commit 4b5687d

9 files changed

Lines changed: 212 additions & 351 deletions

File tree

drivers/input/sensors/accel/bma2xx.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@
10641064

10651065
#define BAM2X2_ENABLE 0X80
10661066

1067-
#define BMA2XX_RANGE 2000000
1067+
#define BMA2XX_RANGE 32768
10681068

10691069
#define X_AXIS_COMPEN 0/*X_AXIS not compensation */
10701070
/*Y_AXIS offset is caused by screws, there needs to be compensation 3.5*/
@@ -1851,12 +1851,13 @@ static int gsensor_report_value
18511851
struct sensor_private_data *sensor =
18521852
(struct sensor_private_data *)i2c_get_clientdata(client);
18531853

1854-
/* Report acceleration sensor information */
1855-
input_report_abs(sensor->input_dev, ABS_X, axis->x);
1856-
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
1857-
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
1858-
input_sync(sensor->input_dev);
1859-
DBG("Gsensor x==%d y==%d z==%d\n", axis->x, axis->y, axis->z);
1854+
if (sensor->status_cur == SENSOR_ON) {
1855+
/* Report acceleration sensor information */
1856+
input_report_abs(sensor->input_dev, ABS_X, axis->x);
1857+
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
1858+
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
1859+
input_sync(sensor->input_dev);
1860+
}
18601861

18611862
return 0;
18621863
}

drivers/input/sensors/accel/dmard10.c

100755100644
Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -327,35 +327,28 @@ static int sensor_init(struct i2c_client *client)
327327

328328
static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)
329329
{
330-
s64 result;
330+
s64 result;
331331

332+
result = ((int)high_byte << 8) | ((int)low_byte);
332333

333-
result = ((int)high_byte << 8)|((int)low_byte);
334-
335-
if (result < DMARD10_BOUNDARY){
336-
result = result* DMARD10_GRAVITY_STEP;
337-
}else{
338-
result = ~( ((~result & (0x7fff>>(16-DMARD10_PRECISION)) ) + 1)* DMARD10_GRAVITY_STEP) + 1;
339-
}
340-
341-
return result;
342-
334+
return result * 128;
343335
}
344336

345337
static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)
346338
{
347339
struct sensor_private_data *sensor =
348340
(struct sensor_private_data *) i2c_get_clientdata(client);
349341

350-
/* Report acceleration sensor information */
351-
input_report_abs(sensor->input_dev, ABS_X, axis->x);
352-
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
353-
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
354-
input_sync(sensor->input_dev);
355-
DBG("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
356-
342+
if (sensor->status_cur == SENSOR_ON) {
343+
/* Report acceleration sensor information */
344+
input_report_abs(sensor->input_dev, ABS_X, axis->x);
345+
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
346+
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
347+
input_sync(sensor->input_dev);
348+
}
357349
return 0;
358350
}
351+
359352
#define DMARD10_COUNT_AVERAGE 2
360353
#define GSENSOR_MIN 2
361354
static int sensor_report_value(struct i2c_client *client)
@@ -393,33 +386,11 @@ static int sensor_report_value(struct i2c_client *client)
393386
axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;
394387
axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
395388

389+
gsensor_report_value(client, &axis);
396390

397-
axis_average.x_average += axis.x;
398-
axis_average.y_average += axis.y;
399-
axis_average.z_average += axis.z;
400-
axis_average.count++;
401-
402-
if(axis_average.count >= DMARD10_COUNT_AVERAGE)
403-
{
404-
axis.x = axis_average.x_average / axis_average.count;
405-
axis.y = axis_average.y_average / axis_average.count;
406-
axis.z = axis_average.z_average / axis_average.count;
407-
408-
DBG( "%s: axis = %d %d %d \n", __func__, axis.x, axis.y, axis.z);
409-
410-
memset(&axis_average, 0, sizeof(struct sensor_axis_average));
411-
412-
//Report event only while value is changed to save some power
413-
if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
414-
{
415-
gsensor_report_value(client, &axis);
416-
417-
/* »¥³âµØ»º´æÊý¾Ý. */
418-
mutex_lock(&(sensor->data_mutex) );
419-
sensor->axis = axis;
420-
mutex_unlock(&(sensor->data_mutex) );
421-
}
422-
}
391+
mutex_lock(&sensor->data_mutex);
392+
sensor->axis = axis;
393+
mutex_unlock(&sensor->data_mutex);
423394

424395
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
425396
{
@@ -433,19 +404,19 @@ static int sensor_report_value(struct i2c_client *client)
433404

434405

435406
struct sensor_operate gsensor_dmard10_ops = {
436-
.name = "gs_dmard10",
437-
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct
438-
.id_i2c = ACCEL_ID_DMARD10, //i2c id number
439-
.read_reg = DMARD10_REG_X_OUT, //read data
440-
.read_len = 8, //data length
441-
.id_reg = SENSOR_UNKNOW_DATA, //read device id from this register
442-
.id_data = SENSOR_UNKNOW_DATA, //device id
443-
.precision = DMARD10_PRECISION, //12 bit
444-
.ctrl_reg = DMARD10_REG_MODE, //enable or disable
445-
.int_status_reg = SENSOR_UNKNOW_DATA, //intterupt status register
446-
.range = {-DMARD10_RANGE,DMARD10_RANGE}, //range
447-
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
448-
.active = sensor_active,
407+
.name = "gs_dmard10",
408+
.type = SENSOR_TYPE_ACCEL,
409+
.id_i2c = ACCEL_ID_DMARD10,
410+
.read_reg = DMARD10_REG_X_OUT,
411+
.read_len = 8,
412+
.id_reg = SENSOR_UNKNOW_DATA,
413+
.id_data = SENSOR_UNKNOW_DATA,
414+
.precision = DMARD10_PRECISION,
415+
.ctrl_reg = DMARD10_REG_MODE,
416+
.int_status_reg = SENSOR_UNKNOW_DATA,
417+
.range = {-65536, 65536},
418+
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
419+
.active = sensor_active,
449420
.init = sensor_init,
450421
.report = sensor_report_value,
451422
};

drivers/input/sensors/accel/kxtik.c

100755100644
Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ static int sensor_convert_data(struct i2c_client *client, char high_byte, char l
225225
case KXTIK_DEVID_J9_1005:
226226
case KXTIK_DEVID_J2_1009:
227227
result = (((int)high_byte << 8) | ((int)low_byte ))>>4;
228-
if (result < KXTIK_BOUNDARY)
229-
result = result* KXTIK_GRAVITY_STEP;
230-
else
231-
result = ~( ((~result & (0x7fff>>(16-KXTIK_PRECISION)) ) + 1)
232-
* KXTIK_GRAVITY_STEP) + 1;
228+
result *= 16;
233229
break;
234230

235231
default:
@@ -244,12 +240,13 @@ static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *a
244240
struct sensor_private_data *sensor =
245241
(struct sensor_private_data *) i2c_get_clientdata(client);
246242

247-
/* Report acceleration sensor information */
248-
input_report_abs(sensor->input_dev, ABS_X, axis->x);
249-
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
250-
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
251-
input_sync(sensor->input_dev);
252-
DBG("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
243+
if (sensor->status_cur == SENSOR_ON) {
244+
/* Report acceleration sensor information */
245+
input_report_abs(sensor->input_dev, ABS_X, axis->x);
246+
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
247+
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
248+
input_sync(sensor->input_dev);
249+
}
253250

254251
return 0;
255252
}
@@ -291,18 +288,11 @@ static int sensor_report_value(struct i2c_client *client)
291288
axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;
292289
axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
293290

294-
DBG( "%s: axis = %d %d %d \n", __func__, axis.x, axis.y, axis.z);
295-
296-
//Report event only while value is changed to save some power
297-
if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
298-
{
299-
gsensor_report_value(client, &axis);
291+
gsensor_report_value(client, &axis);
300292

301-
/* »¥³âµØ»º´æÊý¾Ý. */
302-
mutex_lock(&(sensor->data_mutex) );
303-
sensor->axis = axis;
304-
mutex_unlock(&(sensor->data_mutex) );
305-
}
293+
mutex_lock(&sensor->data_mutex);
294+
sensor->axis = axis;
295+
mutex_unlock(&sensor->data_mutex);
306296

307297
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
308298
{
@@ -315,21 +305,21 @@ static int sensor_report_value(struct i2c_client *client)
315305
}
316306

317307
struct sensor_operate gsensor_kxtik_ops = {
318-
.name = "kxtik",
319-
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct
320-
.id_i2c = ACCEL_ID_KXTIK, //i2c id number
321-
.read_reg = KXTIK_XOUT_L, //read data
322-
.read_len = 6, //data length
323-
.id_reg = SENSOR_UNKNOW_DATA, //read device id from this register
308+
.name = "kxtik",
309+
.type = SENSOR_TYPE_ACCEL,
310+
.id_i2c = ACCEL_ID_KXTIK,
311+
.read_reg = KXTIK_XOUT_L,
312+
.read_len = 6,
313+
.id_reg = SENSOR_UNKNOW_DATA,
324314
.id_data = SENSOR_UNKNOW_DATA,
325-
.precision = KXTIK_PRECISION, //12 bits
326-
.ctrl_reg = KXTIK_CTRL_REG1, //enable or disable
327-
.int_status_reg = KXTIK_INT_REL, //intterupt status register
328-
.range = {-KXTIK_RANGE,KXTIK_RANGE}, //range
329-
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
330-
.active = sensor_active,
315+
.precision = KXTIK_PRECISION,
316+
.ctrl_reg = KXTIK_CTRL_REG1,
317+
.int_status_reg = KXTIK_INT_REL,
318+
.range = {-32768, 32768},
319+
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
320+
.active = sensor_active,
331321
.init = sensor_init,
332-
.report = sensor_report_value,
322+
.report = sensor_report_value,
333323
};
334324

335325
/****************operate according to sensor chip:end************/

drivers/input/sensors/accel/kxtj9.c

100755100644
Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ static int sensor_convert_data(struct i2c_client *client, char high_byte, char l
195195
switch (sensor->devid) {
196196
case KXTJ9_DEVID:
197197
result = (((int)high_byte << 8) | ((int)low_byte ))>>4;
198-
if (result < KXTJ9_BOUNDARY)
199-
result = result* KXTJ9_GRAVITY_STEP;
200-
else
201-
result = ~( ((~result & (0x7fff>>(16-KXTJ9_PRECISION)) ) + 1)
202-
* KXTJ9_GRAVITY_STEP) + 1;
198+
result *= 16;
203199
break;
204200

205201
default:
@@ -215,12 +211,13 @@ static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *a
215211
struct sensor_private_data *sensor =
216212
(struct sensor_private_data *) i2c_get_clientdata(client);
217213

218-
/* Report acceleration sensor information */
219-
input_report_abs(sensor->input_dev, ABS_X, axis->x);
220-
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
221-
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
222-
input_sync(sensor->input_dev);
223-
DBG("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
214+
if (sensor->status_cur == SENSOR_ON) {
215+
/* Report acceleration sensor information */
216+
input_report_abs(sensor->input_dev, ABS_X, axis->x);
217+
input_report_abs(sensor->input_dev, ABS_Y, axis->y);
218+
input_report_abs(sensor->input_dev, ABS_Z, axis->z);
219+
input_sync(sensor->input_dev);
220+
}
224221

225222
return 0;
226223
}
@@ -264,16 +261,11 @@ static int sensor_report_value(struct i2c_client *client)
264261

265262
DBG( "%s: axis = %d %d %d \n", __func__, axis.x, axis.y, axis.z);
266263

267-
//Report event only while value is changed to save some power
268-
if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
269-
{
270-
gsensor_report_value(client, &axis);
264+
gsensor_report_value(client, &axis);
271265

272-
/* »¥³âµØ»º´æÊý¾Ý. */
273-
mutex_lock(&(sensor->data_mutex) );
274-
sensor->axis = axis;
275-
mutex_unlock(&(sensor->data_mutex) );
276-
}
266+
mutex_lock(&sensor->data_mutex);
267+
sensor->axis = axis;
268+
mutex_unlock(&sensor->data_mutex);
277269

278270
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
279271
{
@@ -286,21 +278,21 @@ static int sensor_report_value(struct i2c_client *client)
286278
}
287279

288280
struct sensor_operate gsensor_kxtj9_ops = {
289-
.name = "kxtj9",
290-
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct
291-
.id_i2c = ACCEL_ID_KXTJ9, //i2c id number
292-
.read_reg = KXTJ9_XOUT_L, //read data
293-
.read_len = 6, //data length
294-
.id_reg = KXTJ9_WHO_AM_I, //read device id from this register
295-
.id_data = KXTJ9_DEVID, //device id
296-
.precision = KXTJ9_PRECISION, //12 bits
297-
.ctrl_reg = KXTJ9_CTRL_REG1, //enable or disable
298-
.int_status_reg = KXTJ9_INT_REL, //intterupt status register
299-
.range = {-KXTJ9_RANGE,KXTJ9_RANGE}, //range
300-
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
301-
.active = sensor_active,
281+
.name = "kxtj9",
282+
.type = SENSOR_TYPE_ACCEL,
283+
.id_i2c = ACCEL_ID_KXTJ9,
284+
.read_reg = KXTJ9_XOUT_L,
285+
.read_len = 6,
286+
.id_reg = KXTJ9_WHO_AM_I,
287+
.id_data = KXTJ9_DEVID,
288+
.precision = KXTJ9_PRECISION,
289+
.ctrl_reg = KXTJ9_CTRL_REG1,
290+
.int_status_reg = KXTJ9_INT_REL,
291+
.range = {-32768, 32768},
292+
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
293+
.active = sensor_active,
302294
.init = sensor_init,
303-
.report = sensor_report_value,
295+
.report = sensor_report_value,
304296
};
305297

306298
/****************operate according to sensor chip:end************/

0 commit comments

Comments
 (0)