Skip to content

Commit b8e487f

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

4 files changed

Lines changed: 86 additions & 105 deletions

File tree

drivers/input/sensors/gyro/ewtsa.c

100755100644
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
338338
struct sensor_private_data *sensor =
339339
(struct sensor_private_data *) i2c_get_clientdata(client);
340340

341-
/* Report GYRO information */
342-
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
343-
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
344-
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
345-
input_sync(sensor->input_dev);
346-
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
341+
if (sensor->status_cur == SENSOR_ON) {
342+
/* Report GYRO information */
343+
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
344+
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
345+
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
346+
input_sync(sensor->input_dev);
347+
}
347348

348349
return 0;
349350
}
@@ -395,37 +396,32 @@ static int sensor_report_value(struct i2c_client *client)
395396
axis.z = z;
396397
}
397398

398-
//filter gyro data
399-
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
400-
{
401-
gyro_report_value(client, &axis);
399+
gyro_report_value(client, &axis);
402400

403-
/* »¥³âµØ»º´æÊý¾Ý. */
404-
mutex_lock(&(sensor->data_mutex) );
405-
sensor->axis = axis;
406-
mutex_unlock(&(sensor->data_mutex) );
407-
}
401+
mutex_lock(&sensor->data_mutex);
402+
sensor->axis = axis;
403+
mutex_unlock(&sensor->data_mutex);
408404

409405
return ret;
410406
}
411407

412408

413409
struct sensor_operate gyro_ewtsa_ops = {
414-
.name = "ewtsa",
415-
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
416-
.id_i2c = GYRO_ID_EWTSA, //i2c id number
417-
.read_reg = GYRO_DATA_REG, //read data
418-
.read_len = 6, //data length
419-
.id_reg = -1, //read device id from this register
420-
.id_data = -1, //device id
421-
.precision = 8, //8 bits
422-
.ctrl_reg = REG_PWR_MGM, //enable or disable
423-
.int_status_reg = REG_INT_STATUS, //intterupt status register,if no exist then -1
424-
.range = {-32768,32768}, //range
425-
.trig = IRQF_TRIGGER_HIGH|IRQF_ONESHOT,
426-
.active = sensor_active,
410+
.name = "ewtsa",
411+
.type = SENSOR_TYPE_GYROSCOPE,
412+
.id_i2c = GYRO_ID_EWTSA,
413+
.read_reg = GYRO_DATA_REG,
414+
.read_len = 6,
415+
.id_reg = -1,
416+
.id_data = -1,
417+
.precision = 16,
418+
.ctrl_reg = REG_PWR_MGM,
419+
.int_status_reg = REG_INT_STATUS,
420+
.range = {-32768, 32768},
421+
.trig = IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
422+
.active = sensor_active,
427423
.init = sensor_init,
428-
.report = sensor_report_value,
424+
.report = sensor_report_value,
429425
};
430426

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

drivers/input/sensors/gyro/l3g20d.c

100755100644
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
121121
struct sensor_private_data *sensor =
122122
(struct sensor_private_data *) i2c_get_clientdata(client);
123123

124-
/* Report GYRO information */
125-
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
126-
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
127-
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
128-
input_sync(sensor->input_dev);
129-
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
124+
if (sensor->status_cur == SENSOR_ON) {
125+
/* Report GYRO information */
126+
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
127+
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
128+
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
129+
input_sync(sensor->input_dev);
130+
}
130131

131132
return 0;
132133
}
@@ -184,16 +185,11 @@ static int sensor_report_value(struct i2c_client *client)
184185
axis.z = z;
185186
}
186187

187-
//filter gyro data
188-
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
189-
{
190-
gyro_report_value(client, &axis);
188+
gyro_report_value(client, &axis);
191189

192-
/* »¥³âµØ»º´æÊý¾Ý. */
193-
mutex_lock(&(sensor->data_mutex) );
194-
sensor->axis = axis;
195-
mutex_unlock(&(sensor->data_mutex) );
196-
}
190+
mutex_lock(&sensor->data_mutex);
191+
sensor->axis = axis;
192+
mutex_unlock(&sensor->data_mutex);
197193

198194
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
199195
{
@@ -207,21 +203,21 @@ static int sensor_report_value(struct i2c_client *client)
207203

208204

209205
static struct sensor_operate gyro_l3g20d_ops = {
210-
.name = "l3g20d",
211-
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
212-
.id_i2c = GYRO_ID_L3G20D, //i2c id number
213-
.read_reg = GYRO_DATA_REG, //read data
214-
.read_len = 6, //data length
215-
.id_reg = GYRO_WHO_AM_I, //read device id from this register
216-
.id_data = GYRO_DEVID_L3G20D, //device id
217-
.precision = 8, //8 bits
218-
.ctrl_reg = GYRO_CTRL_REG1, //enable or disable
219-
.int_status_reg = GYRO_INT_SRC, //intterupt status register,if no exist then -1
220-
.range = {-32768,32768}, //range
221-
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
222-
.active = sensor_active,
206+
.name = "l3g20d",
207+
.type = SENSOR_TYPE_GYROSCOPE,
208+
.id_i2c = GYRO_ID_L3G20D,
209+
.read_reg = GYRO_DATA_REG,
210+
.read_len = 6,
211+
.id_reg = GYRO_WHO_AM_I,
212+
.id_data = GYRO_DEVID_L3G20D,
213+
.precision = 16,
214+
.ctrl_reg = GYRO_CTRL_REG1,
215+
.int_status_reg = GYRO_INT_SRC,
216+
.range = {-32768, 32768},
217+
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
218+
.active = sensor_active,
223219
.init = sensor_init,
224-
.report = sensor_report_value,
220+
.report = sensor_report_value,
225221
};
226222

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

drivers/input/sensors/gyro/l3g4200d.c

100755100644
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ static int gyro_report_value(struct i2c_client *client, struct sensor_axis *axis
121121
struct sensor_private_data *sensor =
122122
(struct sensor_private_data *) i2c_get_clientdata(client);
123123

124-
/* Report GYRO information */
125-
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
126-
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
127-
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
128-
input_sync(sensor->input_dev);
129-
DBG("gyro x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
124+
if (sensor->status_cur == SENSOR_ON) {
125+
/* Report GYRO information */
126+
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
127+
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
128+
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
129+
input_sync(sensor->input_dev);
130+
}
130131

131132
return 0;
132133
}
@@ -184,16 +185,11 @@ static int sensor_report_value(struct i2c_client *client)
184185
axis.z = z;
185186
}
186187

187-
//filter gyro data
188-
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
189-
{
190-
gyro_report_value(client, &axis);
188+
gyro_report_value(client, &axis);
191189

192-
/* »¥³âµØ»º´æÊý¾Ý. */
193-
mutex_lock(&(sensor->data_mutex) );
194-
sensor->axis = axis;
195-
mutex_unlock(&(sensor->data_mutex) );
196-
}
190+
mutex_lock(&sensor->data_mutex);
191+
sensor->axis = axis;
192+
mutex_unlock(&sensor->data_mutex);
197193

198194
if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register
199195
{
@@ -207,21 +203,21 @@ static int sensor_report_value(struct i2c_client *client)
207203

208204

209205
struct sensor_operate gyro_l3g4200d_ops = {
210-
.name = "l3g4200d",
211-
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct
212-
.id_i2c = GYRO_ID_L3G4200D, //i2c id number
213-
.read_reg = GYRO_DATA_REG, //read data
214-
.read_len = 6, //data length
215-
.id_reg = GYRO_WHO_AM_I, //read device id from this register
216-
.id_data = GYRO_DEVID_L3G4200D, //device id
217-
.precision = 8, //8 bits
218-
.ctrl_reg = GYRO_CTRL_REG1, //enable or disable
219-
.int_status_reg = GYRO_INT_SRC, //intterupt status register,if no exist then -1
220-
.range = {-32768,32768}, //range
221-
.trig = IRQF_TRIGGER_LOW|IRQF_ONESHOT,
222-
.active = sensor_active,
206+
.name = "l3g4200d",
207+
.type = SENSOR_TYPE_GYROSCOPE,
208+
.id_i2c = GYRO_ID_L3G4200D,
209+
.read_reg = GYRO_DATA_REG,
210+
.read_len = 6,
211+
.id_reg = GYRO_WHO_AM_I,
212+
.id_data = GYRO_DEVID_L3G4200D,
213+
.precision = 16,
214+
.ctrl_reg = GYRO_CTRL_REG1,
215+
.int_status_reg = GYRO_INT_SRC,
216+
.range = {-32768, 32768},
217+
.trig = IRQF_TRIGGER_LOW | IRQF_ONESHOT,
218+
.active = sensor_active,
223219
.init = sensor_init,
224-
.report = sensor_report_value,
220+
.report = sensor_report_value,
225221
};
226222

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

drivers/input/sensors/gyro/lsm330_gyro.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ static int gyro_report_value(struct i2c_client *client,
144144
struct sensor_private_data *sensor =
145145
(struct sensor_private_data *)i2c_get_clientdata(client);
146146

147-
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
148-
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
149-
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
150-
input_sync(sensor->input_dev);
151-
DBG("gyro x==%d y==%d z==%d\n", axis->x, axis->y, axis->z);
147+
if (sensor->status_cur == SENSOR_ON) {
148+
input_report_rel(sensor->input_dev, ABS_RX, axis->x);
149+
input_report_rel(sensor->input_dev, ABS_RY, axis->y);
150+
input_report_rel(sensor->input_dev, ABS_RZ, axis->z);
151+
input_sync(sensor->input_dev);
152+
}
152153

153154
return 0;
154155
}
@@ -194,18 +195,10 @@ static int sensor_report_value(struct i2c_client *client)
194195
(pdata->orientation[7]) * y +
195196
(pdata->orientation[8]) * z;
196197

197-
axis.x = (axis.x * 872) / 1000;
198-
axis.y = (axis.y * 872) / 1000;
199-
axis.z = (axis.z * 872) / 1000;
200-
201-
if ((abs(axis.x) > pdata->x_min) ||
202-
(abs(axis.y) > pdata->y_min) ||
203-
(abs(axis.z) > pdata->z_min)) {
204-
gyro_report_value(client, &axis);
205-
mutex_lock(&sensor->data_mutex);
206-
sensor->axis = axis;
207-
mutex_unlock(&sensor->data_mutex);
208-
}
198+
gyro_report_value(client, &axis);
199+
mutex_lock(&sensor->data_mutex);
200+
sensor->axis = axis;
201+
mutex_unlock(&sensor->data_mutex);
209202

210203
if (sensor->pdata->irq_enable) {
211204
value = sensor_read_reg(client, sensor->ops->int_status_reg);
@@ -226,7 +219,7 @@ struct sensor_operate gyro_lsm330_ops = {
226219
.precision = 16,
227220
.ctrl_reg = CTRL_REG1_G,
228221
.int_status_reg = INT1_SRC_G,
229-
.range = {-0xffff, 0xffff},
222+
.range = {-32768, 32768},
230223
.trig = IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
231224
.active = sensor_active,
232225
.init = sensor_init,

0 commit comments

Comments
 (0)