配置
/mediatek/config/$(project)/ProjectConfig.mk 添加sensor
# accelerometer sensor to detect accelerometer from x y z axis.
CUSTOM_KERNEL_ACCELEROMETER=bma050
# ALSPS sensor driverto detect ambint light and the object is close or far awary from device
CUSTOM_KERNEL_ALSPS=cm36283
Hwmsen注释:
alps/mediatek/kernel/drivers/hwmon/hwmsen/hwmsen_dev.c 中:
hwmsen_unlocked_ioctl提供这个接口给上层调用。
hwmsen_gsensor_add提供来添加G-Sensor。
hwmsen_msensor_add来添加M-sensor。
1)添加驱动程序
对应目录mediatek/custom/common/kernel/
例如: mediatek/custom/commom/kernel/alsps/cm3628c/cm36283.c & .h
包含:设备注册:
static int __init cm36283_init(void)
{
//APS_FUN();
struct alsps_hw *hw = get_cust_alsps_hw();
APS_LOG("%s: i2c_number=%d\n", __func__,hw->i2c_num);
i2c_register_board_info(hw->i2c_num, &i2c_cm36283, 1);
if(platform_driver_register(&cm36283_alsps_driver))
{
APS_ERR("failed to register driver");
return -ENODEV;
}
return 0;
}
驱动Driver:
/*----------------------------------------------------------------------------*/
static struct platform_driver cm36283_alsps_driver = {
.probe = cm36283_probe,
.remove = cm36283_remove,
.driver = {
.name = "als_ps",
}
};
static struct miscdevice cm36283_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "als_ps",
.fops = &cm36283_fops,
};
/*------------------------------misc device related operation functions------------------------------------*/
static struct file_operations cm36283_fops = {
.owner = THIS_MODULE,
.open = cm36283_open,
.release = cm36283_release,
.unlocked_ioctl = cm36283_unlocked_ioctl,
};
static int cm36283_probe(struct platform_device *pdev)
{
//APS_FUN();
struct alsps_hw *hw = get_cust_alsps_hw();
cm36283_power(hw, 1); //*****************
if(i2c_add_driver(&cm36283_i2c_driver))
{
APS_ERR("add driver error\n");
return -1;
}
return 0;
}
I2C部分驱动
#define CM36283_DEV_NAME "cm36283"
static const struct i2c_device_id cm36283_i2c_id[] = {{CM36283_DEV_NAME,0},{}};
static struct i2c_board_info __initdata i2c_cm36283={ I2C_BOARD_INFO(CM36283_DEV_NAME, 0x60)};
static struct i2c_driver cm36283_i2c_driver = {
.probe = cm36283_i2c_probe,
.remove = cm36283_i2c_remove,
.detect = cm36283_i2c_detect,
.suspend = cm36283_i2c_suspend,
.resume = cm36283_i2c_resume,
.id_table = cm36283_i2c_id,
.driver = {
.name = CM36283_DEV_NAME,
},
};
cm36283_i2c_probe() 函数中实现与hwmsen_dev.c挂钩。把设备注册到hwmsev device中。
即:hwmsen_attach(ID_PROXIMITY, &obj_ps);其功能Sensor device driver attach to hwmsen device。
二、与项目相关参数定义
mediatek/custom/projectname/kernel/alspls/cm36283.c
三、HAL接口层
在底层驱动中明明正确加载了gsensor,msensor,psensor等驱动了,并没有出现I2C错误(传感器都是I2C器件),但是在系统中启动
时hwsen_open()时,将系统添加的传感器遍历时,报出sensor(?)没有添加成功,或者在上层应用中启动这些传感器时,并不能成功
打开。例如指南针不能用(msensor),系统设置中不能横竖屏(gsensor),打电话的时候电话靠近时屏幕不灭(psensor)。
出现以上系统驱动加载成功,但是系统上层始终都不能够启动传感器和启动对应的传感器的服务,一般问题就是出在中间层。
在MTK中的mediatek/custom/($项目名)/hal/sensors/sensor/hwmsen_custom.h中没有添加响应的传感器。
导致上层在加载传感器模块的时候(sensor_module_init()),不能找到对应的传感器进行添加。所以就表现出加载传感器驱动正常,
但是上层不能启用传感器的现象。
mediatek/custom/($项目名)/hal/sensors/sensor/hwmsen_custom.h