作者:奔跑的饼干的饼干桶_698 | 来源:互联网 | 2022-02-17 16:23
系统原来用的是BOSCH_BMA222的gsensor, 现在要求换成使用MMA7660,我们来看一下怎样增加驱动和调试过程。
1. 修改Makefie
首先,修改放置驱动的目录里的Makefile(kernel/driver/misc),添置如下语句:
代码如下:
obj-$(CONFIG_SENSORS_MMA7660) += mma7660.o
2. 增加驱动文件
把驱动文件mma7660.c添加到kernel/driver/misc下。
3. 修改.config文件,把下面两行注释掉
代码如下:
# CONFIG_BOSCH_SENSOR=y
# CONFIG_BOSCH_BMA222=y
再增加下面这项
代码如下:
CONFIG_SENSORS_MMA7660=y
编译,显示提示:
代码如下:
make uImage -j16
scripts/kconfig/conf -s arch/arm/Kconfig
*
* Restart config...
*
*
* Misc devices
*
Misc devices (MISC_DEVICES) [Y/n/?] y
Analog Devices AD525x Digital Potentiometers (AD525X_DPOT) [N/m/y/?] n
Android pmem allocator (ANDROID_PMEM) [N/y] n
Integrated Circuits ICS932S401 (ICS932S401) [N/m/y/?] n
Enclosure Services (ENCLOSURE_SERVICES) [N/m/y/?] n
Kernel Debugger Core (KERNEL_DEBUGGER_CORE) [N/y/?] n
Intersil ISL29003 ambient light sensor (ISL29003) [N/m/y/?] n
Taos TSL2550 ambient light sensor (SENSORS_TSL2550) [N/m/y/?] n
Dallas DS1682 Total Elapsed Time Recorder with Alarm (DS1682) [N/m/y/?] n
Texas Instruments DAC7512 (TI_DAC7512) [N/m/y/?] n
UID based statistics tracking exported to /proc/uid_stat (UID_STAT) [Y/n] y
Bluetooth power control driver for TI wl127x (WL127X_RFKILL) [N/m/y/?] n
Android kernel panic diagnostics driver (APANIC) [N/y/?] n
6 Axis sensor mpu3050 (SIX_AXIS_SENSOR_MPU3050) [N/y] n
Motion Processing Unit driver version
> 1. MPU version 2. MPU version >= v3.4.0 (MPU_NEW)
choice[1-2]: 1
BOSCH BMA222 acceleration sensor (BOSCH_SENSOR) [N/m/y/?] (NEW) N
*
* Miscellaneous I2C Chip support
*
BMA222 acceleration sensor support (BOSCH_BMA222) [N/m/y/?] (NEW) N
#
# configuration written to .config
这时看编译输出,系统没有编译mma7660.c, 而且编译后.config的MMA7660的宏也被覆盖掉了,所以这样是没有办法挂载的。之所以出现这个错误的原因,是因为make的时候会检查各个Kconfig文件,没有的选项会自动率掉,所以,我们还需要修改Kconfig文件。
5. 修改kernel/driver/misc/Kconfig,在menuconfig MISC_DEVICES下添加如下:
代码如下:
config SENSORS_MMA7660
tristate "MEMSIC Accelerometer Sensor MMA7660 Driver Support"
depends on I2C
help
If you say yes here you get support for the MEMSIC accelerometer sensor
6. 由于这里gsensor是一个i2c的外挂,所以,还必须修改板子的i2c的device信息,以便系统可以查找到设备。修改板子的资源文件(我这里的特例是./arch/arm/mach-meson3/board-m3-reff24.c),在结构aml_i2c_bus_info_1[]中添加一下信息:
代码如下:
#ifdef CONFIG_SENSORS_MMA7660
{
I2C_BOARD_INFO("mma7660", 0x4C),
.irq = INT_GPIO_2,
},
#endif
7. 再进行编译,驱动就被编译了。