Sunday, July 14, 2013

Linux Driver I2C

Dans le driver:

Register a driver : i2c_add_driver()

static int __init mpr_touchkey_init(void)
{
    return i2c_add_driver(&mpr_touchkey_driver);
}
static struct i2c_driver mpr_touchkey_driver = {
    .driver = {
        .name  = "mpr121",
        .owner = THIS_MODULE,
        .pm    = &mpr121_touchkey_pm_ops,
    },
    .id_table = mpr121_id,
    .probe  = mpr_touchkey_probe,
    .remove = __devexit_p(mpr_touchkey_remove),
};
static const struct i2c_device_id mpr121_id[] = {
    {"mpr121_touchkey", 0},
    { }
};
MODULE_DEVICE_TABLE(i2c, mpr121_id);

Delete a driver : i2c_del_driver()

static void __exit mpr_touchkey_exit(void)
{
    i2c_del_driver(&mpr_touchkey_driver);
}

Dans le board file

Register the bus I2C : omap_register_i2c_bus()

static int __init tam3517_i2c_init(void)
{
    omap_register_i2c_bus(1, 400, tam3517_i2c1_boardinfo,
            ARRAY_SIZE(tam3517_i2c1_boardinfo));
    omap_register_i2c_bus(2, 400, tam3517_i2c2_boardinfo,
            ARRAY_SIZE(tam3517_i2c2_boardinfo));
    omap_register_i2c_bus(3, 400, tam3517_i2c3_boardinfo,
                    ARRAY_SIZE(tam3517_i2c3_boardinfo));
    return 0;
}

static struct i2c_board_info __initdata tam3517_i2c3_boardinfo[] = {
#if defined(CONFIG_KEYBOARD_MPR121) || defined(CONFIG_KEYBOARD_MPR121_MODULE)
    {
        I2C_BOARD_INFO("mpr121_touchkey", 0x5b),
//le nom doit correspondre lequel dans le i2c_device_id 
        .irq = OMAP_GPIO_IRQ(CONFIG_TAM3517_MPR121_BUTCAPA1_IRQ_GPIO),
        .platform_data = &mpr121_pdata,
    },
#endif

static struct mpr121_platform_data mpr121_pdata = {
    .keymap_size = ARRAY_SIZE(mpr121_touchkey_matrix),
    .keymap = mpr121_touchkey_matrix,
    .wakeup = 1,
    .vdd_uv = CONFIG_TAM3517_MPR121_TENSION,
};

static u16 mpr121_touchkey_matrix[3] = {
    KEY_0,KEY_1,KEY_2,
};

No comments:

Post a Comment