Writing a driver i2c for MPC6050

旧街凉风 提交于 2019-12-11 02:47:23

问题


I'm new in C, and I try to write a driver for MPC6050 accelerometer. (Kernel 3.4 for Android 4.2.2). This is the following of this question.

This page and this one helped me, but I can't use the driver yet:

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]

I'm working on /ANDROID/lichee/linux-3.4/arch/arm/mach-sun7i/core.c file. (the equivalent of board-machine.c)

I have pasted the struct of each structure base. The init functions are, I hope ok, like this:

/* 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,
    },
}; */

Now, my problem is to use and make active theses functions. I don't understand what means this:

static int __init omap4_panda_i2c_init(void)
{
        omap_register_i2c_bus(4, 400,
                              single_chip_board_info,
                              ARRAY_SIZE(single_chip_board_info));
}

I can't find the register_i2c_bus equivalent in my folders.

And at the end of the file, I will call it like this:

    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");
    }

So, my question is: How to make active my init functions, because omap is a very different system comparate to sun7i ?

Any help should be very appeciate! Thanks a lot.

Edit: With this documentation the compilation don't fail. The new dmesg is:

<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

来源:https://stackoverflow.com/questions/30253104/writing-a-driver-i2c-for-mpc6050

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!