From 29ce05a8a62c5d24dee29e11f70136ea4feeb197 Mon Sep 17 00:00:00 2001 From: lw Date: Tue, 20 Dec 2011 10:47:54 +0800 Subject: [PATCH] sensors:modify a22 and td8801 sensor driver,need update android --- arch/arm/mach-rk29/board-rk29-a22.c | 36 +++++++++++ arch/arm/mach-rk29/board-rk29-td8801_v2.c | 37 +++++++++++ arch/arm/mach-rk29/include/mach/board.h | 2 +- drivers/input/gsensor/bma023.c | 77 ++++++++++++++++++++--- drivers/input/magnetometer/ak8975.c | 40 +++++++++++- drivers/input/magnetometer/ak8975.h | 10 +++ 6 files changed, 192 insertions(+), 10 deletions(-) mode change 100644 => 100755 drivers/input/gsensor/bma023.c diff --git a/arch/arm/mach-rk29/board-rk29-a22.c b/arch/arm/mach-rk29/board-rk29-a22.c index 62918bbb4e6e..3ccc0791f31a 100755 --- a/arch/arm/mach-rk29/board-rk29-a22.c +++ b/arch/arm/mach-rk29/board-rk29-a22.c @@ -1796,6 +1796,41 @@ struct platform_device rk_device_headset = { }; #endif +#if defined (CONFIG_COMPASS_AK8975) +static struct akm8975_platform_data akm8975_info = +{ + .m_layout = + { + { + {1, 0, 0 }, + {0, -1, 0 }, + {0, 0, -1 }, + }, + + { + {1, 0, 0 }, + {0, 1, 0 }, + {0, 0, 1 }, + }, + + { + {1, 0, 0 }, + {0, 1, 0 }, + {0, 0, 1 }, + }, + + { + {1, 0, 0 }, + {0, 1, 0 }, + {0, 0, 1 }, + }, + } + +}; + +#endif + + #if defined (CONFIG_SENSORS_MPU3050) /*mpu3050*/ static struct mpu3050_platform_data mpu3050_data = { @@ -2055,6 +2090,7 @@ static struct i2c_board_info __initdata board_i2c0_devices[] = { .addr = 0x0d, .flags = 0, .irq = RK29_PIN6_PC5, + .platform_data = &akm8975_info, }, #endif #if defined (CONFIG_COMPASS_MMC328X) diff --git a/arch/arm/mach-rk29/board-rk29-td8801_v2.c b/arch/arm/mach-rk29/board-rk29-td8801_v2.c index e9beeb10a60a..032c23796ac3 100755 --- a/arch/arm/mach-rk29/board-rk29-td8801_v2.c +++ b/arch/arm/mach-rk29/board-rk29-td8801_v2.c @@ -681,6 +681,42 @@ static struct bma023_platform_data bma023_info = { }; #endif + +#if defined (CONFIG_COMPASS_AK8975) +static struct akm8975_platform_data akm8975_info = +{ + .m_layout = + { + { + {-1, 0, 0 }, + {0, -1, 0 }, + {0, 0, 1 }, + }, + + { + {-1, 0, 0 }, + {0, -1, 0 }, + {0, 0, 1 }, + }, + + { + {1, 0, 0 }, + {0, 1, 0 }, + {0, 0, 1 }, + }, + + { + {1, 0, 0 }, + {0, 1, 0 }, + {0, 0, 1 }, + }, + } + +}; + +#endif + + /*mpu3050*/ #if defined (CONFIG_MPU_SENSORS_MPU3050) static struct mpu_platform_data mpu3050_data = { @@ -1960,6 +1996,7 @@ static struct i2c_board_info __initdata board_i2c0_devices[] = { .addr = 0x0d, .flags = 0, .irq = RK29_PIN6_PC5, + .platform_data = &akm8975_info, }, #endif #if defined (CONFIG_INPUT_LPSENSOR_ISL29028) diff --git a/arch/arm/mach-rk29/include/mach/board.h b/arch/arm/mach-rk29/include/mach/board.h index d9c9068afcaf..5c85b1ac0c51 100755 --- a/arch/arm/mach-rk29/include/mach/board.h +++ b/arch/arm/mach-rk29/include/mach/board.h @@ -331,7 +331,7 @@ struct laibao_platform_data { }; struct akm8975_platform_data { - char layouts[3][3]; + short m_layout[4][3][3]; char project_name[64]; int gpio_DRDY; }; diff --git a/drivers/input/gsensor/bma023.c b/drivers/input/gsensor/bma023.c old mode 100644 new mode 100755 index d4d66cb0301c..fe2ab2ecd02c --- a/drivers/input/gsensor/bma023.c +++ b/drivers/input/gsensor/bma023.c @@ -34,6 +34,14 @@ #include #endif + +#if 0 +#define DBG(x...) printk(x) +#else +#define DBG(x...) +#endif + + #define SENSOR_NAME "bma150" #define GRAVITY_EARTH 9806550 #define ABSMIN_2G (-GRAVITY_EARTH * 2) @@ -226,8 +234,11 @@ struct bma150_data { #define BMA_IOCTL_START _IO(BMAIO, 0x03) #define BMA_IOCTL_GETDATA _IOR(BMAIO, 0x08, char[RBUFF_SIZE+1]) -static int bma023_ioctl(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg); +/* IOCTLs for APPs */ +#define BMA_IOCTL_APP_SET_RATE _IOW(BMAIO, 0x10, char) + +static long bma023_ioctl( struct file *file, unsigned int cmd, unsigned long arg); + static void bma150_early_suspend(struct early_suspend *h); static void bma150_late_resume(struct early_suspend *h); @@ -457,7 +468,7 @@ static void bma150_work_func(struct work_struct *work) mutex_lock(&bma150->value_mutex); bma150->value = acc; mutex_unlock(&bma150->value_mutex); - //printk("bma150_work_func acc.x=%d,acc.y=%d,acc.z=%d\n",acc.x,acc.y,acc.z); + DBG("bma150_work_func acc.x=%d,acc.y=%d,acc.z=%d\n",acc.x,acc.y,acc.z); schedule_delayed_work(&bma150->work, delay); } @@ -724,6 +735,7 @@ static void bma150_input_delete(struct bma150_data *bma150) static int bma023_open(struct inode *inode, struct file *file) { + printk("%s\n",__FUNCTION__); return 0;//nonseekable_open(inode, file); } @@ -742,22 +754,68 @@ static struct miscdevice bma023_device = { .name = "mma8452_daemon",//"mma8452_daemon", .fops = &bma023_fops, }; -static int bma023_ioctl(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg) + + +static bma023_enable(struct i2c_client *client, int enable) +{ + + struct bma150_data *bma150 = i2c_get_clientdata(client); + int pre_enable = atomic_read(&bma150->enable); + + mutex_lock(&bma150->enable_mutex); + + if(enable) + { + if(pre_enable==0) + { + bma150_set_mode(client,BMA150_MODE_NORMAL); + schedule_delayed_work(&bma150->work, + msecs_to_jiffies(atomic_read(&bma150->delay))); + atomic_set(&bma150->enable, 1); + } + } + else + { + bma150_set_mode(client,BMA150_MODE_SLEEP); + cancel_delayed_work_sync(&bma150->work); + atomic_set(&bma150->enable, 0); + } + + mutex_unlock(&bma150->enable_mutex); + +} + + +static long bma023_ioctl( struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; struct i2c_client *client = container_of(bma023_device.parent, struct i2c_client, dev); struct bma150_data *bma150 = i2c_get_clientdata(client);; switch (cmd) { + case BMA_IOCTL_START: + bma023_enable(client, 1); + DBG("%s:%d,cmd=BMA_IOCTL_START\n",__FUNCTION__,__LINE__); + break; + + case BMA_IOCTL_CLOSE: + bma023_enable(client, 0); + DBG("%s:%d,cmd=BMA_IOCTL_CLOSE\n",__FUNCTION__,__LINE__); + break; + + case BMA_IOCTL_APP_SET_RATE: + atomic_set(&bma150->delay, 20);//20ms + DBG("%s:%d,cmd=BMA_IOCTL_APP_SET_RATE\n",__FUNCTION__,__LINE__); + break; + case BMA_IOCTL_GETDATA: mutex_lock(&bma150->value_mutex); if(abs(sense_data.x-bma150->value.x)>10)//·À¶¶¶¯ - sense_data.x=bma150->value.x; + sense_data.x=(bma150->value.x*1000)>>8; if(abs(sense_data.y+(bma150->value.z))>10)//·À¶¶¶¯ - sense_data.y=-(bma150->value.z); + sense_data.y=(bma150->value.z*1000)>>8; if(abs(sense_data.z+(bma150->value.y))>10)//·À¶¶¶¯ - sense_data.z=-(bma150->value.y); + sense_data.z=(bma150->value.y*1000)>>8; //bma150->value = acc; mutex_unlock(&bma150->value_mutex); @@ -765,8 +823,11 @@ static int bma023_ioctl(struct inode *inode, struct file *file, unsigned int cmd printk("failed to copy sense data to user space."); return -EFAULT; } + + DBG("%s:%d,cmd=BMA_IOCTL_GETDATA\n",__FUNCTION__,__LINE__); break; default: + printk("%s:%d,error,cmd=%x\n",__FUNCTION__,__LINE__,cmd); break; } return 0; diff --git a/drivers/input/magnetometer/ak8975.c b/drivers/input/magnetometer/ak8975.c index 68ff06e23b83..7057207fb7f9 100755 --- a/drivers/input/magnetometer/ak8975.c +++ b/drivers/input/magnetometer/ak8975.c @@ -61,6 +61,7 @@ struct akm8975_data { struct work_struct work; struct early_suspend akm_early_suspend; int eoc_irq; + struct akm8975_platform_data *pdata; }; /* Addresses to scan -- protected by sense_data_mutex */ @@ -501,6 +502,26 @@ static int akmd_release(struct inode *inode, struct file *file) return 0; } + +static int akm_get_platform_data(struct akm8975_platform_data __user *arg) +{ + struct akm8975_data *data = (struct akm8975_data *)i2c_get_clientdata(this_client); + struct akm8975_platform_data *pdata_slave; +// struct akm8975_platform_data local_pdata_slave; + +// if (copy_from_user(&local_pdata_slave, arg, sizeof(local_pdata_slave))) +// return -EFAULT; + pdata_slave = data->pdata; + if (!pdata_slave) + return -ENODEV; + if (copy_to_user(arg, pdata_slave, sizeof(*pdata_slave))) + return -EFAULT; + + return 0; +} + + + //static int akmd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, // unsigned long arg) @@ -609,6 +630,15 @@ static long akmd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) AKMFUNC("IOCTL_GET_DELAY"); delay = akmd_delay; break; + case ECS_IOCTL_GET_PLATFORM_DATA: + ret = akm_get_platform_data((struct akm8975_platform_data __user *)arg); + if(ret < 0) + { + printk("%s:error,ret=%d\n",__FUNCTION__, ret); + return ret; + } + break; + default: return -ENOTTY; } @@ -766,7 +796,13 @@ int akm8975_probe(struct i2c_client *client, const struct i2c_device_id *id) int err = 0; AKMFUNC("akm8975_probe"); - + + if (client->dev.platform_data == NULL) { + dev_err(&client->dev, "platform data is NULL. exiting.\n"); + err = -ENODEV; + goto exit0; + } + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { printk(KERN_ERR "AKM8975 akm8975_probe: check_functionality failed.\n"); err = -ENODEV; @@ -780,6 +816,8 @@ int akm8975_probe(struct i2c_client *client, const struct i2c_device_id *id) err = -ENOMEM; goto exit1; } + + akm->pdata = client->dev.platform_data; INIT_WORK(&akm->work, akm8975_work_func); i2c_set_clientdata(client, akm); diff --git a/drivers/input/magnetometer/ak8975.h b/drivers/input/magnetometer/ak8975.h index dd6628552d18..d26ba79d30c7 100755 --- a/drivers/input/magnetometer/ak8975.h +++ b/drivers/input/magnetometer/ak8975.h @@ -67,6 +67,8 @@ Defines a read-only address of the fuse ROM of the AK8975.*/ #define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, short) #define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64]) #define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short [4][3][3]) +#define ECS_IOCTL_GET_PLATFORM_DATA _IOR(AKMIO, 0x0E, struct akm8975_platform_data) + /* IOCTLs for APPs */ #define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short) @@ -82,5 +84,13 @@ Defines a read-only address of the fuse ROM of the AK8975.*/ #define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) #define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) +struct akm8975_platform_data { + short m_layout[4][3][3]; + char project_name[64]; + int gpio_DRDY; +}; + + + #endif -- 2.34.1