@@ -327,35 +327,28 @@ static int sensor_init(struct i2c_client *client)
327327
328328static 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
345337static 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
361354static 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
435406struct 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};
0 commit comments