rk30:add orientation control for gyrosensor
authorlw <lw@rock-chips.com>
Tue, 10 Apr 2012 06:44:47 +0000 (14:44 +0800)
committerlw <lw@rock-chips.com>
Tue, 10 Apr 2012 06:44:47 +0000 (14:44 +0800)
arch/arm/mach-rk30/board-rk30-sdk.c
drivers/input/gyroscope/l3g4200d.c
include/linux/l3g4200d.h

index ffa3a6d1acf4ae692eaded94101b1826f903a067..ad9f745b6222e8371abf566d974de9bccbc4acfc 100755 (executable)
@@ -544,9 +544,9 @@ static struct akm8975_platform_data akm8975_info =
        .m_layout = 
        {
                {
-                       {-1, 0, 0},
+                       {1, 0, 0},
                        {0, 0, 1},
-                       {0, -1, 0},
+                       {0, 1, 0},
                },
 
                {
@@ -578,25 +578,13 @@ static struct akm8975_platform_data akm8975_info =
 
 static int l3g4200d_init_platform_hw(void)
 {
-       if (gpio_request(L3G4200D_INT_PIN, NULL) != 0) {
-               gpio_free(L3G4200D_INT_PIN);
-               printk("%s: request l3g4200d int pin error\n", __func__);
-               return -EIO;
-       }
-       gpio_pull_updown(L3G4200D_INT_PIN, 1);
+       rk30_mux_api_set(GPIO4C3_SMCDATA3_TRACEDATA3_NAME, GPIO4C_GPIO4C3);
+       
        return 0;
 }
 
 static struct l3g4200d_platform_data l3g4200d_info = {
-       .fs_range = 1,
-
-       .axis_map_x = 0,
-       .axis_map_y = 1,
-       .axis_map_z = 2,
-
-       .negate_x = 1,
-       .negate_y = 1,
-       .negate_z = 0,
+       .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
 
        .init = l3g4200d_init_platform_hw,
 };
index 52986d462854d7b1563b0a9c1a012e219be962d2..99c003805932e93962e3312c387ebda27343b8ac 100755 (executable)
@@ -409,7 +409,7 @@ static int l3g4200d_get_data(struct i2c_client *client)
        //int res;
        unsigned char gyro_data[6];
        /* x,y,z hardware data */
-       int hw_d[3] = { 0 };
+       int x = 0, y = 0, z = 0;
 
        for(i=0;i<6;i++)
        {
@@ -418,20 +418,24 @@ static int l3g4200d_get_data(struct i2c_client *client)
                ret = l3g4200d_rx_data(client, &gyro_data[i], 1);
        }
 
-       hw_d[0] = (short) (((gyro_data[1]) << 8) | gyro_data[0]);
-       hw_d[1] = (short) (((gyro_data[3]) << 8) | gyro_data[2]);
-       hw_d[2] = (short) (((gyro_data[5]) << 8) | gyro_data[4]);
-
-       DBG("%s: x==%d  y==%d z==%d x==%d  y==%d z==%d\n",__func__, gyro_data[0],gyro_data[1],gyro_data[2],gyro_data[3],gyro_data[4],gyro_data[5]);
-
-
-       axis.x = ((this_data->pdata->negate_x) ? (-hw_d[this_data->pdata->axis_map_x])
-       : (hw_d[this_data->pdata->axis_map_x]));
-       axis.y = ((this_data->pdata->negate_y) ? (-hw_d[this_data->pdata->axis_map_y])
-       : (hw_d[this_data->pdata->axis_map_y]));
-       axis.z = ((this_data->pdata->negate_z) ? (-hw_d[this_data->pdata->axis_map_z])
-       : (hw_d[this_data->pdata->axis_map_z]));
+       x = (short) (((gyro_data[1]) << 8) | gyro_data[0]);
+       y = (short) (((gyro_data[3]) << 8) | gyro_data[2]);
+       z = (short) (((gyro_data[5]) << 8) | gyro_data[4]);
 
+       DBG("%s: x=%d  y=%d z=%d \n",__func__, x,y,z);
+       if(pdata && pdata->orientation)
+       {
+               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;
+       }
+       else
+       {
+               axis.x = x;     
+               axis.y = y;
+               axis.z = z;     
+       }
+       
        l3g4200d_report_value(client, &axis);
 
        return 0;
@@ -559,7 +563,7 @@ static irqreturn_t l3g4200d_interrupt(int irq, void *dev_id)
        struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)dev_id;
        
        disable_irq_nosync(irq);
-       schedule_delayed_work(&l3g4200d->delaywork, msecs_to_jiffies(200));
+       schedule_delayed_work(&l3g4200d->delaywork, msecs_to_jiffies(20));
        DBG("%s :enter\n",__FUNCTION__);        
        return IRQ_HANDLED;
 }
@@ -728,7 +732,10 @@ static int  l3g4200d_probe(struct i2c_client *client, const struct i2c_device_id
        struct l3g4200d_data *l3g4200d;
        struct l3g4200d_platform_data *pdata = pdata = client->dev.platform_data;
        int err;
-
+       
+       if(pdata && pdata->init)
+               pdata->init();
+       
        l3g4200d = kzalloc(sizeof(struct l3g4200d_data), GFP_KERNEL);
        if (!l3g4200d) {
                DBG("[l3g4200d]:alloc data failed.\n");
index e6066689fbf58b89c1a75dd9d285aeb47664c49c..a25277a762d45dab15bc00edfdd160685cb7fdfa 100755 (executable)
@@ -90,6 +90,7 @@ struct l3g4200d_platform_data {
        u8 negate_x;
        u8 negate_y;
        u8 negate_z;
+       signed char orientation[9];
 
        int (*init)(void);
        void (*exit)(void);