Kernel->sensor:fix mc3230 set layout no effect issue
This commit is contained in:
123
kernel/drivers/input/sensors/accel/mc3230.c
Executable file → Normal file
123
kernel/drivers/input/sensors/accel/mc3230.c
Executable file → Normal file
@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
#define MITECH_SENSOR_DBG
|
||||
|
||||
static int sensor_active(struct i2c_client *client, int enable, int rate);
|
||||
//#define MITECH_SENSOR_DBG(x...) printk(x);
|
||||
#define MC32X0_XOUT_REG 0x00
|
||||
#define MC32X0_YOUT_REG 0x01
|
||||
@ -151,7 +151,7 @@ s16 G_RAW_DATA[3];
|
||||
static signed int gain_data[3];
|
||||
static signed int enable_RBM_calibration = 0;
|
||||
static unsigned char mc32x0_type;
|
||||
|
||||
static int g_value;
|
||||
|
||||
#if 0
|
||||
#define mcprintkreg(x...) printk(x)
|
||||
@ -794,9 +794,8 @@ static inline int mc3230_convert_to_int(s16 value)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void mc3230_report_value(struct i2c_client *client, struct mc3230_axis *axis)
|
||||
static void mc3230_report_value(struct i2c_client *client,
|
||||
struct sensor_axis *axis)
|
||||
{
|
||||
struct sensor_private_data *mc3230 = i2c_get_clientdata(client);
|
||||
//struct mc3230_axis *axis = (struct mc3230_axis *)rbuf;
|
||||
@ -820,65 +819,79 @@ static int MC32X0_ReadData(struct i2c_client *client, s16 buffer[MC32X0_AXES_NUM
|
||||
/** ? ?????? ???? g sensor ??? */
|
||||
static int mc3230_get_data(struct i2c_client *client)
|
||||
{
|
||||
struct sensor_private_data* mc3230 = i2c_get_clientdata(client);
|
||||
struct sensor_private_data *sensor =
|
||||
(struct sensor_private_data *)i2c_get_clientdata(client);
|
||||
struct sensor_platform_data *pdata = sensor->pdata;
|
||||
s16 buffer[6];
|
||||
int ret;
|
||||
int x,y,z;
|
||||
struct mc3230_axis axis;
|
||||
|
||||
struct sensor_platform_data *pdata = pdata = client->dev.platform_data;
|
||||
//printk("%d\n==========",load_cali_flg);
|
||||
if( load_cali_flg > 0)
|
||||
{
|
||||
ret =mcube_read_cali_file(client);
|
||||
if(ret == 0)
|
||||
int x, y, z;
|
||||
int value = 0;
|
||||
static int flag;
|
||||
struct sensor_axis axis;
|
||||
|
||||
if (load_cali_flg > 0) {
|
||||
ret = mcube_read_cali_file(client);
|
||||
if (ret == 0)
|
||||
load_cali_flg = ret;
|
||||
else
|
||||
load_cali_flg --;
|
||||
//printk("load_cali %d %d\n",ret, load_cali_flg);
|
||||
}
|
||||
ret = MC32X0_ReadData(client, buffer);
|
||||
if(ret)
|
||||
{
|
||||
|
||||
GSE_ERR("%s I2C error: ret value=%d", __func__,ret);
|
||||
return EIO;
|
||||
else
|
||||
load_cali_flg--;
|
||||
}
|
||||
ret = MC32X0_ReadData(client, buffer);
|
||||
if (ret) {
|
||||
GSE_ERR("%s I2C error: ret value=%d", __func__, ret);
|
||||
return -EIO;
|
||||
}
|
||||
mcprintkfunc("%s %d %d %d \n",__func__,buffer[0],buffer[1],buffer[2]);
|
||||
|
||||
x = mc3230_convert_to_int(buffer[0]);
|
||||
y = mc3230_convert_to_int(buffer[1]);
|
||||
z = mc3230_convert_to_int(buffer[2])*2/5;
|
||||
|
||||
value = sensor_read_reg(client, 0x20);
|
||||
|
||||
axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;
|
||||
axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;
|
||||
axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
|
||||
if (value == 0x00) {
|
||||
static int cnt;
|
||||
|
||||
if (cnt++ >= 20) {
|
||||
sensor_active(client, 1, 0xff);
|
||||
cnt = 0;
|
||||
}
|
||||
g_value = 4;
|
||||
} else if (value == 0x01) {
|
||||
g_value = 2;
|
||||
} else
|
||||
g_value = 1;
|
||||
|
||||
axis.x = x;
|
||||
axis.y = y;
|
||||
axis.z = z;
|
||||
|
||||
//printk( "%s: ------------------mc3230_GetData axis = %d %d %d--------------\n",
|
||||
//__func__, axis.x, axis.y, axis.z);
|
||||
|
||||
//memcpy(sense_data, &axis, sizeof(axis));
|
||||
mc3230_report_value(client, &axis);
|
||||
//atomic_set(&data_ready, 0);
|
||||
//wake_up(&data_ready_wq);
|
||||
x = mc3230_convert_to_int(buffer[0]) * g_value;
|
||||
y = mc3230_convert_to_int(buffer[1]) * g_value;
|
||||
z = mc3230_convert_to_int(buffer[2]) * g_value;
|
||||
|
||||
/* ?????????? */
|
||||
|
||||
|
||||
mutex_lock(&mc3230->data_mutex);
|
||||
memcpy(&mc3230->axis, &axis, sizeof(mc3230->axis)); //get data from buffer
|
||||
mutex_unlock(&mc3230->data_mutex);
|
||||
|
||||
/* ?? data_ready */
|
||||
atomic_set(&(mc3230->data_ready), 1);
|
||||
/* ??? data_ready ????? */
|
||||
wake_up(&(mc3230->data_ready_wq) );
|
||||
axis.x =
|
||||
(pdata->orientation[0]) * x + (pdata->orientation[1]) * y +
|
||||
(pdata->orientation[2]) * z;
|
||||
axis.y =
|
||||
(pdata->orientation[3]) * x + (pdata->orientation[4]) * y +
|
||||
(pdata->orientation[5]) * z;
|
||||
axis.z =
|
||||
(pdata->orientation[6]) * x + (pdata->orientation[7]) * y +
|
||||
(pdata->orientation[8]) * z;
|
||||
|
||||
/* input dev will ignore report data if data value is the same with last_value,
|
||||
sample rate will not enough by this way, so just avoid this case */
|
||||
if ((sensor->axis.x == axis.x) && (sensor->axis.y == axis.y) && (sensor->axis.z == axis.z)) {
|
||||
if (flag) {
|
||||
flag = 0;
|
||||
axis.x += 1;
|
||||
axis.y += 1;
|
||||
axis.z += 1;
|
||||
} else {
|
||||
flag = 1;
|
||||
axis.x -= 1;
|
||||
axis.y -= 1;
|
||||
axis.z -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
mc3230_report_value(client, &axis);
|
||||
|
||||
mutex_lock(&sensor->data_mutex);
|
||||
sensor->axis = axis;
|
||||
mutex_unlock(&sensor->data_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user