http://blog.csdn.net/macxen_gunter/article/details/10588859
1. 修改mediatek/config/project_name/projectconfig.mk
CUSTOM_KERNEL_ACCELEROMETER=mma865x_auto afa830_auto
MTK_AUTO_DETECT_ACCELEROMETER=yes
2. 将已经调试OK 的mma865x和afa830文件夹名字重命名为 mma865x_auto afa830_auto
mediatek/custom/common/kernel/accelerometer/mma865x_auto
mediatek/custom/common/kernel/accelerometer/afa830_auto
mediatek/custom/project_name/kernel/accelerometer/mma865x_auto
mediatek/custom/project_name/kernel/accelerometer/afa830_auto
3. 修改driver文件mma865x.c afa830.c
mediatek/custom/common/kernel/accelerometer/mma865x_auto/mma865x.c
mediatek/custom/common/kernel/accelerometer/afa830_auto/afa830.c
以mma865x为例 :
(1)打开
static unsigned short mma865x_force[] = {0x00, MMA865X_I2C_SLAVE_ADDR, I2C_CLIENT_END, I2C_CLIENT_END};
static const unsigned short *const mma865x_forces[] = { mma865x_force, NULL };
(2)在代码文件靠前部分声明函数
static int mma865x_local_init(void);
static int mma865x_remove(void);
static int mma865x_init_flag = -1;
(3)打开已定义或者定义
static struct sensor_init_info mma865x_init_info = {
.name = "mma865x",
.init = mma865x_local_init,
.uninit = mma865x_remove,
};
(4)修改I2C_driver 数据结构
将
static struct i2c_driver mma865x_i2c_driver = {
.driver = {
// .owner = THIS_MODULE,
.name = MMA865X_DEV_NAME,
},
.probe = mma865x_i2c_probe,
.remove = mma865x_i2c_remove,
.detect = mma865x_i2c_detect,
#if !defined(CONFIG_HAS_EARLYSUSPEND)
.suspend = mma865x_suspend,
.resume = mma865x_resume,
#endif
.id_table = mma865x_i2c_id,
// .address_data = &mma865x_addr_data,
};
修改为
static struct i2c_driver mma865x_i2c_driver = {
.driver = {
// .owner = THIS_MODULE,
.name = MMA865X_DEV_NAME,
},
.probe = mma865x_i2c_probe,
.remove = mma865x_i2c_remove,
.detect = mma865x_i2c_detect,
#if !defined(CONFIG_HAS_EARLYSUSPEND)
.suspend = mma865x_suspend,
.resume = mma865x_resume,
#endif
.id_table = mma865x_i2c_id,
.address_list = (const unsigned short*)mma865x_forces,
};
(5) 重命名函数
int gsensor_operate(void* self, uint32_t command, void* buff_in, int size_in,
void* buff_out, int size_out, int* actualout)
修改为
int mma865x_operate(void* self, uint32_t command, void* buff_in, int size_in,
void* buff_out, int size_out, int* actualout)
static long mma865x_unlocked_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
修改为
static int mma865x_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
(6) 修改相应的结构体
static struct file_operations mma865x_fops = {
.owner = THIS_MODULE,
.open = mma865x_open,
.release = mma865x_release,
.unlocked_ioctl = mma865x_unlocked_ioctl,
};
修改为
static struct file_operations mma865x_fops = {
.owner = THIS_MODULE,
.open = mma865x_open,
.release = mma865x_release,
.compat_ioctl = mma865x_ioctl,
};
(7)将文件中所有的
get_cust_acc_hw();
替换为
mma865x_get_cust_acc_hw();
(8)将文件中所有的
if(err = mma865x_create_attr(&mma865x_gsensor_driver.driver))
替换为
if(err = mma865x_create_attr(&mma865x_init_info.platform_diver_addr->driver))
(9)static int mma865x_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
函数中
sobj.sensor_operate = gsensor_operate;
修改为:
sobj.sensor_operate = mma865x_operate;
(10)打开已定义或者定义
static int mma865x_local_init(void)
{
struct acc_hw *hw = mma865x_get_cust_acc_hw();
GSE_FUN();
MMA865X_power(hw, 1);
mma865x_force[0] = hw->i2c_num;
if(i2c_add_driver(&mma865x_i2c_driver))
{
GSE_ERR("add driver error\n");
return -1;
}
if(-1 == mma865x_init_flag)
{
return -1;
}
}
static int mma865x_remove(void)
{
struct acc_hw *hw = mma865x_get_cust_acc_hw();
GSE_FUN();
MMA865X_power(hw, 0);
i2c_del_driver(&mma865x_i2c_driver);
return 0;
}
(11) 在static int __init mma865x_init(void) 中
使用
hwmsen_gsensor_add(&mma865x_init_info);
替换
if(platform_driver_register(&mma865x_gsensor_driver))
{
GSE_ERR("failed to register driver");
return -ENODEV;
}
4. 如下修改 mediatek/custom/project_name/kernel/accelerometer/mma865x_auto/cust_acc.c
#include <linux/types.h>
#include <cust_acc.h>
#include <mach/mt_pm_ldo.h>
/*---------------------------------------------------------------------------*/
int cust_acc_power(struct acc_hw *hw, unsigned int on, char* devname)
{
if (hw->power_id == MT65XX_POWER_NONE)
return 0;
if (on)
return hwPowerOn(hw->power_id, hw->power_vol, devname);
else
return hwPowerDown(hw->power_id, devname);
}
static struct acc_hw mma865x_cust_acc_hw = {
.i2c_num = 1,
.direction =1,// 6,
.power_id = MT65XX_POWER_NONE, /*!< LDO is not used */
.power_vol= VOL_DEFAULT, /*!< LDO is not used */
.firlen = 16, /*!< don't enable low pass fileter */
.power = cust_acc_power,
};
/*---------------------------------------------------------------------------*/
struct acc_hw* mma865x_get_cust_acc_hw(void)
{
return &mma865x_cust_acc_hw;
}
static struct acc_hw AFA830_cust_acc_hw = {
.i2c_num = 1,
.direction = 6,
.power_id = MT65XX_POWER_NONE, /*!< LDO is not used */
.power_vol= VOL_DEFAULT, /*!< LDO is not used */
.firlen = 16, /*!< don't enable low pass fileter */
.power = cust_acc_power,
};
/*---------------------------------------------------------------------------*/
struct acc_hw* AFA830_get_cust_acc_hw(void)
{
return &AFA830_cust_acc_hw;
}