Quantcast
Channel: CSDN博客移动开发推荐文章
Viewing all articles
Browse latest Browse all 5930

Android Sensor详解(3)porting drvier

$
0
0

kernel层porting

复制kernel driver file到相关目录

将cm36xxx.c复制到 drivers/input/misc中
将cm36xxx.h,lightsensor.h,capella_cm3602.h复制到kernel/include/linux中

修改/arch/arm/boot/dts/qcom/下的dtsi问题

查看电路图,看看driver它挂在什么地方,然后找到spec看driver的i2c address。

提取信息如下:sensor挂在bus6上,i2c adress为0x60,interrupt连接到SOC的gpio43上

因而我们可以修改相关的dtsi文件如下:

cm36xxx@60 {
         compatible = "capella,cm36xxx";
          reg = <0x60>;
          capella,slave_address = <0x60>;
          interrupt-parent = <&tlmm>; 
          interrupts = <43 0x2>;
          capella,intrpin-gpios = <&tlmm 43 0x2>;
           vio-supply = <&pm8953_l6>;
    };

这里要注意:compatible要与kernel driver中的cm36xxx_match_table中的compatible一致

修改makefile使能够编译driver

修改kernel/drivers/input/misc/Makefile

obj-$(CONFIG_SENSORS_CM36656) += cm36656.o

修改kernel/drivers/input/misc/Kconfig

config SENSORS_CM36xxx
tristate “CM36xxx optical sensor”
depends on I2C
default n
help
Say Y here to enable the CM36xxx Optical Sensor.

修改kernel/arch/arm64/configs/xxxx_defconfig

CONFIG_SENSORS_CM36xxx=y

修改相关权限

注意kernel driver中的misc的name

static const struct file_operations rgbsensor_fops = {
    .owner = THIS_MODULE,
    .open = rgbsensor_open,
    .release = rgbsensor_release,
    .unlocked_ioctl = rgbsensor_ioctl,
    .compat_ioctl = rgbsensor_ioctl,
};
static struct miscdevice rgbsensor_misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = "asusRgbSensor",
    .fops = &rgbsensor_fops
};

注意:rgb使用32位的lib因而需要compat_ioctl

修改system/core/rootdir/ueventd.rc

/dev/lightsensor 0640 system system
/dev/proximitySensor 0640 compass system
/dev/asusRgbSensor 0640 system system

修改init.rc文件

on post-fs-data
chown system system /dev/proximitySensor
chmod 0660 /dev/proximitySensor
chown system system /dev/lightsensor
chmod 0660 /dev/lightsensor

HAL层porting

这个很简单,只要在编译的时候能够load android.mk即可编译
注意open的目录名字与设备名字要相同

编译改错

一般厂商给的demo code在编译时都会出一些错误,因而需要我们BSP进行修正。这边会在后续的博客中解释。

作者:u013983194 发表于2017/2/23 16:50:59 原文链接
阅读:21 评论:0 查看评论

Viewing all articles
Browse latest Browse all 5930

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>