我是C的新手,我尝试为MPC6050加速度计编写驱动程序。 (内核3.4 for Android 4.2.2)。这是以下question。
arch/arm/mach-sun7i/core.c:77:44: warning: ‘sun7i_i2c_platform_data’ defined but not used [-Wunused-variable]
arch/arm/mach-sun7i/core.c:136:41: warning: ‘sun7i_i2c_platform_device’ defined but not used [-Wunused-variable]
我正在处理 /ANDROID/lichee/linux-3.4/arch/arm/mach-sun7i/core.c 文件。 (相当于board-machine.c)
我已经粘贴了每个结构库的结构。 我希望init函数可以这样:
/* ACCELEROMETER*/
#include <linux/i2c-gpio.h>
#include <linux/mpu.h>
#include <linux/i2c.h>
#include <mach/i2c.h>
#include <mach/gpio.h>
#define I2C_SDA TWI_LCR_SDA_EN
#define I2C_SCL TWI_LCR_SCL_EN
/*
* /////////// from linux/i2c-gpio.h //////////
*
struct i2c_gpio_platform_data {
unsigned int sda_pin;
unsigned int scl_pin;
int udelay;
int timeout;
unsigned int sda_is_open_drain:1;
unsigned int scl_is_open_drain:1;
unsigned int scl_is_output_only:1;
}; */
static struct i2c_gpio_platform_data sun7i_i2c_platform_data = {
.sda_pin = I2C_SDA, // gpio number
.scl_pin = I2C_SCL,
.udelay = 5, // 100KHz
.sda_is_open_drain = 0,
.scl_is_open_drain = 0,
.scl_is_output_only = 0
};
/*
* /////////// from linux/mpu.h //////////
*
struct mpu_platform_data {
__u8 int_config;
__u8 level_shifter;
__s8 orientation[9];
enum secondary_slave_type sec_slave_type;
enum ext_slave_id sec_slave_id;
__u16 secondary_i2c_addr;
__s8 secondary_orientation[9];
__u8 key[16];
enum secondary_slave_type aux_slave_type;
enum ext_slave_id aux_slave_id;
__u16 aux_i2c_addr;
int (*power_on)(struct mpu_platform_data *);
int (*power_off)(struct mpu_platform_data *);
struct regulator *vdd_ana;
struct regulator *vdd_i2c;
};
*/
static struct mpu_platform_data gyro_platform_data = {
.int_config = 0x00,
.level_shifter = 0,
.orientation = { -1, 0, 0,
0, 1, 0,
0, 0, -1 },
.sec_slave_type = SECONDARY_SLAVE_TYPE_COMPASS,
.sec_slave_id = COMPASS_ID_AK8972,
.secondary_i2c_addr = 0x0E
};
/*
* /////////// from i2c.h //////////
*
* struct i2c_board_info {
char type[I2C_NAME_SIZE];
unsigned short flags;
unsigned short addr;
void *platform_data;
struct dev_archdata *archdata;
struct device_node *of_node;
int irq;
};*/
//for MPU6050
#define IRQ_GPIO SUN7I_IRQ_TWI0
#define TWI_STAT_REG (0x10) /* 28 interrupt types + 0xF8 normal type = 29 */
static struct i2c_board_info __initdata sun7i_i2c_platform_device[] = {
{
I2C_BOARD_INFO("mpu6050", 0x68),
.irq = (IRQ_GPIO + TWI_STAT_REG),
.platform_data = &gyro_platform_data,
},
};
/*
// ORIGINAL FROM THE README PAGE //
static struct i2c_board_info __initdata single_chip_board_info[] = {
{
I2C_BOARD_INFO("mpu6050", 0x68), // can be 0x34
.irq = (IH_GPIO_BASE + MPUIRQ_GPIO),
.platform_data = &gyro_platform_data,
},
}; */
现在,我的问题是使用并激活这些功能。我不明白这是什么意思:
static int __init omap4_panda_i2c_init(void)
{
omap_register_i2c_bus(4, 400,
single_chip_board_info,
ARRAY_SIZE(single_chip_board_info));
}
我无法在我的文件夹中找到register_i2c_bus
等效文件。
在文件末尾,我会这样称呼它:
static void __init sun7i_init(void)
{
pr_info("%s: enter\n", __func__);
sw_pdev_init();
/* Register platform devices here!! */
+ &sun7i_i2c_init();
+ pr_info("sun7i_i2c_init\n");
}
所以,我的问题是:如何激活我的init函数,因为omap是一个与sun7i非常不同的系统?
任何帮助都应该非常适合!非常感谢。
修改:使用此documentation,编辑不会失败。 新的dmesg是:
<3>[ 11.963914] inv-mpu-iio 1-0068: Unable to read axis_map_x
<3>[ 11.969998] i2c i2c-1: inv_mpu_probe failed -38
<4>[ 11.975080] inv-mpu-iio: probe of 1-0068 failed with error -5
<7>[ 11.975436] i2c-core: driver [inv-mpu-iio] registered