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

标签 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)。

#控制台日志

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/drivers/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”需要做什么样的修改?

请大家多多支持

最佳答案

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

根据您提供的代码,该结构应该是 struct pca953x_platform_data 类型并且 在 platform_data 字段中引用。

即(SABRE 精简板)

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

关于linux - I2C 设备驱动程序错误 [TCA6408 I/O 扩展器],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20698877/

相关文章:

linux - Linux 如何在 x86-64 中支持超过 512GB 的虚拟地址范围?

c - Linux 内核 : why do 'subclass' structs put base class info at end?

linux - 在 Linux 中将开始位和停止位发送到 i2c 总线?

c# - 如何在不取消链接的情况下关闭 shm_open 文件描述符?

linux - 在 linux 中使用 bash 脚本删除文件中的文本

linux - smtp配置位于solaris中的位置

linux - linux 中的 Probe() 方法是否需要重入?

linux - 未定义的对 -finstrument-functions 的引用

linux - CMAKE:忽略唯一变量名称

linux - 在 shell 脚本中保存预定后台进程的终端输出