mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 11:50:43 +09:00
drivers/input: remove unused gsensor drivers
Change-Id: I9a895925a37f775244d04a7a4bf6b2d4c43cdc3a Signed-off-by: Tao Huang <huangtao@rock-chips.com>
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# gsensor drivers configuration
|
||||
#
|
||||
|
||||
menuconfig G_SENSOR_DEVICE
|
||||
bool "g_sensor device support"
|
||||
help
|
||||
Enable this to be able to choose the drivers for controlling the
|
||||
g_sensor on some platforms, for example on PDAs.
|
||||
|
||||
if G_SENSOR_DEVICE
|
||||
|
||||
config GS_MMA7660
|
||||
bool "gs_mma7660"
|
||||
help
|
||||
To have support for your specific gsesnor you will have to
|
||||
select the proper drivers which depend on this option.
|
||||
|
||||
config GS_MMA8452
|
||||
bool "gs_mma8452"
|
||||
help
|
||||
To have support for your specific gsesnor you will have to
|
||||
select the proper drivers which depend on this option.
|
||||
|
||||
config GS_LIS3DH
|
||||
bool "gs_lis3dh"
|
||||
help
|
||||
To have support for your specific gsesnor you will have to
|
||||
select the proper drivers which depend on this option.
|
||||
|
||||
config GS_L3G4200D
|
||||
bool "gs_l3g4200d"
|
||||
help
|
||||
To have support for your specific gsesnor you will have to
|
||||
select the proper drivers which depend on this option.
|
||||
|
||||
config GS_BMA023
|
||||
bool "gs_bma023"
|
||||
help
|
||||
To have support for your specific gsesnor you will have to
|
||||
select the proper drivers which depend on this option.
|
||||
endif
|
||||
@@ -1,8 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# gsensor drivers
|
||||
|
||||
obj-$(CONFIG_GS_MMA7660) += mma7660.o
|
||||
obj-$(CONFIG_GS_MMA8452) += mma8452.o
|
||||
obj-$(CONFIG_GS_L3G4200D) += l3g4200d.o
|
||||
obj-$(CONFIG_GS_LIS3DH) += lis3dh.o
|
||||
obj-$(CONFIG_GS_BMA023) += bma023.o
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,879 +0,0 @@
|
||||
/* drivers/i2c/chips/l3g4200d.c - l3g4200d compass driver
|
||||
*
|
||||
* Copyright (C) 2007-2008 HTC Corporation.
|
||||
* Author: Hou-Kun Chen <houkun.chen@gmail.com>
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/l3g4200d.h>
|
||||
#include <mach/gpio.h>
|
||||
#include <mach/board.h>
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
#include <linux/earlysuspend.h>
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#define mmaprintk(x...) printk(x)
|
||||
#else
|
||||
#define mmaprintk(x...)
|
||||
#endif
|
||||
static int l3g4200d_probe(struct i2c_client *client, const struct i2c_device_id *id);
|
||||
|
||||
#define L3G4200D_SPEED 200 * 1000
|
||||
#define L3G4200D_DEVID 0xD3
|
||||
|
||||
#define L3G4200D_MAJOR 102
|
||||
#define L3G4200D_MINOR 4
|
||||
|
||||
/* l3g4200d gyroscope registers */
|
||||
#define WHO_AM_I 0x0F
|
||||
|
||||
#define CTRL_REG1 0x20 /* power control reg */
|
||||
#define CTRL_REG2 0x21 /* power control reg */
|
||||
#define CTRL_REG3 0x22 /* power control reg */
|
||||
#define CTRL_REG4 0x23 /* interrupt control reg */
|
||||
#define CTRL_REG5 0x24 /* interrupt control reg */
|
||||
#define AXISDATA_REG 0x28
|
||||
|
||||
|
||||
/* Addresses to scan -- protected by sense_data_mutex */
|
||||
//static char sense_data[RBUFF_SIZE + 1];
|
||||
static struct i2c_client *this_client;
|
||||
static struct l3g4200d_data *this_data;
|
||||
static struct miscdevice l3g4200d_device;
|
||||
|
||||
static DECLARE_WAIT_QUEUE_HEAD(data_ready_wq);
|
||||
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
static struct early_suspend l3g4200d_early_suspend;
|
||||
#endif
|
||||
static int revision = -1;
|
||||
/* AKM HW info */
|
||||
static ssize_t gsensor_vendor_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
|
||||
sprintf(buf, "%#x\n", revision);
|
||||
ret = strlen(buf) + 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(vendor, 0444, gsensor_vendor_show, NULL);
|
||||
|
||||
static struct kobject *android_gsensor_kobj;
|
||||
|
||||
static int gsensor_sysfs_init(void)
|
||||
{
|
||||
int ret ;
|
||||
|
||||
android_gsensor_kobj = kobject_create_and_add("android_gyrosensor", NULL);
|
||||
if (android_gsensor_kobj == NULL) {
|
||||
mmaprintk(KERN_ERR
|
||||
"L3G4200D gsensor_sysfs_init:"\
|
||||
"subsystem_register failed\n");
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = sysfs_create_file(android_gsensor_kobj, &dev_attr_vendor.attr);
|
||||
if (ret) {
|
||||
mmaprintk(KERN_ERR
|
||||
"L3G4200D gsensor_sysfs_init:"\
|
||||
"sysfs_create_group failed\n");
|
||||
goto err4;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
err4:
|
||||
kobject_del(android_gsensor_kobj);
|
||||
err:
|
||||
return ret ;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int l3g4200d_rx_data(struct i2c_client *client, char *rxData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = rxData[0];
|
||||
ret = i2c_master_reg8_recv(client, reg, rxData, length, L3G4200D_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
#else
|
||||
static int l3g4200d_rx_data(struct i2c_client *client, char *rxData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
int retry = 3;
|
||||
char reg = rxData[0];
|
||||
again:
|
||||
ret = i2c_master_reg8_recv(client, reg, rxData, length, L3G4200D_SPEED);
|
||||
if(ret < 0)
|
||||
{
|
||||
retry--;
|
||||
mdelay(1);
|
||||
goto again;
|
||||
}
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
static int l3g4200d_tx_data(struct i2c_client *client, char *txData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = txData[0];
|
||||
ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, L3G4200D_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
#else
|
||||
static int l3g4200d_tx_data(struct i2c_client *client, char *txData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = txData[0];
|
||||
int retry = 3;
|
||||
again:
|
||||
ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, L3G4200D_SPEED);
|
||||
if(ret < 0)
|
||||
{
|
||||
retry--;
|
||||
mdelay(1);
|
||||
goto again;
|
||||
}
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int gyro_rx_data(struct i2c_client *client, char *rxData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
int retry = 3;
|
||||
char reg = rxData[0];
|
||||
again:
|
||||
ret = i2c_master_reg8_recv(client, reg, rxData, length, L3G4200D_SPEED);
|
||||
if(ret < 0)
|
||||
{
|
||||
retry--;
|
||||
mdelay(1);
|
||||
goto again;
|
||||
}
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
static int gyro_tx_data(struct i2c_client *client, char *txData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = txData[0];
|
||||
int retry = 3;
|
||||
again:
|
||||
ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, L3G4200D_SPEED);
|
||||
if(ret < 0)
|
||||
{
|
||||
retry--;
|
||||
mdelay(1);
|
||||
goto again;
|
||||
}
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* i2c read routine for l3g4200d digital gyroscope */
|
||||
static char l3g4200d_i2c_read(unsigned char reg_addr,
|
||||
unsigned char *data,
|
||||
unsigned char len)
|
||||
{
|
||||
char tmp;
|
||||
int ret = 0;
|
||||
if (this_client == NULL) /* No global client pointer? */
|
||||
return -1;
|
||||
|
||||
data[0]=reg_addr;
|
||||
ret = gyro_rx_data(this_client, data, len);
|
||||
return tmp;
|
||||
}
|
||||
/* i2c write routine for l3g4200d digital gyroscope */
|
||||
static char l3g4200d_i2c_write(unsigned char reg_addr,
|
||||
unsigned char *data,
|
||||
unsigned char len)
|
||||
{
|
||||
|
||||
char buffer[3];
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
if (this_client == NULL) /* No global client pointer? */
|
||||
return -1;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
buffer[0] = reg_addr+i;
|
||||
buffer[1] = data[i];
|
||||
ret = gyro_tx_data(this_client, &buffer[0], 2);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static char l3g4200d_read_reg(struct i2c_client *client,int addr)
|
||||
{
|
||||
char tmp;
|
||||
int ret = 0;
|
||||
|
||||
tmp = addr;
|
||||
// ret = l3g4200d_tx_data(client, &tmp, 1);
|
||||
ret = l3g4200d_rx_data(client, &tmp, 1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int l3g4200d_write_reg(struct i2c_client *client,int addr,int value)
|
||||
{
|
||||
char buffer[3];
|
||||
int ret = 0;
|
||||
|
||||
buffer[0] = addr;
|
||||
buffer[1] = value;
|
||||
ret = l3g4200d_tx_data(client, &buffer[0], 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char l3g4200d_get_devid(struct i2c_client *client)
|
||||
{
|
||||
int tempvalue;
|
||||
tempvalue=l3g4200d_read_reg(client, WHO_AM_I);
|
||||
if ((tempvalue & 0x00FF) == 0x00D3) {
|
||||
#if DEBUG
|
||||
printk(KERN_INFO "I2C driver registered!\n");
|
||||
#endif
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
#if DEBUG
|
||||
printk(KERN_INFO "I2C driver %d!\n",tempvalue);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int l3g4200d_active(struct i2c_client *client,int enable)
|
||||
{
|
||||
int tmp;
|
||||
int ret = 0;
|
||||
|
||||
tmp = l3g4200d_read_reg(client,CTRL_REG1);
|
||||
if(enable)
|
||||
tmp |=ACTIVE_MASK;
|
||||
else
|
||||
tmp &=~ACTIVE_MASK;
|
||||
mmaprintk("l3g4200d_active %s (0x%x)\n",enable?"active":"standby",tmp);
|
||||
ret = l3g4200d_write_reg(client,CTRL_REG1,tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int device_init(void)
|
||||
{
|
||||
int res;
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0x07; //27
|
||||
buf[1] = 0x00;
|
||||
buf[2] = 0x00;
|
||||
buf[3] = 0x20; //0x00
|
||||
buf[4] = 0x00;
|
||||
res = l3g4200d_i2c_write(CTRL_REG1, &buf[0], 5);
|
||||
return res;
|
||||
}
|
||||
|
||||
int l3g4200d_set_bandwidth(char bw)
|
||||
{
|
||||
int res = 0;
|
||||
unsigned char data;
|
||||
|
||||
res = l3g4200d_read_reg(this_client, CTRL_REG1);
|
||||
if (res >= 0)
|
||||
data = res & 0x000F;
|
||||
|
||||
data = data + bw;
|
||||
res = l3g4200d_i2c_write(CTRL_REG1, &data, 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int l3g4200d_start_dev(struct i2c_client *client, char rate)
|
||||
{
|
||||
int ret = 0;
|
||||
int tmp;
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
|
||||
/* standby */
|
||||
l3g4200d_active(client,0);
|
||||
device_init();
|
||||
l3g4200d_set_bandwidth(rate);
|
||||
l3g4200d_active(client,1);
|
||||
|
||||
enable_irq(client->irq);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int l3g4200d_start(struct i2c_client *client, char rate)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
|
||||
printk("%s::enter\n",__FUNCTION__);
|
||||
if (l3g4200d->status == L3G4200D_OPEN) {
|
||||
return 0;
|
||||
}
|
||||
l3g4200d->status = L3G4200D_OPEN;
|
||||
return l3g4200d_start_dev(client, rate);
|
||||
}
|
||||
|
||||
static int l3g4200d_close_dev(struct i2c_client *client)
|
||||
{
|
||||
mmaprintk("%s :enter\n",__FUNCTION__);
|
||||
disable_irq_nosync(client->irq);
|
||||
return l3g4200d_active(client,0);
|
||||
}
|
||||
|
||||
static int l3g4200d_close(struct i2c_client *client)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
printk("%s::enter\n",__FUNCTION__);
|
||||
l3g4200d->status = L3G4200D_CLOSE;
|
||||
|
||||
return l3g4200d_close_dev(client);
|
||||
}
|
||||
|
||||
static int l3g4200d_reset_rate(struct i2c_client *client, char rate)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mmaprintk("\n----------------------------l3g4200d_reset_rate------------------------\n");
|
||||
|
||||
ret = l3g4200d_close_dev(client);
|
||||
ret = l3g4200d_start_dev(client, rate);
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static inline int l3g4200d_convert_to_int(char value)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (value < 1) {
|
||||
result = value * 1;
|
||||
} else {
|
||||
result = ~(((~value & 0x7f) + 1)* 1) + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void l3g4200d_report_value(struct i2c_client *client, struct l3g4200d_axis *axis)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d = i2c_get_clientdata(client);
|
||||
//struct l3g4200d_axis *axis = (struct l3g4200d_axis *)rbuf;
|
||||
|
||||
/* Report acceleration sensor information */
|
||||
input_report_abs(l3g4200d->input_dev, ABS_RX, axis->x);
|
||||
input_report_abs(l3g4200d->input_dev, ABS_RY, axis->y);
|
||||
input_report_abs(l3g4200d->input_dev, ABS_RZ, axis->z);
|
||||
input_sync(l3g4200d->input_dev);
|
||||
mmaprintk("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
}
|
||||
|
||||
|
||||
static int l3g4200d_get_data(struct i2c_client *client)
|
||||
{
|
||||
char buffer[6];
|
||||
int ret,i;
|
||||
struct l3g4200d_axis axis;
|
||||
struct l3g4200d_platform_data *pdata = pdata = client->dev.platform_data;
|
||||
|
||||
int res;
|
||||
unsigned char gyro_data[6];
|
||||
/* x,y,z hardware data */
|
||||
int hw_d[3] = { 0 };
|
||||
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
gyro_data[i] = AXISDATA_REG+i;
|
||||
//ret = l3g4200d_tx_data(client, &buffer[0], 1);
|
||||
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]);
|
||||
|
||||
//mmaprintk("Gsensor x==%d y==%d z==%d x==%d y==%d z==%d\n",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]));
|
||||
|
||||
l3g4200d_report_value(client, &axis);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static int l3g4200d_trans_buff(char *rbuf, int size)
|
||||
{
|
||||
//wait_event_interruptible_timeout(data_ready_wq,
|
||||
// atomic_read(&data_ready), 1000);
|
||||
wait_event_interruptible(data_ready_wq,
|
||||
atomic_read(&data_ready));
|
||||
|
||||
atomic_set(&data_ready, 0);
|
||||
memcpy(rbuf, &sense_data[0], size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
static int l3g4200d_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
mmaprintk("%s :enter\n",__FUNCTION__);
|
||||
return 0;//nonseekable_open(inode, file);
|
||||
}
|
||||
|
||||
static int l3g4200d_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
mmaprintk("%s :enter\n",__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
#define RBUFF_SIZE 12 /* Rx buffer size */
|
||||
|
||||
static int l3g4200d_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(this_client);
|
||||
void __user *argp = (void __user *)arg;
|
||||
char msg[RBUFF_SIZE + 1];
|
||||
int ret = -1;
|
||||
char rate;
|
||||
struct i2c_client *client = container_of(l3g4200d_device.parent, struct i2c_client, dev);
|
||||
printk(KERN_ERR "l3g4200d_ioctl,%d,%d,%d,%d,%d,%d,%d\n",cmd,GYROSENSOR_IOCTL_ENABLE,GYROSENSOR_IOCTL_GET_ENABLED,ECS_IOCTL_APP_GET_ABS,ECS_IOCTL_START,ECS_IOCTL_CLOSE,ECS_IOCTL_APP_SET_RATE);
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_APP_SET_RATE:
|
||||
if (copy_from_user(&rate, argp, sizeof(rate)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_START:
|
||||
case GYROSENSOR_IOCTL_ENABLE:
|
||||
ret = l3g4200d_start(client, ODR100_BW12_5);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case ECS_IOCTL_CLOSE:
|
||||
ret = l3g4200d_close(client);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case ECS_IOCTL_APP_SET_RATE:
|
||||
ret = l3g4200d_reset_rate(client, 0x00);//rate<<4);//0x20
|
||||
printk(KERN_ERR "%d\n",rate);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case GYROSENSOR_IOCTL_GET_ENABLED:
|
||||
break;
|
||||
/*
|
||||
case ECS_IOCTL_GETDATA:
|
||||
ret = l3g4200d_trans_buff(msg, RBUFF_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_GETDATA:
|
||||
case ECS_IOCTL_APP_GET_ABS:
|
||||
if (copy_to_user(argp, &msg, sizeof(msg)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
case GYROSENSOR_IOCTL_GET_ENABLED:
|
||||
mmaprintk("%s :enter\n",__FUNCTION__);
|
||||
ret=!l3g4200d->status;
|
||||
if (copy_to_user(argp, &ret, sizeof(ret)))
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void l3g4200d_work_func(struct work_struct *work)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d = container_of(work, struct l3g4200d_data, work);
|
||||
struct i2c_client *client = l3g4200d->client;
|
||||
|
||||
if (l3g4200d_get_data(client) < 0)
|
||||
mmaprintk(KERN_ERR "L3G4200D mma_work_func: Get data failed\n");
|
||||
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
static void l3g4200d_delaywork_func(struct work_struct *work)
|
||||
{
|
||||
struct delayed_work *delaywork = container_of(work, struct delayed_work, work);
|
||||
struct l3g4200d_data *l3g4200d = container_of(delaywork, struct l3g4200d_data, delaywork);
|
||||
struct i2c_client *client = l3g4200d->client;
|
||||
|
||||
if (l3g4200d_get_data(client) < 0)
|
||||
mmaprintk(KERN_ERR "L3G4200D mma_work_func: Get data failed\n");
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
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));
|
||||
//mmaprintk("%s :enter\n",__FUNCTION__);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static struct file_operations l3g4200d_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = l3g4200d_open,
|
||||
.release = l3g4200d_release,
|
||||
.ioctl = l3g4200d_ioctl,
|
||||
};
|
||||
|
||||
static struct miscdevice l3g4200d_device = {
|
||||
.minor = MISC_DYNAMIC_MINOR,
|
||||
.name = "gyrosensor",//"l3g4200d_daemon",
|
||||
.fops = &l3g4200d_fops,
|
||||
};
|
||||
|
||||
static int l3g4200d_remove(struct i2c_client *client)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d = i2c_get_clientdata(client);
|
||||
|
||||
misc_deregister(&l3g4200d_device);
|
||||
input_unregister_device(l3g4200d->input_dev);
|
||||
input_free_device(l3g4200d->input_dev);
|
||||
free_irq(client->irq, l3g4200d);
|
||||
kfree(l3g4200d);
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
unregister_early_suspend(&l3g4200d_early_suspend);
|
||||
#endif
|
||||
this_client = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
static void l3g4200d_suspend(struct early_suspend *h)
|
||||
{
|
||||
struct i2c_client *client = container_of(l3g4200d_device.parent, struct i2c_client, dev);
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
// if(l3g4200d->status == L3G4200D_OPEN)
|
||||
// {
|
||||
//l3g4200d->status = L3G4200D_SUSPEND;
|
||||
// l3g4200d_close_dev(client);
|
||||
// }
|
||||
}
|
||||
|
||||
static void l3g4200d_resume(struct early_suspend *h)
|
||||
{
|
||||
struct i2c_client *client = container_of(l3g4200d_device.parent, struct i2c_client, dev);
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
mmaprintk("Gsensor mma7760 resume!! l3g4200d->status %d\n",l3g4200d->status);
|
||||
//if((l3g4200d->status == L3G4200D_SUSPEND) && (l3g4200d->status != L3G4200D_OPEN))
|
||||
// if (l3g4200d->status == L3G4200D_OPEN)
|
||||
// l3g4200d_start_dev(client,l3g4200d->curr_tate);
|
||||
}
|
||||
#else
|
||||
static int l3g4200d_suspend(struct i2c_client *client, pm_message_t mesg)
|
||||
{
|
||||
int ret;
|
||||
mmaprintk("Gsensor mma7760 enter 2 level suspend l3g4200d->status %d\n",l3g4200d->status);
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
// if(l3g4200d->status == L3G4200D_OPEN)
|
||||
// {
|
||||
// l3g4200d->status = L3G4200D_SUSPEND;
|
||||
// ret = l3g4200d_close_dev(client);
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
static int l3g4200d_resume(struct i2c_client *client)
|
||||
{
|
||||
int ret;
|
||||
struct l3g4200d_data *l3g4200d = (struct l3g4200d_data *)i2c_get_clientdata(client);
|
||||
mmaprintk("Gsensor mma7760 2 level resume!! l3g4200d->status %d\n",l3g4200d->status);
|
||||
// if((l3g4200d->status == L3G4200D_SUSPEND) && (l3g4200d->status != L3G4200D_OPEN))
|
||||
//if (l3g4200d->status == L3G4200D_OPEN)
|
||||
// ret = l3g4200d_start_dev(client, l3g4200d->curr_tate);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct i2c_device_id l3g4200d_id[] = {
|
||||
{"gs_l3g4200d", 0},
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct i2c_driver l3g4200d_driver = {
|
||||
.driver = {
|
||||
.name = "gs_l3g4200d",
|
||||
},
|
||||
.id_table = l3g4200d_id,
|
||||
.probe = l3g4200d_probe,
|
||||
.remove = __devexit_p(l3g4200d_remove),
|
||||
#ifndef CONFIG_HAS_EARLYSUSPEND
|
||||
.suspend = &l3g4200d_suspend,
|
||||
.resume = &l3g4200d_resume,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static int l3g4200d_init_client(struct i2c_client *client)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d;
|
||||
int ret;
|
||||
l3g4200d = i2c_get_clientdata(client);
|
||||
mmaprintk("gpio_to_irq(%d) is %d\n",client->irq,gpio_to_irq(client->irq));
|
||||
if ( !gpio_is_valid(client->irq)) {
|
||||
mmaprintk("+++++++++++gpio_is_invalid\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = gpio_request(client->irq, "l3g4200d_int");
|
||||
if (ret) {
|
||||
mmaprintk( "failed to request mma7990_trig GPIO%d\n",gpio_to_irq(client->irq));
|
||||
return ret;
|
||||
}
|
||||
ret = gpio_direction_input(client->irq);
|
||||
if (ret) {
|
||||
mmaprintk("failed to set mma7990_trig GPIO gpio input\n");
|
||||
return ret;
|
||||
}
|
||||
gpio_pull_updown(client->irq, GPIOPullUp);
|
||||
client->irq = gpio_to_irq(client->irq);
|
||||
ret = request_irq(client->irq, l3g4200d_interrupt, IRQF_TRIGGER_LOW, client->dev.driver->name, l3g4200d);
|
||||
mmaprintk("request irq is %d,ret is 0x%x\n",client->irq,ret);
|
||||
if (ret ) {
|
||||
mmaprintk(KERN_ERR "l3g4200d_init_client: request irq failed,ret is %d\n",ret);
|
||||
return ret;
|
||||
}
|
||||
disable_irq(client->irq);
|
||||
init_waitqueue_head(&data_ready_wq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int l3g4200d_validate_pdata(struct l3g4200d_data *gyro)
|
||||
{
|
||||
if (gyro->pdata->axis_map_x > 2 ||
|
||||
gyro->pdata->axis_map_y > 2 ||
|
||||
gyro->pdata->axis_map_z > 2) {
|
||||
dev_err(&gyro->client->dev,
|
||||
"invalid axis_map value x:%u y:%u z%u\n",
|
||||
gyro->pdata->axis_map_x, gyro->pdata->axis_map_y,
|
||||
gyro->pdata->axis_map_z);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Only allow 0 and 1 for negation boolean flag */
|
||||
if (gyro->pdata->negate_x > 1 ||
|
||||
gyro->pdata->negate_y > 1 ||
|
||||
gyro->pdata->negate_z > 1) {
|
||||
dev_err(&gyro->client->dev,
|
||||
"invalid negate value x:%u y:%u z:%u\n",
|
||||
gyro->pdata->negate_x, gyro->pdata->negate_y,
|
||||
gyro->pdata->negate_z);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int l3g4200d_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct l3g4200d_data *l3g4200d;
|
||||
struct l3g4200d_platform_data *pdata = pdata = client->dev.platform_data;
|
||||
int err;
|
||||
|
||||
mmaprintk("%s enter\n",__FUNCTION__);
|
||||
|
||||
l3g4200d = kzalloc(sizeof(struct l3g4200d_data), GFP_KERNEL);
|
||||
if (!l3g4200d) {
|
||||
mmaprintk("[l3g4200d]:alloc data failed.\n");
|
||||
err = -ENOMEM;
|
||||
goto exit_alloc_data_failed;
|
||||
}
|
||||
|
||||
INIT_WORK(&l3g4200d->work, l3g4200d_work_func);
|
||||
INIT_DELAYED_WORK(&l3g4200d->delaywork, l3g4200d_delaywork_func);
|
||||
|
||||
l3g4200d->client = client;
|
||||
i2c_set_clientdata(client, l3g4200d);
|
||||
|
||||
this_client = client;
|
||||
|
||||
err = l3g4200d_init_client(client);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"l3g4200d_probe: l3g4200d_init_client failed\n");
|
||||
goto exit_request_gpio_irq_failed;
|
||||
}
|
||||
|
||||
|
||||
l3g4200d->pdata = kmalloc(sizeof(*l3g4200d->pdata), GFP_KERNEL);
|
||||
|
||||
if (l3g4200d->pdata == NULL)
|
||||
goto exit_kfree;
|
||||
|
||||
memcpy(l3g4200d->pdata, client->dev.platform_data, sizeof(*l3g4200d->pdata));
|
||||
|
||||
err = l3g4200d_validate_pdata(l3g4200d);
|
||||
if (err < 0) {
|
||||
dev_err(&client->dev, "failed to validate platform data\n");
|
||||
goto exit_kfree_pdata;
|
||||
}
|
||||
this_data=l3g4200d;
|
||||
|
||||
|
||||
|
||||
|
||||
l3g4200d->input_dev = input_allocate_device();
|
||||
if (!l3g4200d->input_dev) {
|
||||
err = -ENOMEM;
|
||||
mmaprintk(KERN_ERR
|
||||
"l3g4200d_probe: Failed to allocate input device\n");
|
||||
goto exit_input_allocate_device_failed;
|
||||
}
|
||||
|
||||
set_bit(EV_ABS, l3g4200d->input_dev->evbit);
|
||||
|
||||
/* x-axis acceleration */
|
||||
input_set_abs_params(l3g4200d->input_dev, ABS_RX, -28571, 28571, 0, 0); //2g full scale range
|
||||
/* y-axis acceleration */
|
||||
input_set_abs_params(l3g4200d->input_dev, ABS_RY, -28571, 28571, 0, 0); //2g full scale range
|
||||
/* z-axis acceleration */
|
||||
input_set_abs_params(l3g4200d->input_dev, ABS_RZ, -28571, 28571, 0, 0); //2g full scale range
|
||||
|
||||
l3g4200d->input_dev->name = "gyro";
|
||||
l3g4200d->input_dev->dev.parent = &client->dev;
|
||||
|
||||
err = input_register_device(l3g4200d->input_dev);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"l3g4200d_probe: Unable to register input device: %s\n",
|
||||
l3g4200d->input_dev->name);
|
||||
goto exit_input_register_device_failed;
|
||||
}
|
||||
|
||||
l3g4200d_device.parent = &client->dev;
|
||||
err = misc_register(&l3g4200d_device);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"l3g4200d_probe: mmad_device register failed\n");
|
||||
goto exit_misc_device_register_l3g4200d_device_failed;
|
||||
}
|
||||
|
||||
err = gsensor_sysfs_init();
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"l3g4200d_probe: gsensor sysfs init failed\n");
|
||||
goto exit_gsensor_sysfs_init_failed;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
l3g4200d_early_suspend.suspend = l3g4200d_suspend;
|
||||
l3g4200d_early_suspend.resume = l3g4200d_resume;
|
||||
l3g4200d_early_suspend.level = 0x2;
|
||||
register_early_suspend(&l3g4200d_early_suspend);
|
||||
#endif
|
||||
if(l3g4200d_get_devid(this_client))
|
||||
printk(KERN_INFO "l3g4200d probe ok\n");
|
||||
else
|
||||
printk(KERN_INFO "l3g4200d probe error\n");
|
||||
|
||||
|
||||
l3g4200d->status = -1;
|
||||
#if 0
|
||||
// l3g4200d_start_test(this_client);
|
||||
l3g4200d_start(client, L3G4200D_RATE_12P5);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
exit_gsensor_sysfs_init_failed:
|
||||
misc_deregister(&l3g4200d_device);
|
||||
exit_misc_device_register_l3g4200d_device_failed:
|
||||
input_unregister_device(l3g4200d->input_dev);
|
||||
exit_input_register_device_failed:
|
||||
input_free_device(l3g4200d->input_dev);
|
||||
exit_input_allocate_device_failed:
|
||||
free_irq(client->irq, l3g4200d);
|
||||
exit_kfree_pdata:
|
||||
kfree(l3g4200d->pdata);
|
||||
exit_kfree:
|
||||
exit_request_gpio_irq_failed:
|
||||
kfree(l3g4200d);
|
||||
exit_alloc_data_failed:
|
||||
;
|
||||
exit:
|
||||
mmaprintk("%s error\n",__FUNCTION__);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int __init l3g4200d_i2c_init(void)
|
||||
{
|
||||
return i2c_add_driver(&l3g4200d_driver);
|
||||
}
|
||||
|
||||
static void __exit l3g4200d_i2c_exit(void)
|
||||
{
|
||||
i2c_del_driver(&l3g4200d_driver);
|
||||
}
|
||||
|
||||
module_init(l3g4200d_i2c_init);
|
||||
module_exit(l3g4200d_i2c_exit);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,186 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/****************************************************************************************
|
||||
* File: driver/input/gsensor/lis3dh.h
|
||||
* Copyright: Copyright (C) 2012-2013 RK Corporation.
|
||||
* Author: LiBing <libing@rock-chips.com>
|
||||
* Date: 2012.03.06
|
||||
* Description: This driver use for rk29 chip extern gsensor. Use i2c IF ,the chip is
|
||||
* STMicroelectronics lis3dh.
|
||||
*****************************************************************************************/
|
||||
|
||||
#ifndef LIS3DH_H
|
||||
#define LIS3DH_H
|
||||
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#define ODR1 0x10 /* 1Hz output data rate */
|
||||
#define ODR10 0x20 /* 10Hz output data rate */
|
||||
#define ODR25 0x30 /* 25Hz output data rate */
|
||||
#define ODR50 0x40 /* 50Hz output data rate */
|
||||
#define ODR100 0x50 /* 100Hz output data rate */
|
||||
#define ODR200 0x60 /* 200Hz output data rate */
|
||||
#define ODR400 0x70 /* 400Hz output data rate */
|
||||
#define ODR1250 0x90 /* 1250Hz output data rate */
|
||||
|
||||
#define SENSITIVITY_2G 1 /** mg/LSB */
|
||||
#define SENSITIVITY_4G 2 /** mg/LSB */
|
||||
#define SENSITIVITY_8G 4 /** mg/LSB */
|
||||
#define SENSITIVITY_16G 12 /** mg/LSB */
|
||||
|
||||
#define HIGH_RESOLUTION 0x08
|
||||
|
||||
/* Accelerometer Sensor Full Scale */
|
||||
#define LIS3DH_ACC_FS_MASK 0x30
|
||||
#define LIS3DH_ACC_G_2G 0x00
|
||||
#define LIS3DH_ACC_G_4G 0x10
|
||||
#define LIS3DH_ACC_G_8G 0x20
|
||||
#define LIS3DH_ACC_G_16G 0x30
|
||||
|
||||
#define WHO_AM_I 0x0F
|
||||
#define WHOAMI_LIS3DH_ACC 0x33
|
||||
#define AXISDATA_REG 0x28
|
||||
|
||||
#define I2C_AUTO_INCREMENT 0x80
|
||||
#define I2C_RETRY_DELAY 5
|
||||
#define I2C_RETRIES 5
|
||||
|
||||
#define RESUME_ENTRIES 17
|
||||
|
||||
#define RES_CTRL_REG1 0
|
||||
#define RES_CTRL_REG2 1
|
||||
#define RES_CTRL_REG3 2
|
||||
#define RES_CTRL_REG4 3
|
||||
#define RES_CTRL_REG5 4
|
||||
#define RES_CTRL_REG6 5
|
||||
|
||||
#define RES_INT_CFG1 6
|
||||
#define RES_INT_THS1 7
|
||||
#define RES_INT_DUR1 8
|
||||
|
||||
#define RES_TT_CFG 9
|
||||
#define RES_TT_THS 10
|
||||
#define RES_TT_LIM 11
|
||||
#define RES_TT_TLAT 12
|
||||
#define RES_TT_TW 13
|
||||
#define TT_CFG 0x38 /* tap config */
|
||||
#define TT_SRC 0x39 /* tap source */
|
||||
#define TT_THS 0x3A /* tap threshold */
|
||||
#define TT_LIM 0x3B /* tap time limit */
|
||||
#define TT_TLAT 0x3C /* tap time latency */
|
||||
#define TT_TW 0x3D /* tap time window */
|
||||
|
||||
#define RES_TEMP_CFG_REG 14
|
||||
#define RES_REFERENCE_REG 15
|
||||
#define RES_FIFO_CTRL_REG 16
|
||||
|
||||
#define CTRL_REG1 0x20 /* control reg 1 */
|
||||
#define CTRL_REG2 0x21 /* control reg 2 */
|
||||
#define CTRL_REG3 0x22 /* control reg 3 */
|
||||
#define CTRL_REG4 0x23 /* control reg 4 */
|
||||
#define CTRL_REG5 0x24 /* control reg 5 */
|
||||
#define CTRL_REG6 0x25 /* control reg 6 */
|
||||
|
||||
#define TEMP_CFG_REG 0x1F /* temper sens control reg */
|
||||
|
||||
#define FIFO_CTRL_REG 0x2E /* FiFo control reg */
|
||||
|
||||
#define INT_CFG1 0x30 /* interrupt 1 config */
|
||||
#define INT_SRC1 0x31 /* interrupt 1 source */
|
||||
#define INT_THS1 0x32 /* interrupt 1 threshold */
|
||||
#define INT_DUR1 0x33 /* interrupt 1 duration */
|
||||
|
||||
/* Default register settings */
|
||||
#define RBUFF_SIZE 12 /* Rx buffer size */
|
||||
#define STIO 0xA1
|
||||
|
||||
/* IOCTLs for LIS3DH library */
|
||||
#define ST_IOCTL_INIT _IO(STIO, 0x01)
|
||||
#define ST_IOCTL_RESET _IO(STIO, 0x04)
|
||||
#define ST_IOCTL_CLOSE _IO(STIO, 0x02)
|
||||
#define ST_IOCTL_START _IO(STIO, 0x03)
|
||||
#define ST_IOCTL_GETDATA _IOR(STIO, 0x08, char[RBUFF_SIZE+1])
|
||||
|
||||
/* IOCTLs for APPs */
|
||||
#define ST_IOCTL_APP_SET_RATE _IOW(STIO, 0x10, char)
|
||||
|
||||
/*rate*/
|
||||
#define LIS3DH_RATE_800 0
|
||||
#define LIS3DH_RATE_400 1
|
||||
#define LIS3DH_RATE_200 2
|
||||
#define LIS3DH_RATE_100 3
|
||||
#define LIS3DH_RATE_50 4
|
||||
#define LIS3DH_RATE_12P5 5
|
||||
#define LIS3DH_RATE_6P25 6
|
||||
#define LIS3DH_RATE_1P56 7
|
||||
#define LIS3DH_RATE_SHIFT 3
|
||||
#define LIS3DH_ASLP_RATE_50 0
|
||||
#define LIS3DH_ASLP_RATE_12P5 1
|
||||
#define LIS3DH_ASLP_RATE_6P25 2
|
||||
#define LIS3DH_ASLP_RATE_1P56 3
|
||||
#define LIS3DH_ASLP_RATE_SHIFT 6
|
||||
|
||||
#define ACTIVE_MASK 1
|
||||
#define FREAD_MASK 2
|
||||
|
||||
/*status*/
|
||||
#define LIS3DH_SUSPEND 2
|
||||
#define LIS3DH_OPEN 1
|
||||
#define LIS3DH_CLOSE 0
|
||||
#define LIS3DH_SPEED 200 * 1000
|
||||
|
||||
#define LIS3DH_ACC_ENABLE_ALL_AXES 0x07
|
||||
|
||||
#define LIS3DH_RANGE 2000000
|
||||
#define LIS3DH_PRECISION 16 //8bit data
|
||||
#define LIS3DH_BOUNDARY (0x1 << (LIS3DH_PRECISION - 1))
|
||||
#define LIS3DH_GRAVITY_STEP LIS3DH_RANGE / LIS3DH_BOUNDARY //2g full scale range
|
||||
|
||||
#ifdef CONFIG_HAS_EARLYSUSPEND
|
||||
static struct early_suspend lis3dh_early_suspend;
|
||||
#endif
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int cutoff_ms;
|
||||
unsigned int mask;
|
||||
}lis3dh_acc_odr_table[] =
|
||||
{
|
||||
{ 1, ODR1250},
|
||||
{ 3, ODR400 },
|
||||
{ 5, ODR200 },
|
||||
{ 10, ODR100 },
|
||||
{ 20, ODR50 },
|
||||
{ 40, ODR25 },
|
||||
{ 100, ODR10 },
|
||||
{ 1000, ODR1 },
|
||||
};
|
||||
|
||||
struct lis3dh_axis {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
};
|
||||
|
||||
|
||||
struct lis3dh_data {
|
||||
char status;
|
||||
char curr_tate;
|
||||
|
||||
unsigned int poll_interval;
|
||||
unsigned int min_interval;
|
||||
|
||||
struct input_dev *input_dev;
|
||||
struct i2c_client *client;
|
||||
struct work_struct work;
|
||||
struct delayed_work delaywork; /*report second event*/
|
||||
struct lis3dh_axis sense_data;
|
||||
struct mutex sense_data_mutex;
|
||||
struct mutex operation_mutex;
|
||||
|
||||
atomic_t data_ready;
|
||||
wait_queue_head_t data_ready_wq;
|
||||
int start_count;
|
||||
u8 resume_state[RESUME_ENTRIES];
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,137 +0,0 @@
|
||||
|
||||
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
|
||||
*
|
||||
* File Name : lis3dh_misc.h
|
||||
* Authors : MH - C&I BU - Application Team
|
||||
* : Carmine Iascone (carmine.iascone@st.com)
|
||||
* : Matteo Dameno (matteo.dameno@st.com)
|
||||
* Version : V 1.0.5
|
||||
* Date : 26/08/2010
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* THE PRESENT SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
|
||||
* OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, FOR THE SOLE
|
||||
* PURPOSE TO SUPPORT YOUR APPLICATION DEVELOPMENT.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* THIS SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
/*******************************************************************************
|
||||
Version History.
|
||||
|
||||
Revision 1-0-0 05/11/2009
|
||||
First Release
|
||||
Revision 1-0-1 26/01/2010
|
||||
Linux K&R Compliant Release
|
||||
Revision 1-0-5 16/08/2010
|
||||
Interrupt Management
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __LIS3DH_H__
|
||||
#define __LIS3DH_H__
|
||||
|
||||
#include <linux/ioctl.h> /* For IOCTL macros */
|
||||
#include <linux/input.h>
|
||||
|
||||
#define SAD0L 0x00
|
||||
#define SAD0H 0x01
|
||||
#define LIS3DH_ACC_I2C_SADROOT 0x0C
|
||||
#define LIS3DH_ACC_I2C_SAD_L ((LIS3DH_ACC_I2C_SADROOT<<1)|SAD0L)
|
||||
#define LIS3DH_ACC_I2C_SAD_H ((LIS3DH_ACC_I2C_SADROOT<<1)|SAD0H)
|
||||
#define LIS3DH_ACC_DEV_NAME "lis3dh_acc_misc"
|
||||
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_BASE 77
|
||||
/** The following define the IOCTL command values via the ioctl macros */
|
||||
#define LIS3DH_ACC_IOCTL_SET_DELAY _IOW(LIS3DH_ACC_IOCTL_BASE, 0, int)
|
||||
#define LIS3DH_ACC_IOCTL_GET_DELAY _IOR(LIS3DH_ACC_IOCTL_BASE, 1, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_ENABLE _IOW(LIS3DH_ACC_IOCTL_BASE, 2, int)
|
||||
#define LIS3DH_ACC_IOCTL_GET_ENABLE _IOR(LIS3DH_ACC_IOCTL_BASE, 3, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_FULLSCALE _IOW(LIS3DH_ACC_IOCTL_BASE, 4, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_G_RANGE LIS3DH_ACC_IOCTL_SET_FULLSCALE
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_SET_CTRL_REG3 _IOW(LIS3DH_ACC_IOCTL_BASE, 6, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_CTRL_REG6 _IOW(LIS3DH_ACC_IOCTL_BASE, 7, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_DURATION1 _IOW(LIS3DH_ACC_IOCTL_BASE, 8, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_THRESHOLD1 _IOW(LIS3DH_ACC_IOCTL_BASE, 9, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_CONFIG1 _IOW(LIS3DH_ACC_IOCTL_BASE, 10, int)
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_SET_DURATION2 _IOW(LIS3DH_ACC_IOCTL_BASE, 11, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_THRESHOLD2 _IOW(LIS3DH_ACC_IOCTL_BASE, 12, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_CONFIG2 _IOW(LIS3DH_ACC_IOCTL_BASE, 13, int)
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_GET_SOURCE1 _IOW(LIS3DH_ACC_IOCTL_BASE, 14, int)
|
||||
#define LIS3DH_ACC_IOCTL_GET_SOURCE2 _IOW(LIS3DH_ACC_IOCTL_BASE, 15, int)
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_GET_TAP_SOURCE _IOW(LIS3DH_ACC_IOCTL_BASE, 16, int)
|
||||
|
||||
#define LIS3DH_ACC_IOCTL_SET_TAP_TW _IOW(LIS3DH_ACC_IOCTL_BASE, 17, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_TAP_CFG _IOW(LIS3DH_ACC_IOCTL_BASE, 18, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_TAP_TLIM _IOW(LIS3DH_ACC_IOCTL_BASE, 19, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_TAP_THS _IOW(LIS3DH_ACC_IOCTL_BASE, 20, int)
|
||||
#define LIS3DH_ACC_IOCTL_SET_TAP_TLAT _IOW(LIS3DH_ACC_IOCTL_BASE, 21, int)
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************/
|
||||
/* Accelerometer defines section */
|
||||
/************************************************/
|
||||
|
||||
/* Accelerometer Sensor Full Scale */
|
||||
#define LIS3DH_ACC_FS_MASK 0x30
|
||||
#define LIS3DH_ACC_G_2G 0x00
|
||||
#define LIS3DH_ACC_G_4G 0x10
|
||||
#define LIS3DH_ACC_G_8G 0x20
|
||||
#define LIS3DH_ACC_G_16G 0x30
|
||||
|
||||
|
||||
/* Accelerometer Sensor Operating Mode */
|
||||
#define LIS3DH_ACC_ENABLE 0x01
|
||||
#define LIS3DH_ACC_DISABLE 0x00
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __KERNEL__
|
||||
struct lis3dh_acc_platform_data {
|
||||
int poll_interval;
|
||||
int min_interval;
|
||||
|
||||
u8 g_range;
|
||||
|
||||
u8 axis_map_x;
|
||||
u8 axis_map_y;
|
||||
u8 axis_map_z;
|
||||
|
||||
u8 negate_x;
|
||||
u8 negate_y;
|
||||
u8 negate_z;
|
||||
|
||||
int (*init)(void);
|
||||
void (*exit)(void);
|
||||
int (*power_on)(void);
|
||||
int (*power_off)(void);
|
||||
|
||||
int gpio_int1;
|
||||
int gpio_int2;
|
||||
|
||||
};
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif /* __LIS3DH_H__ */
|
||||
|
||||
|
||||
|
||||
@@ -1,639 +0,0 @@
|
||||
/* drivers/i2c/chips/mma7660.c - mma7660 compass driver
|
||||
*
|
||||
* Copyright (C) 2007-2008 HTC Corporation.
|
||||
* Author: Hou-Kun Chen <houkun.chen@gmail.com>
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/mma7660.h>
|
||||
#include <mach/gpio.h>
|
||||
#include <mach/board.h>
|
||||
#ifdef CONFIG_ANDROID_POWER
|
||||
#include <linux/android_power.h>
|
||||
#endif
|
||||
|
||||
//#define RK28_PRINT
|
||||
//#include <asm/arch/rk28_debug.h>
|
||||
#if 0
|
||||
#define rk28printk(x...) printk(x)
|
||||
#else
|
||||
#define rk28printk(x...)
|
||||
#endif
|
||||
static int mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id);
|
||||
|
||||
#define MMA7660_SPEED 200 * 1000
|
||||
|
||||
/* Addresses to scan -- protected by sense_data_mutex */
|
||||
//static char sense_data[RBUFF_SIZE + 1];
|
||||
static struct i2c_client *this_client;
|
||||
static struct miscdevice mma7660_device;
|
||||
|
||||
static DECLARE_WAIT_QUEUE_HEAD(data_ready_wq);
|
||||
|
||||
#ifdef CONFIG_ANDROID_POWER
|
||||
static android_early_suspend_t mma7660_early_suspend;
|
||||
#endif
|
||||
static int revision = -1;
|
||||
/* AKM HW info */
|
||||
static ssize_t gsensor_vendor_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
|
||||
sprintf(buf, "%#x\n", revision);
|
||||
ret = strlen(buf) + 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(vendor, 0444, gsensor_vendor_show, NULL);
|
||||
|
||||
static struct kobject *android_gsensor_kobj;
|
||||
|
||||
static int gsensor_sysfs_init(void)
|
||||
{
|
||||
int ret ;
|
||||
|
||||
android_gsensor_kobj = kobject_create_and_add("android_gsensor", NULL);
|
||||
if (android_gsensor_kobj == NULL) {
|
||||
rk28printk(KERN_ERR
|
||||
"MMA7660 gsensor_sysfs_init:"\
|
||||
"subsystem_register failed\n");
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = sysfs_create_file(android_gsensor_kobj, &dev_attr_vendor.attr);
|
||||
if (ret) {
|
||||
rk28printk(KERN_ERR
|
||||
"MMA7660 gsensor_sysfs_init:"\
|
||||
"sysfs_create_group failed\n");
|
||||
goto err4;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
err4:
|
||||
kobject_del(android_gsensor_kobj);
|
||||
err:
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static int mma7660_rx_data(struct i2c_client *client, char *rxData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = rxData[0];
|
||||
ret = i2c_master_reg8_recv(client, reg, rxData, length, MMA7660_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
static int mma7660_tx_data(struct i2c_client *client, char *txData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = txData[0];
|
||||
ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, MMA7660_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
static int mma7660_set_rate(struct i2c_client *client, char rate)
|
||||
{
|
||||
char buffer[2];
|
||||
int ret = 0;
|
||||
|
||||
if (rate > 128)
|
||||
return -EINVAL;
|
||||
rk28printk("[ZWP]%s,rate = %d\n",__FUNCTION__,rate);
|
||||
//<2F><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>,<2C><>ÿRawDataLength<74>β<EFBFBD><CEB2>ϱ<EFBFBD>һ<EFBFBD><D2BB>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gsensor<6F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(rate > 2)
|
||||
rate -= 2;
|
||||
rk28printk("[ZWP]%s,new rate = %d\n",__FUNCTION__,rate);
|
||||
|
||||
/*
|
||||
for (i = 0; i < 7; i++) {
|
||||
if (rate & (0x1 << i))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
buffer[0] = MMA7660_REG_SR;
|
||||
buffer[1] = 0xf8 | (0x07 & (~i));
|
||||
*/
|
||||
buffer[0] = MMA7660_REG_SR;
|
||||
buffer[1] = 0xf8 | (0x07 & rate);
|
||||
|
||||
ret = mma7660_tx_data(client, &(buffer[0]), 2);
|
||||
ret = mma7660_rx_data(client, &(buffer[0]), 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mma7660_start_dev(struct i2c_client *client, char rate)
|
||||
{
|
||||
char buffer[MMA7660_REG_LEN];
|
||||
int ret = 0;
|
||||
|
||||
buffer[0] = MMA7660_REG_INTSU;
|
||||
buffer[1] = 0x10; //0x10; modify by zhao
|
||||
ret = mma7660_tx_data(client, &buffer[0], 2);
|
||||
ret = mma7660_rx_data(client, &buffer[0], 1);
|
||||
|
||||
ret = mma7660_set_rate(client, rate);
|
||||
|
||||
buffer[0] = MMA7660_REG_MODE;
|
||||
buffer[1] = 0x01;
|
||||
ret = mma7660_tx_data(client, &buffer[0], 2);
|
||||
ret = mma7660_rx_data(client, &buffer[0], 1);
|
||||
|
||||
enable_irq(client->irq);
|
||||
rk28printk("\n----------------------------mma7660_start------------------------\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mma7660_start(struct i2c_client *client, char rate)
|
||||
{
|
||||
struct mma7660_data *mma7660 = (struct mma7660_data *)i2c_get_clientdata(client);
|
||||
|
||||
if (mma7660->status == MMA7660_OPEN) {
|
||||
return 0;
|
||||
}
|
||||
mma7660->status = MMA7660_OPEN;
|
||||
return mma7660_start_dev(client, rate);
|
||||
}
|
||||
|
||||
static int mma7660_close_dev(struct i2c_client *client)
|
||||
{
|
||||
char buffer[2];
|
||||
|
||||
disable_irq_nosync(client->irq);
|
||||
|
||||
buffer[0] = MMA7660_REG_MODE;
|
||||
buffer[1] = 0x00;
|
||||
|
||||
return mma7660_tx_data(client, buffer, 2);
|
||||
}
|
||||
|
||||
static int mma7660_close(struct i2c_client *client)
|
||||
{
|
||||
struct mma7660_data *mma7660 = (struct mma7660_data *)i2c_get_clientdata(client);
|
||||
|
||||
mma7660->status = MMA7660_CLOSE;
|
||||
|
||||
return mma7660_close_dev(client);
|
||||
}
|
||||
|
||||
static int mma7660_reset_rate(struct i2c_client *client, char rate)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
rk28printk("\n----------------------------mma7660_reset_rate------------------------\n");
|
||||
|
||||
ret = mma7660_close_dev(client);
|
||||
ret = mma7660_start_dev(client, rate);
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static inline int mma7660_convert_to_int(char value)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (value < MMA7660_BOUNDARY) {
|
||||
result = value * MMA7660_GRAVITY_STEP;
|
||||
} else {
|
||||
result = ~(((~value & 0x3f) + 1)* MMA7660_GRAVITY_STEP) + 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void mma7660_report_value(struct i2c_client *client, struct mma7660_axis *axis)
|
||||
{
|
||||
struct mma7660_data *mma7660 = i2c_get_clientdata(client);
|
||||
//struct mma7660_axis *axis = (struct mma7660_axis *)rbuf;
|
||||
|
||||
/* Report acceleration sensor information */
|
||||
input_report_abs(mma7660->input_dev, ABS_X, axis->x);
|
||||
input_report_abs(mma7660->input_dev, ABS_Y, axis->y);
|
||||
input_report_abs(mma7660->input_dev, ABS_Z, axis->z);
|
||||
input_sync(mma7660->input_dev);
|
||||
rk28printk("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
}
|
||||
|
||||
#define RawDataLength 4
|
||||
int RawDataNum;
|
||||
int Xaverage, Yaverage, Zaverage;
|
||||
|
||||
static int mma7660_get_data(struct i2c_client *client)
|
||||
{
|
||||
char buffer[3];
|
||||
int ret;
|
||||
struct mma7660_axis axis;
|
||||
//struct rk2818_gs_platform_data *pdata = client->dev.platform_data;
|
||||
do {
|
||||
memset(buffer, 0, 3);
|
||||
buffer[0] = MMA7660_REG_X_OUT;
|
||||
ret = mma7660_rx_data(client, &buffer[0], 3);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} while ((buffer[0] & 0x40) || (buffer[1] & 0x40) || (buffer[2] & 0x40));
|
||||
|
||||
axis.x = mma7660_convert_to_int(buffer[MMA7660_REG_X_OUT]);
|
||||
axis.y = -mma7660_convert_to_int(buffer[MMA7660_REG_Y_OUT]);
|
||||
axis.z = -mma7660_convert_to_int(buffer[MMA7660_REG_Z_OUT]);
|
||||
/*
|
||||
if(pdata->swap_xy)
|
||||
{
|
||||
axis.y = -axis.y;
|
||||
swap(axis.x,axis.y);
|
||||
}
|
||||
*/
|
||||
//<2F><><EFBFBD><EFBFBD>RawDataLength<74><68>ֵ<EFBFBD><D6B5>ƽ<EFBFBD><C6BD>ֵ
|
||||
Xaverage += axis.x;
|
||||
Yaverage += axis.y;
|
||||
Zaverage += axis.z;
|
||||
rk28printk( "%s: ------------------mma7660_GetData axis = %d %d %d,average=%d %d %d--------------\n",
|
||||
__func__, axis.x, axis.y, axis.z,Xaverage,Yaverage,Zaverage);
|
||||
|
||||
if((++RawDataNum)>=RawDataLength){
|
||||
RawDataNum = 0;
|
||||
axis.x = Xaverage/RawDataLength;
|
||||
axis.y = Yaverage/RawDataLength;
|
||||
axis.z = Zaverage/RawDataLength;
|
||||
mma7660_report_value(client, &axis);
|
||||
Xaverage = Yaverage = Zaverage = 0;
|
||||
}
|
||||
#if 0
|
||||
// rk28printk( "%s: ------------------mma7660_GetData axis = %d %d %d--------------\n",
|
||||
// __func__, axis.x, axis.y, axis.z);
|
||||
|
||||
//memcpy(sense_data, &axis, sizeof(axis));
|
||||
mma7660_report_value(client, &axis);
|
||||
//atomic_set(&data_ready, 0);
|
||||
//wake_up(&data_ready_wq);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static int mma7660_trans_buff(char *rbuf, int size)
|
||||
{
|
||||
//wait_event_interruptible_timeout(data_ready_wq,
|
||||
// atomic_read(&data_ready), 1000);
|
||||
wait_event_interruptible(data_ready_wq,
|
||||
atomic_read(&data_ready));
|
||||
|
||||
atomic_set(&data_ready, 0);
|
||||
memcpy(rbuf, &sense_data[0], size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
static int mma7660_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;//nonseekable_open(inode, file);
|
||||
}
|
||||
|
||||
static int mma7660_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long mma7660_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
|
||||
void __user *argp = (void __user *)arg;
|
||||
char msg[RBUFF_SIZE + 1];
|
||||
int ret = -1;
|
||||
char rate;
|
||||
struct i2c_client *client = container_of(mma7660_device.parent, struct i2c_client, dev);
|
||||
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_APP_SET_RATE:
|
||||
if (copy_from_user(&rate, argp, sizeof(rate)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_START:
|
||||
ret = mma7660_start(client, MMA7660_RATE_32);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case ECS_IOCTL_CLOSE:
|
||||
ret = mma7660_close(client);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case ECS_IOCTL_APP_SET_RATE:
|
||||
ret = mma7660_reset_rate(client, rate);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
/*
|
||||
case ECS_IOCTL_GETDATA:
|
||||
ret = mma7660_trans_buff(msg, RBUFF_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case ECS_IOCTL_GETDATA:
|
||||
if (copy_to_user(argp, &msg, sizeof(msg)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mma7660_work_func(struct work_struct *work)
|
||||
{
|
||||
struct mma7660_data *mma7660 = container_of(work, struct mma7660_data, work);
|
||||
struct i2c_client *client = mma7660->client;
|
||||
|
||||
if (mma7660_get_data(client) < 0)
|
||||
rk28printk(KERN_ERR "MMA7660 mma_work_func: Get data failed\n");
|
||||
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
static void mma7660_delaywork_func(struct work_struct *work)
|
||||
{
|
||||
struct delayed_work *delaywork = container_of(work, struct delayed_work, work);
|
||||
struct mma7660_data *mma7660 = container_of(delaywork, struct mma7660_data, delaywork);
|
||||
struct i2c_client *client = mma7660->client;
|
||||
|
||||
if (mma7660_get_data(client) < 0)
|
||||
rk28printk(KERN_ERR "MMA7660 mma_work_func: Get data failed\n");
|
||||
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
static irqreturn_t mma7660_interrupt(int irq, void *dev_id)
|
||||
{
|
||||
struct mma7660_data *mma7660 = (struct mma7660_data *)dev_id;
|
||||
|
||||
disable_irq_nosync(irq);
|
||||
schedule_delayed_work(&mma7660->delaywork, msecs_to_jiffies(30));
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static struct file_operations mma7660_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = mma7660_open,
|
||||
.release = mma7660_release,
|
||||
.unlocked_ioctl = mma7660_ioctl,
|
||||
};
|
||||
|
||||
static struct miscdevice mma7660_device = {
|
||||
.minor = MISC_DYNAMIC_MINOR,
|
||||
.name = "mma8452_daemon",//"mma7660_daemon",
|
||||
.fops = &mma7660_fops,
|
||||
};
|
||||
|
||||
static int mma7660_remove(struct i2c_client *client)
|
||||
{
|
||||
struct mma7660_data *mma7660 = i2c_get_clientdata(client);
|
||||
|
||||
misc_deregister(&mma7660_device);
|
||||
input_unregister_device(mma7660->input_dev);
|
||||
input_free_device(mma7660->input_dev);
|
||||
free_irq(client->irq, mma7660);
|
||||
kfree(mma7660);
|
||||
#ifdef CONFIG_ANDROID_POWER
|
||||
android_unregister_early_suspend(&mma7660_early_suspend);
|
||||
#endif
|
||||
this_client = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ANDROID_POWER
|
||||
static int mma7660_suspend(android_early_suspend_t *h)
|
||||
{
|
||||
struct i2c_client *client = container_of(mma7660_device.parent, struct i2c_client, dev);
|
||||
rk28printk("Gsensor mma7760 enter suspend\n");
|
||||
return mma7660_close_dev(client);
|
||||
}
|
||||
|
||||
static int mma7660_resume(android_early_suspend_t *h)
|
||||
{
|
||||
struct i2c_client *client = container_of(mma7660_device.parent, struct i2c_client, dev);
|
||||
struct mma7660_data *mma7660 = (struct mma7660_data *)i2c_get_clientdata(client);
|
||||
rk28printk("Gsensor mma7760 resume!!\n");
|
||||
return mma7660_start_dev(mma7660->curr_tate);
|
||||
}
|
||||
#else
|
||||
static int mma7660_suspend(struct i2c_client *client, pm_message_t mesg)
|
||||
{
|
||||
rk28printk("Gsensor mma7760 enter 2 level suspend\n");
|
||||
return mma7660_close_dev(client);
|
||||
}
|
||||
static int mma7660_resume(struct i2c_client *client)
|
||||
{
|
||||
struct mma7660_data *mma7660 = (struct mma7660_data *)i2c_get_clientdata(client);
|
||||
rk28printk("Gsensor mma7760 2 level resume!!\n");
|
||||
return mma7660_start_dev(client, mma7660->curr_tate);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct i2c_device_id mma7660_id[] = {
|
||||
{"gs_mma7660", 0},
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct i2c_driver mma7660_driver = {
|
||||
.driver = {
|
||||
.name = "gs_mma7660",
|
||||
},
|
||||
.id_table = mma7660_id,
|
||||
.probe = mma7660_probe,
|
||||
.remove = __devexit_p(mma7660_remove),
|
||||
#ifndef CONFIG_ANDROID_POWER
|
||||
.suspend = &mma7660_suspend,
|
||||
.resume = &mma7660_resume,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static int mma7660_init_client(struct i2c_client *client)
|
||||
{
|
||||
struct mma7660_data *mma7660;
|
||||
int ret;
|
||||
mma7660 = i2c_get_clientdata(client);
|
||||
rk28printk("gpio_to_irq(%d) is %d\n",client->irq,gpio_to_irq(client->irq));
|
||||
if ( !gpio_is_valid(client->irq)) {
|
||||
rk28printk("+++++++++++gpio_is_invalid\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = gpio_request(client->irq, "mma7660_int");
|
||||
if (ret) {
|
||||
rk28printk( "failed to request mma7990_trig GPIO%d\n",gpio_to_irq(client->irq));
|
||||
return ret;
|
||||
}
|
||||
ret = gpio_direction_input(client->irq);
|
||||
if (ret) {
|
||||
rk28printk("failed to set mma7990_trig GPIO gpio input\n");
|
||||
return ret;
|
||||
}
|
||||
gpio_pull_updown(client->irq, GPIOPullUp);
|
||||
client->irq = gpio_to_irq(client->irq);
|
||||
ret = request_irq(client->irq, mma7660_interrupt, IRQF_TRIGGER_LOW, client->dev.driver->name, mma7660);
|
||||
rk28printk("request irq is %d,ret is 0x%x\n",client->irq,ret);
|
||||
if (ret ) {
|
||||
rk28printk(KERN_ERR "mma7660_init_client: request irq failed,ret is %d\n",ret);
|
||||
return ret;
|
||||
}
|
||||
disable_irq(client->irq);
|
||||
init_waitqueue_head(&data_ready_wq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct mma7660_data *mma7660;
|
||||
int err;
|
||||
|
||||
Xaverage = Yaverage = Zaverage = RawDataNum = 0;
|
||||
|
||||
mma7660 = kzalloc(sizeof(struct mma7660_data), GFP_KERNEL);
|
||||
if (!mma7660) {
|
||||
rk28printk("[mma7660]:alloc data failed.\n");
|
||||
err = -ENOMEM;
|
||||
goto exit_alloc_data_failed;
|
||||
}
|
||||
|
||||
INIT_WORK(&mma7660->work, mma7660_work_func);
|
||||
INIT_DELAYED_WORK(&mma7660->delaywork, mma7660_delaywork_func);
|
||||
|
||||
mma7660->client = client;
|
||||
//mma7660->swap_xy =
|
||||
i2c_set_clientdata(client, mma7660);
|
||||
|
||||
this_client = client;
|
||||
|
||||
err = mma7660_init_client(client);
|
||||
if (err < 0) {
|
||||
rk28printk(KERN_ERR
|
||||
"mma7660_probe: mma7660_init_client failed\n");
|
||||
goto exit_request_gpio_irq_failed;
|
||||
}
|
||||
|
||||
mma7660->input_dev = input_allocate_device();
|
||||
if (!mma7660->input_dev) {
|
||||
err = -ENOMEM;
|
||||
rk28printk(KERN_ERR
|
||||
"mma7660_probe: Failed to allocate input device\n");
|
||||
goto exit_input_allocate_device_failed;
|
||||
}
|
||||
|
||||
set_bit(EV_ABS, mma7660->input_dev->evbit);
|
||||
|
||||
/* x-axis acceleration */
|
||||
input_set_abs_params(mma7660->input_dev, ABS_X, -MMA7660_RANGE, MMA7660_RANGE, 0, 0);
|
||||
/* y-axis acceleration */
|
||||
input_set_abs_params(mma7660->input_dev, ABS_Y, -MMA7660_RANGE, MMA7660_RANGE, 0, 0);
|
||||
/* z-axis acceleration */
|
||||
input_set_abs_params(mma7660->input_dev, ABS_Z, -MMA7660_RANGE, MMA7660_RANGE, 0, 0);
|
||||
|
||||
mma7660->input_dev->name = "compass";
|
||||
mma7660->input_dev->dev.parent = &client->dev;
|
||||
|
||||
err = input_register_device(mma7660->input_dev);
|
||||
if (err < 0) {
|
||||
rk28printk(KERN_ERR
|
||||
"mma7660_probe: Unable to register input device: %s\n",
|
||||
mma7660->input_dev->name);
|
||||
goto exit_input_register_device_failed;
|
||||
}
|
||||
|
||||
mma7660_device.parent = &client->dev;
|
||||
err = misc_register(&mma7660_device);
|
||||
if (err < 0) {
|
||||
rk28printk(KERN_ERR
|
||||
"mma7660_probe: mmad_device register failed\n");
|
||||
goto exit_misc_device_register_mma7660_device_failed;
|
||||
}
|
||||
|
||||
err = gsensor_sysfs_init();
|
||||
if (err < 0) {
|
||||
rk28printk(KERN_ERR
|
||||
"mma7660_probe: gsensor sysfs init failed\n");
|
||||
goto exit_gsensor_sysfs_init_failed;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ANDROID_POWER
|
||||
mma7660_early_suspend.suspend = mma7660_suspend;
|
||||
mma7660_early_suspend.resume = mma7660_resume;
|
||||
mma7660_early_suspend.level = 0x2;
|
||||
android_register_early_suspend(&mma7660_early_suspend);
|
||||
#endif
|
||||
rk28printk(KERN_INFO "mma7660 probe ok\n");
|
||||
mma7660->status = -1;
|
||||
#if 0
|
||||
mma7660_start(client, MMA7660_RATE_32);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
exit_gsensor_sysfs_init_failed:
|
||||
misc_deregister(&mma7660_device);
|
||||
exit_misc_device_register_mma7660_device_failed:
|
||||
input_unregister_device(mma7660->input_dev);
|
||||
exit_input_register_device_failed:
|
||||
input_free_device(mma7660->input_dev);
|
||||
exit_input_allocate_device_failed:
|
||||
free_irq(client->irq, mma7660);
|
||||
exit_request_gpio_irq_failed:
|
||||
kfree(mma7660);
|
||||
exit_alloc_data_failed:
|
||||
;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int __init mma7660_i2c_init(void)
|
||||
{
|
||||
return i2c_add_driver(&mma7660_driver);
|
||||
}
|
||||
|
||||
static void __exit mma7660_i2c_exit(void)
|
||||
{
|
||||
i2c_del_driver(&mma7660_driver);
|
||||
}
|
||||
|
||||
module_init(mma7660_i2c_init);
|
||||
module_exit(mma7660_i2c_exit);
|
||||
|
||||
|
||||
|
||||
@@ -1,833 +0,0 @@
|
||||
/* drivers/i2c/chips/mma8452.c - mma8452 compass driver
|
||||
*
|
||||
* Copyright (C) 2007-2008 HTC Corporation.
|
||||
* Author: Hou-Kun Chen <houkun.chen@gmail.com>
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/atomic.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/mma8452.h>
|
||||
#include <mach/gpio.h>
|
||||
#include <mach/board.h>
|
||||
|
||||
#if 0
|
||||
#define mmaprintk(x...) printk(x)
|
||||
#else
|
||||
#define mmaprintk(x...)
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define mmaprintkd(x...) printk(x)
|
||||
#else
|
||||
#define mmaprintkd(x...)
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define mmaprintkf(x...) printk(x)
|
||||
#else
|
||||
#define mmaprintkf(x...)
|
||||
#endif
|
||||
|
||||
static int mma8452_probe(struct i2c_client *client, const struct i2c_device_id *id);
|
||||
|
||||
#define MMA8452_SPEED 200 * 1000
|
||||
#define MMA8451_DEVID 0x1a
|
||||
#define MMA8452_DEVID 0x2a
|
||||
#define MMA8453_DEVID 0x3a
|
||||
/* Addresses to scan -- protected by sense_data_mutex */
|
||||
//static char sense_data[RBUFF_SIZE + 1];
|
||||
static struct i2c_client *this_client;
|
||||
static struct miscdevice mma8452_device;
|
||||
|
||||
static DECLARE_WAIT_QUEUE_HEAD(data_ready_wq);
|
||||
|
||||
static int revision = -1;
|
||||
static const char* vendor = "Freescale Semiconductor";
|
||||
static char devid;
|
||||
|
||||
|
||||
typedef char status_t;
|
||||
/*status*/
|
||||
#define MMA8452_OPEN 1
|
||||
#define MMA8452_CLOSE 0
|
||||
|
||||
struct mma8452_data {
|
||||
status_t status;
|
||||
char curr_tate;
|
||||
struct input_dev *input_dev;
|
||||
struct i2c_client *client;
|
||||
struct work_struct work;
|
||||
struct delayed_work delaywork; /*report second event*/
|
||||
|
||||
struct mma8452_axis sense_data;
|
||||
struct mutex sense_data_mutex;
|
||||
atomic_t data_ready;
|
||||
wait_queue_head_t data_ready_wq;
|
||||
|
||||
int start_count;
|
||||
struct mutex operation_mutex;
|
||||
};
|
||||
|
||||
/* AKM HW info */
|
||||
static ssize_t gsensor_vendor_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
|
||||
// sprintf(buf, "%#x\n", revision);
|
||||
sprintf(buf, "%s.\n", vendor);
|
||||
ret = strlen(buf) + 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(vendor, 0444, gsensor_vendor_show, NULL);
|
||||
|
||||
static struct kobject *android_gsensor_kobj;
|
||||
|
||||
static int gsensor_sysfs_init(void)
|
||||
{
|
||||
int ret ;
|
||||
|
||||
android_gsensor_kobj = kobject_create_and_add("android_gsensor", NULL);
|
||||
if (android_gsensor_kobj == NULL) {
|
||||
mmaprintk(KERN_ERR
|
||||
"MMA8452 gsensor_sysfs_init:"\
|
||||
"subsystem_register failed\n");
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = sysfs_create_file(android_gsensor_kobj, &dev_attr_vendor.attr); // "vendor"
|
||||
if (ret) {
|
||||
mmaprintk(KERN_ERR
|
||||
"MMA8452 gsensor_sysfs_init:"\
|
||||
"sysfs_create_group failed\n");
|
||||
goto err4;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
err4:
|
||||
kobject_del(android_gsensor_kobj);
|
||||
err:
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static int mma8452_rx_data(struct i2c_client *client, char *rxData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = rxData[0];
|
||||
ret = i2c_master_reg8_recv(client, reg, rxData, length, MMA8452_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
static int mma8452_tx_data(struct i2c_client *client, char *txData, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
char reg = txData[0];
|
||||
ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, MMA8452_SPEED);
|
||||
return (ret > 0)? 0 : ret;
|
||||
}
|
||||
|
||||
static char mma845x_read_reg(struct i2c_client *client,int addr)
|
||||
{
|
||||
char tmp;
|
||||
int ret = 0;
|
||||
|
||||
tmp = addr;
|
||||
// ret = mma8452_tx_data(client, &tmp, 1);
|
||||
ret = mma8452_rx_data(client, &tmp, 1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int mma845x_write_reg(struct i2c_client *client,int addr,int value)
|
||||
{
|
||||
char buffer[3];
|
||||
int ret = 0;
|
||||
|
||||
buffer[0] = addr;
|
||||
buffer[1] = value;
|
||||
ret = mma8452_tx_data(client, &buffer[0], 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char mma8452_get_devid(struct i2c_client *client)
|
||||
{
|
||||
printk("mma8452 devid:%x\n",mma845x_read_reg(client,MMA8452_REG_WHO_AM_I));
|
||||
return mma845x_read_reg(client,MMA8452_REG_WHO_AM_I);
|
||||
}
|
||||
|
||||
static int mma845x_active(struct i2c_client *client,int enable)
|
||||
{
|
||||
int tmp;
|
||||
int ret = 0;
|
||||
|
||||
tmp = mma845x_read_reg(client,MMA8452_REG_CTRL_REG1);
|
||||
if(enable)
|
||||
tmp |=ACTIVE_MASK;
|
||||
else
|
||||
tmp &=~ACTIVE_MASK;
|
||||
mmaprintkd("mma845x_active %s (0x%x)\n",enable?"active":"standby",tmp);
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG1,tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mma8452_start_test(struct i2c_client *client)
|
||||
{
|
||||
int ret = 0;
|
||||
int tmp;
|
||||
|
||||
mmaprintkf("-------------------------mma8452 start test------------------------\n");
|
||||
|
||||
/* standby */
|
||||
mma845x_active(client,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
/* disable FIFO FMODE = 0*/
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_F_SETUP,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_F_SETUP:%x\n",mma845x_read_reg(client,MMA8452_REG_F_SETUP));
|
||||
|
||||
/* set full scale range to 2g */
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_XYZ_DATA_CFG,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_XYZ_DATA_CFG:%x\n",mma845x_read_reg(client,MMA8452_REG_XYZ_DATA_CFG));
|
||||
|
||||
/* set bus 8bit/14bit(FREAD = 1,FMODE = 0) ,data rate*/
|
||||
tmp = (MMA8452_RATE_12P5<< MMA8452_RATE_SHIFT) | FREAD_MASK;
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG1,tmp);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG1:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG1));
|
||||
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG3,5);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG3:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG3));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG4,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG4:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG4));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG5,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG5:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG5));
|
||||
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
mma845x_active(client,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
enable_irq(client->irq);
|
||||
msleep(50);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mma8452_start_dev(struct i2c_client *client, char rate)
|
||||
{
|
||||
int ret = 0;
|
||||
int tmp;
|
||||
struct mma8452_data *mma8452 = (struct mma8452_data *)i2c_get_clientdata(client); // mma8452_data <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> mma8452.h <20><>.
|
||||
|
||||
mmaprintkf("-------------------------mma8452 start ------------------------\n");
|
||||
/* standby */
|
||||
mma845x_active(client,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
/* disable FIFO FMODE = 0*/
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_F_SETUP,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_F_SETUP:%x\n",mma845x_read_reg(client,MMA8452_REG_F_SETUP));
|
||||
|
||||
/* set full scale range to 2g */
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_XYZ_DATA_CFG,0);
|
||||
mmaprintkd("mma8452 MMA8452_REG_XYZ_DATA_CFG:%x\n",mma845x_read_reg(client,MMA8452_REG_XYZ_DATA_CFG));
|
||||
|
||||
/* set bus 8bit/14bit(FREAD = 1,FMODE = 0) ,data rate*/
|
||||
tmp = (rate<< MMA8452_RATE_SHIFT) | FREAD_MASK;
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG1,tmp);
|
||||
mma8452->curr_tate = rate;
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG1:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG1));
|
||||
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG3,5);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG3:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG3));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG4,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG4:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG4));
|
||||
|
||||
ret = mma845x_write_reg(client,MMA8452_REG_CTRL_REG5,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_CTRL_REG5:%x\n",mma845x_read_reg(client,MMA8452_REG_CTRL_REG5));
|
||||
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
mma845x_active(client,1);
|
||||
mmaprintkd("mma8452 MMA8452_REG_SYSMOD:%x\n",mma845x_read_reg(client,MMA8452_REG_SYSMOD));
|
||||
|
||||
enable_irq(client->irq);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int mma8452_start(struct i2c_client *client, char rate)
|
||||
{
|
||||
struct mma8452_data *mma8452 = (struct mma8452_data *)i2c_get_clientdata(client);
|
||||
|
||||
mmaprintkf("%s::enter\n",__FUNCTION__);
|
||||
if (mma8452->status == MMA8452_OPEN) {
|
||||
return 0;
|
||||
}
|
||||
mma8452->status = MMA8452_OPEN;
|
||||
return mma8452_start_dev(client, rate);
|
||||
}
|
||||
|
||||
static int mma8452_close_dev(struct i2c_client *client)
|
||||
{
|
||||
disable_irq_nosync(client->irq);
|
||||
return mma845x_active(client,0);
|
||||
}
|
||||
|
||||
static int mma8452_close(struct i2c_client *client)
|
||||
{
|
||||
struct mma8452_data *mma8452 = (struct mma8452_data *)i2c_get_clientdata(client);
|
||||
mmaprintkf("%s::enter\n",__FUNCTION__);
|
||||
mma8452->status = MMA8452_CLOSE;
|
||||
|
||||
return mma8452_close_dev(client);
|
||||
}
|
||||
|
||||
static int mma8452_reset_rate(struct i2c_client *client, char rate)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mmaprintkf("\n----------------------------mma8452_reset_rate------------------------\n");
|
||||
|
||||
ret = mma8452_close_dev(client);
|
||||
ret = mma8452_start_dev(client, rate);
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static inline int mma8452_convert_to_int(const char high_byte, const char low_byte)
|
||||
{
|
||||
s64 result;
|
||||
/* enabled only if FREAD MODE */
|
||||
/*
|
||||
if (high_byte < MMA8452_BOUNDARY) {
|
||||
result = high_byte * MMA8452_GRAVITY_STEP;
|
||||
} else {
|
||||
result = ~(((~high_byte&0x7f) + 1) * MMA8452_GRAVITY_STEP) + 1;
|
||||
}
|
||||
*/
|
||||
switch (devid) {
|
||||
|
||||
case MMA8451_DEVID:
|
||||
result = ((int)high_byte << (MMA8451_PRECISION-8))
|
||||
| ((int)low_byte >> (16-MMA8451_PRECISION));
|
||||
if (result < MMA8451_BOUNDARY)
|
||||
result = result* MMA8451_GRAVITY_STEP;
|
||||
else
|
||||
result = ~( ((~result & (0x7fff>>(16-MMA8451_PRECISION)) ) + 1)
|
||||
* MMA8451_GRAVITY_STEP) + 1;
|
||||
break;
|
||||
|
||||
case MMA8452_DEVID:
|
||||
result = ((int)high_byte << (MMA8452_PRECISION-8))
|
||||
| ((int)low_byte >> (16-MMA8452_PRECISION));
|
||||
if (result < MMA8452_BOUNDARY)
|
||||
result = result* MMA8452_GRAVITY_STEP;
|
||||
else
|
||||
result = ~( ((~result & (0x7fff>>(16-MMA8452_PRECISION)) ) + 1)
|
||||
* MMA8452_GRAVITY_STEP) + 1;
|
||||
break;
|
||||
|
||||
case MMA8453_DEVID:
|
||||
result = ((int)high_byte << (MMA8453_PRECISION-8))
|
||||
| ((int)low_byte >> (16-MMA8453_PRECISION));
|
||||
if (result < MMA8453_BOUNDARY)
|
||||
result = result* MMA8453_GRAVITY_STEP;
|
||||
else
|
||||
result = ~( ((~result & (0x7fff>>(16-MMA8453_PRECISION)) ) + 1)
|
||||
* MMA8453_GRAVITY_STEP) + 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_convert_to_int: devid wasn't set correctly\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
static void mma8452_report_value(struct i2c_client *client, struct mma8452_axis *axis)
|
||||
{
|
||||
struct mma8452_data *mma8452 = i2c_get_clientdata(client);
|
||||
//struct mma8452_axis *axis = (struct mma8452_axis *)rbuf;
|
||||
|
||||
/* Report acceleration sensor information */
|
||||
input_report_abs(mma8452->input_dev, ABS_X, axis->x);
|
||||
input_report_abs(mma8452->input_dev, ABS_Y, axis->y);
|
||||
input_report_abs(mma8452->input_dev, ABS_Z, axis->z);
|
||||
input_sync(mma8452->input_dev);
|
||||
mmaprintkd("Gsensor x==%d y==%d z==%d\n",axis->x,axis->y,axis->z);
|
||||
}
|
||||
|
||||
/** <20><> <20>װ벿ִ<EBB2BF><D6B4>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ g sensor <20><><EFBFBD><EFBFBD>. */
|
||||
static int mma8452_get_data(struct i2c_client *client)
|
||||
{
|
||||
struct mma8452_data* mma8452 = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
int x,y,z;
|
||||
struct mma8452_axis axis;
|
||||
struct gsensor_platform_data *pdata = pdata = client->dev.platform_data;
|
||||
|
||||
/* enabled only if FREAD MODE */
|
||||
/*
|
||||
char buffer[3];
|
||||
do {
|
||||
memset(buffer, 0, 3);
|
||||
buffer[0] = MMA8452_REG_X_OUT_MSB;
|
||||
ret = mma8452_rx_data(client, &buffer[0], 3);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} while (0);
|
||||
|
||||
x = mma8452_convert_to_int(buffer[0],0);
|
||||
y = mma8452_convert_to_int(buffer[1],0);
|
||||
z = mma8452_convert_to_int(buffer[2],0);
|
||||
*/
|
||||
char buffer[6];
|
||||
do {
|
||||
memset(buffer, 0, 6);
|
||||
buffer[0] = MMA8452_REG_X_OUT_MSB;
|
||||
ret = mma8452_rx_data(client, &buffer[0], 6);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} while (0);
|
||||
|
||||
x = mma8452_convert_to_int(buffer[0],buffer[1]);
|
||||
y = mma8452_convert_to_int(buffer[2],buffer[3]);
|
||||
z = mma8452_convert_to_int(buffer[4],buffer[5]);
|
||||
|
||||
if (pdata->swap_xyz) {
|
||||
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;
|
||||
}
|
||||
|
||||
if(pdata->swap_xy)
|
||||
{
|
||||
axis.x = -axis.x;
|
||||
swap(axis.x,axis.y);
|
||||
}
|
||||
|
||||
mmaprintkd( "%s: ------------------mma8452_GetData axis = %d %d %d--------------\n",
|
||||
__func__, axis.x, axis.y, axis.z);
|
||||
|
||||
//memcpy(sense_data, &axis, sizeof(axis));
|
||||
mma8452_report_value(client, &axis);
|
||||
//atomic_set(&data_ready, 0);
|
||||
//wake_up(&data_ready_wq);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. */
|
||||
mutex_lock(&(mma8452->sense_data_mutex) );
|
||||
mma8452->sense_data = axis;
|
||||
mutex_unlock(&(mma8452->sense_data_mutex) );
|
||||
|
||||
/* <20><>λ data_ready */
|
||||
atomic_set(&(mma8452->data_ready), 1);
|
||||
/* <20><><EFBFBD><EFBFBD> data_ready <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ͷ. */
|
||||
wake_up(&(mma8452->data_ready_wq) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static int mma8452_trans_buff(char *rbuf, int size)
|
||||
{
|
||||
//wait_event_interruptible_timeout(data_ready_wq,
|
||||
// atomic_read(&data_ready), 1000);
|
||||
wait_event_interruptible(data_ready_wq,
|
||||
atomic_read(&data_ready));
|
||||
|
||||
atomic_set(&data_ready, 0);
|
||||
memcpy(rbuf, &sense_data[0], size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
static int mma8452_get_cached_data(struct i2c_client* client, struct mma8452_axis* sense_data)
|
||||
{
|
||||
struct mma8452_data* this = (struct mma8452_data *)i2c_get_clientdata(client);
|
||||
|
||||
wait_event_interruptible_timeout(this->data_ready_wq,
|
||||
atomic_read(&(this->data_ready) ),
|
||||
msecs_to_jiffies(1000) );
|
||||
if ( 0 == atomic_read(&(this->data_ready) ) ) {
|
||||
printk("waiting 'data_ready_wq' timed out.");
|
||||
return -1;
|
||||
}
|
||||
mutex_lock(&(this->sense_data_mutex) );
|
||||
*sense_data = this->sense_data;
|
||||
mutex_unlock(&(this->sense_data_mutex) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mma8452_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;//nonseekable_open(inode, file);
|
||||
}
|
||||
|
||||
static int mma8452_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long mma8452_ioctl( struct file *file, unsigned int cmd,unsigned long arg)
|
||||
{
|
||||
|
||||
void __user *argp = (void __user *)arg;
|
||||
// char msg[RBUFF_SIZE + 1];
|
||||
struct mma8452_axis sense_data = {0};
|
||||
int ret = -1;
|
||||
char rate;
|
||||
struct i2c_client *client = container_of(mma8452_device.parent, struct i2c_client, dev);
|
||||
struct mma8452_data* this = (struct mma8452_data *)i2c_get_clientdata(client); /* <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>. */
|
||||
|
||||
switch (cmd) {
|
||||
case MMA_IOCTL_APP_SET_RATE:
|
||||
if (copy_from_user(&rate, argp, sizeof(rate)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case MMA_IOCTL_START:
|
||||
mutex_lock(&(this->operation_mutex) );
|
||||
mmaprintkd("to perform 'MMA_IOCTL_START', former 'start_count' is %d.", this->start_count);
|
||||
(this->start_count)++;
|
||||
if ( 1 == this->start_count ) {
|
||||
atomic_set(&(this->data_ready), 0);
|
||||
if ( (ret = mma8452_start(client, MMA8452_RATE_12P5) ) < 0 ) {
|
||||
mutex_unlock(&(this->operation_mutex) );
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&(this->operation_mutex) );
|
||||
mmaprintkd("finish 'MMA_IOCTL_START', ret = %d.", ret);
|
||||
return 0;
|
||||
|
||||
case MMA_IOCTL_CLOSE:
|
||||
mutex_lock(&(this->operation_mutex) );
|
||||
mmaprintkd("to perform 'MMA_IOCTL_CLOSE', former 'start_count' is %d, PID : %d", this->start_count, get_current()->pid);
|
||||
if ( 0 == (--(this->start_count) ) ) {
|
||||
atomic_set(&(this->data_ready), 0);
|
||||
if ( (ret = mma8452_close(client) ) < 0 ) {
|
||||
mutex_unlock(&(this->operation_mutex) );
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&(this->operation_mutex) );
|
||||
return 0;
|
||||
|
||||
case MMA_IOCTL_APP_SET_RATE:
|
||||
ret = mma8452_reset_rate(client, rate);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
break;
|
||||
case MMA_IOCTL_GETDATA:
|
||||
// ret = mma8452_trans_buff(msg, RBUFF_SIZE);
|
||||
if ( (ret = mma8452_get_cached_data(client, &sense_data) ) < 0 ) {
|
||||
printk("failed to get cached sense data, ret = %d.", ret);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case MMA_IOCTL_GETDATA:
|
||||
/*
|
||||
if (copy_to_user(argp, &msg, sizeof(msg)))
|
||||
return -EFAULT;
|
||||
*/
|
||||
if ( copy_to_user(argp, &sense_data, sizeof(sense_data) ) ) {
|
||||
printk("failed to copy sense data to user space.");
|
||||
return -EFAULT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mma8452_work_func(struct work_struct *work)
|
||||
{
|
||||
struct mma8452_data *mma8452 = container_of(work, struct mma8452_data, work);
|
||||
struct i2c_client *client = mma8452->client;
|
||||
|
||||
if (mma8452_get_data(client) < 0)
|
||||
mmaprintkd(KERN_ERR "MMA8452 mma_work_func: Get data failed\n");
|
||||
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
static void mma8452_delaywork_func(struct work_struct *work)
|
||||
{
|
||||
struct delayed_work *delaywork = container_of(work, struct delayed_work, work);
|
||||
struct mma8452_data *mma8452 = container_of(delaywork, struct mma8452_data, delaywork);
|
||||
struct i2c_client *client = mma8452->client;
|
||||
|
||||
if (mma8452_get_data(client) < 0)
|
||||
printk(KERN_ERR "MMA8452 mma_work_func: Get data failed\n");
|
||||
mmaprintkd("%s :int src:0x%02x\n",__FUNCTION__,mma845x_read_reg(mma8452->client,MMA8452_REG_INTSRC));
|
||||
enable_irq(client->irq);
|
||||
}
|
||||
|
||||
static irqreturn_t mma8452_interrupt(int irq, void *dev_id)
|
||||
{
|
||||
struct mma8452_data *mma8452 = (struct mma8452_data *)dev_id;
|
||||
|
||||
disable_irq_nosync(irq);
|
||||
schedule_delayed_work(&mma8452->delaywork, msecs_to_jiffies(30));
|
||||
mmaprintkf("%s :enter\n",__FUNCTION__);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static struct file_operations mma8452_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = mma8452_open,
|
||||
.release = mma8452_release,
|
||||
.unlocked_ioctl = mma8452_ioctl,
|
||||
};
|
||||
|
||||
static struct miscdevice mma8452_device = {
|
||||
.minor = MISC_DYNAMIC_MINOR,
|
||||
.name = "mma8452_daemon",//"mma8452_daemon",
|
||||
.fops = &mma8452_fops,
|
||||
};
|
||||
|
||||
static int mma8452_remove(struct i2c_client *client)
|
||||
{
|
||||
struct mma8452_data *mma8452 = i2c_get_clientdata(client);
|
||||
|
||||
misc_deregister(&mma8452_device);
|
||||
input_unregister_device(mma8452->input_dev);
|
||||
input_free_device(mma8452->input_dev);
|
||||
free_irq(client->irq, mma8452);
|
||||
kfree(mma8452);
|
||||
this_client = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id mma8452_id[] = {
|
||||
{"gs_mma8452", 0},
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct i2c_driver mma8452_driver = {
|
||||
.driver = {
|
||||
.name = "gs_mma8452",
|
||||
},
|
||||
.id_table = mma8452_id,
|
||||
.probe = mma8452_probe,
|
||||
.remove = __devexit_p(mma8452_remove),
|
||||
};
|
||||
|
||||
|
||||
static int mma8452_init_client(struct i2c_client *client)
|
||||
{
|
||||
struct mma8452_data *mma8452;
|
||||
int ret,irq;
|
||||
mma8452 = i2c_get_clientdata(client);
|
||||
mmaprintk("gpio_to_irq(%d) is %d\n",client->irq,gpio_to_irq(client->irq));
|
||||
if ( !gpio_is_valid(client->irq)) {
|
||||
mmaprintk("+++++++++++gpio_is_invalid\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = gpio_request(client->irq, "mma8452_int");
|
||||
if (ret) {
|
||||
mmaprintk( "failed to request mma7990_trig GPIO%d\n",gpio_to_irq(client->irq));
|
||||
return ret;
|
||||
}
|
||||
ret = gpio_direction_input(client->irq);
|
||||
if (ret) {
|
||||
mmaprintk("failed to set mma7990_trig GPIO gpio input\n");
|
||||
gpio_free(client->irq);
|
||||
return ret;
|
||||
}
|
||||
gpio_pull_updown(client->irq, GPIOPullUp);
|
||||
irq = gpio_to_irq(client->irq);
|
||||
ret = request_irq(irq, mma8452_interrupt, IRQF_TRIGGER_LOW, client->dev.driver->name, mma8452);
|
||||
mmaprintk("request irq is %d,ret is 0x%x\n",irq,ret);
|
||||
if (ret ) {
|
||||
gpio_free(client->irq);
|
||||
mmaprintk(KERN_ERR "mma8452_init_client: request irq failed,ret is %d\n",ret);
|
||||
return ret;
|
||||
}
|
||||
client->irq = irq;
|
||||
disable_irq(client->irq);
|
||||
init_waitqueue_head(&data_ready_wq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mma8452_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct mma8452_data *mma8452;
|
||||
struct gsensor_platform_data *pdata = pdata = client->dev.platform_data;
|
||||
int err;
|
||||
|
||||
mmaprintkf("%s enter\n",__FUNCTION__);
|
||||
|
||||
mma8452 = kzalloc(sizeof(struct mma8452_data), GFP_KERNEL);
|
||||
if (!mma8452) {
|
||||
mmaprintk("[mma8452]:alloc data failed.\n");
|
||||
err = -ENOMEM;
|
||||
goto exit_alloc_data_failed;
|
||||
}
|
||||
|
||||
INIT_WORK(&mma8452->work, mma8452_work_func);
|
||||
INIT_DELAYED_WORK(&mma8452->delaywork, mma8452_delaywork_func);
|
||||
|
||||
memset(&(mma8452->sense_data), 0, sizeof(struct mma8452_axis) );
|
||||
mutex_init(&(mma8452->sense_data_mutex) );
|
||||
|
||||
atomic_set(&(mma8452->data_ready), 0);
|
||||
init_waitqueue_head(&(mma8452->data_ready_wq) );
|
||||
|
||||
mma8452->start_count = 0;
|
||||
mutex_init(&(mma8452->operation_mutex) );
|
||||
|
||||
mma8452->status = MMA8452_CLOSE;
|
||||
|
||||
mma8452->client = client;
|
||||
i2c_set_clientdata(client, mma8452);
|
||||
|
||||
this_client = client;
|
||||
|
||||
devid = mma8452_get_devid(this_client);
|
||||
if ((MMA8452_DEVID != devid)
|
||||
&& (MMA8451_DEVID != devid)
|
||||
&& (MMA8453_DEVID != devid)) {
|
||||
pr_info("mma8452: invalid devid\n");
|
||||
goto exit_invalid_devid;
|
||||
}
|
||||
|
||||
err = mma8452_init_client(client);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_probe: mma8452_init_client failed\n");
|
||||
goto exit_request_gpio_irq_failed;
|
||||
}
|
||||
|
||||
mma8452->input_dev = input_allocate_device();
|
||||
if (!mma8452->input_dev) {
|
||||
err = -ENOMEM;
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_probe: Failed to allocate input device\n");
|
||||
goto exit_input_allocate_device_failed;
|
||||
}
|
||||
|
||||
set_bit(EV_ABS, mma8452->input_dev->evbit);
|
||||
|
||||
/* x-axis acceleration */
|
||||
input_set_abs_params(mma8452->input_dev, ABS_X, -MMA845X_RANGE, MMA845X_RANGE, 0, 0); //2g full scale range
|
||||
/* y-axis acceleration */
|
||||
input_set_abs_params(mma8452->input_dev, ABS_Y, -MMA845X_RANGE, MMA845X_RANGE, 0, 0); //2g full scale range
|
||||
/* z-axis acceleration */
|
||||
input_set_abs_params(mma8452->input_dev, ABS_Z, -MMA845X_RANGE, MMA845X_RANGE, 0, 0); //2g full scale range
|
||||
|
||||
// mma8452->input_dev->name = "compass";
|
||||
mma8452->input_dev->name = "gsensor";
|
||||
mma8452->input_dev->dev.parent = &client->dev;
|
||||
|
||||
err = input_register_device(mma8452->input_dev);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_probe: Unable to register input device: %s\n",
|
||||
mma8452->input_dev->name);
|
||||
goto exit_input_register_device_failed;
|
||||
}
|
||||
|
||||
mma8452_device.parent = &client->dev;
|
||||
err = misc_register(&mma8452_device);
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_probe: mmad_device register failed\n");
|
||||
goto exit_misc_device_register_mma8452_device_failed;
|
||||
}
|
||||
|
||||
err = gsensor_sysfs_init();
|
||||
if (err < 0) {
|
||||
mmaprintk(KERN_ERR
|
||||
"mma8452_probe: gsensor sysfs init failed\n");
|
||||
goto exit_gsensor_sysfs_init_failed;
|
||||
}
|
||||
|
||||
printk(KERN_INFO "mma8452 probe ok\n");
|
||||
#if 0
|
||||
// mma8452_start_test(this_client);
|
||||
mma8452_start(client, MMA8452_RATE_12P5);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
exit_gsensor_sysfs_init_failed:
|
||||
misc_deregister(&mma8452_device);
|
||||
exit_misc_device_register_mma8452_device_failed:
|
||||
input_unregister_device(mma8452->input_dev);
|
||||
exit_input_register_device_failed:
|
||||
input_free_device(mma8452->input_dev);
|
||||
exit_input_allocate_device_failed:
|
||||
free_irq(client->irq, mma8452);
|
||||
exit_request_gpio_irq_failed:
|
||||
cancel_delayed_work_sync(&mma8452->delaywork);
|
||||
cancel_work_sync(&mma8452->work);
|
||||
exit_invalid_devid:
|
||||
kfree(mma8452);
|
||||
exit_alloc_data_failed:
|
||||
;
|
||||
mmaprintk("%s error\n",__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int __init mma8452_i2c_init(void)
|
||||
{
|
||||
return i2c_add_driver(&mma8452_driver);
|
||||
}
|
||||
|
||||
static void __exit mma8452_i2c_exit(void)
|
||||
{
|
||||
i2c_del_driver(&mma8452_driver);
|
||||
}
|
||||
|
||||
module_init(mma8452_i2c_init);
|
||||
module_exit(mma8452_i2c_exit);
|
||||
|
||||
Reference in New Issue
Block a user