I2C设备驱动程序错误[TCA6408 I / O扩展器]

时间:2013-12-20 08:02:58

标签: linux linux-device-driver embedded-linux kernel-module

我想连接TCA6408 IO扩展器并获取我的嵌入式系统的密钥输入。 我正在尝试使用SABRELite(iMX6Q)Boad,我的开发环境是LTIB(L3.0.35_4.1.0_130816_source.tar.gz)

我做了以下修改

1。)在“board-mx6q_sabrelite.c”中添加一个条目

static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
    {
          I2C_BOARD_INFO("pca953x", 0x21),
          .irq = gpio_to_irq(MX6Q_SABRELITE_CAP_TCH_INT1),
    },
};

2.。从menuconfig

启用驱动程序
---  GPIO Support
< * > PCA953x, PCA955x, TCA64xx, and MAX7310 I/O ports
[ * ]         Interrupt controller support for PCA953x

启动系统时,驱动程序注册正常。 但是在Probe()函数中有一个错误(pca953x:探测器2-0020失败,错误-22)。

#Console Log

Freescale USB OTG Driver loaded, $Revision: 1.55 $
pca953x: probe of 2-0020 failed with error -22
imx-ipuv3 imx-ipuv3.0: IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)
imx-ipuv3 imx-ipuv3.1: IPU DMFC NORMAL mode: 1(0~1), 5B(4,5), 5F(6,7)
mxc_mipi_csi2 mxc_mipi_csi2: i.MX MIPI CSI2 driver probed
mxc_mipi_csi2 mxc_mipi_csi2: i.MX MIPI CSI2 dphy version is 0x3130302a
MIPI CSI2 driver module loaded
Advanced Linux Sound Architecture Driver Version 1.0.24.

因(pdata == NULL)

而发生此错误

的linux-3.0.35 /驱动器/ GPIO / pca953x.c

static int __devinit pca953x_probe(struct i2c_client *client,
               const struct i2c_device_id *id)
{
struct pca953x_platform_data *pdata;
struct pca953x_chip *chip;
int ret = 0;

chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
if (chip == NULL)
    return -ENOMEM;

pdata = client->dev.platform_data;
if (pdata == NULL) {
    pdata = pca953x_get_alt_pdata(client);
    /*
     * Unlike normal platform_data, this is allocated
     * dynamically and must be freed in the driver
     */
    chip->dyn_pdata = pdata;
}

if (pdata == NULL) {
    dev_dbg(&client->dev, "no platform data\n");
    ret = -EINVAL;
    goto out_failed;
}

我无法理解这个问题。 “platform_data”需要什么样的修改?

任何人都请支持我。

2 个答案:

答案 0 :(得分:2)

您需要在i2c_board_info结构中提供一些平台数据。

根据您提供的代码,结构应为struct pca953x_platform_data和 在platform_data字段中引用。

即。 (SABRE Lite Board)

static struct pca953x_platform_data my_pca953x_pdata = {
     .gpio_base = MX6Q_PAD_GPIO_5__I2C3_SCL,
};

static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
    {
          I2C_BOARD_INFO("pca953x", 0x21),
          .irq = gpio_to_irq(MX6Q_SABRELITE_CAP_TCH_INT1),
          .platform_data = &my_pca953x_pdata
    },
};

答案 1 :(得分:1)

以下是am3517板和tca6416的示例。 platform_data指定应从哪个GPIO编号新GPIO计数。例如OMAP_MAX_GPIO_LINES 128,那么第一个tca6416 GPIO将是128 + 1 = 129。

static struct pca953x_platform_data sp860_gpio_expander_info_0 = {
        .gpio_base      = OMAP_MAX_GPIO_LINES,
};
static struct i2c_board_info __initdata am3517evm_i2c2_boardinfo[] = {
        {
                I2C_BOARD_INFO("tca6416", 0x20),
                .platform_data = &sp860_gpio_expander_info_0,
        },
};

您可以在此platform_data结构中设置以下参数:

struct pca953x_platform_data {
        /* number of the first GPIO */
        unsigned        gpio_base;

        /* initial polarity inversion setting */
        uint16_t        invert;

        /* interrupt base */
        int             irq_base;

        void            *context;       /* param to setup/teardown */

        int             (*setup)(struct i2c_client *client,
                                unsigned gpio, unsigned ngpio,
                                void *context);
        int             (*teardown)(struct i2c_client *client,
                                unsigned gpio, unsigned ngpio,
                                void *context);
        const char      *const *names;
};