i2c input设备读写出错

Creator_莫言 2014-12-11 12:01:55
我添加了一个i2c的键盘,probe函数调用后,里面读写i2c就会出错:

	
static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
{
I2C_BOARD_INFO("rtc-pcf8563", 0x51),
.type = "pcf8563",
},
{
I2C_BOARD_INFO("tca8424_keypad", 0x3b),
.type = "tca8424_keypad" ,
.irq = MX53_TCA6416_IRQ,
.platform_data = &tca8424_date,
}
};

i2c_register_board_info(2, mxc_i2c2_board_info,
ARRAY_SIZE(mxc_i2c2_board_info));

tca8424_keypad_probe()
{
....
int reg, error;
error = tca8424_read_byte(keypad_data, REG_HID_DESCRIP_LEN_L, ®);
if(error < 0)
printk("reg = 0x%x\n",reg);
....
}

这里读寄存器一直失败,
[ 53.020690] tca8424_keypad 2-003b: tca8424_read_byte failed, reg: 1, error: -110
[ 53.030669] tca8424_keypad: probe of 2-003b failed with error -110
请问添加一个i2c设备,从设备地址设置正确后,还需要其他设置吗?从设备地址正确了不就可以读写从设备了吗?那为什么还会读写出错呢。刚接触i2c,望大神不吝赐教!
...全文
416 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Creator_莫言 2014-12-12
  • 打赏
  • 举报
回复
另外,同一个总选i2c2 下的rtc设备,可以读写i2c,我测量过SCL和SDA信号正常,但是我添加的设备就完全没有信号。中断也无法产生
Creator_莫言 2014-12-12
  • 打赏
  • 举报
回复
引用 2 楼 xuweiwei1860 的回复:
你的代码不是很全 不过在probe里面一般还是不会去读写的啊
我重新贴一下probe的代码。

static int tca8424_keypad_probe(struct i2c_client *client,
					  const struct i2c_device_id *id)
{
	struct device *dev = &client->dev;
	const struct tca8424_keypad_platform_data *pdata =
						dev_get_platdata(dev);
	struct tca8424_keypad *keypad_data;
	struct input_dev *input;
	const struct matrix_keymap_data *keymap_data = NULL;
	u32 rows = 0, cols = 0;
	bool rep = false;
	bool irq_is_gpio = false;
	int irq;
	int error, row_shift, max_keys;

	/* Copy the platform data */
	if (pdata) {
		if (!pdata->keymap_data) {
			dev_err(dev, "no keymap data defined\n");
			return -EINVAL;
		}
		keymap_data = pdata->keymap_data;
		rows = pdata->rows;
		cols = pdata->cols;
		rep  = pdata->rep;
		irq_is_gpio = pdata->irq_is_gpio;
	}/* else {
		struct device_node *np = dev->of_node;
		int err;

		err = matrix_keypad_parse_of_params(dev, &rows, &cols);
		if (err)
			return err;
		rep = of_property_read_bool(np, "keypad,autorepeat");
	}*/

	if (!rows || rows > TCA8424_MAX_ROWS) {
		dev_err(dev, "invalid rows\n");
		return -EINVAL;
	}

	if (!cols || cols > TCA8424_MAX_COLS) {
		dev_err(dev, "invalid columns\n");
		return -EINVAL;
	}

	/* Check i2c driver capabilities */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
		dev_err(dev, "%s adapter not supported\n",
			dev_driver_string(&client->adapter->dev));
		return -ENODEV;
	}

	row_shift = get_count_order(cols);
	max_keys = rows << row_shift;

	/* Allocate memory for keypad_data and input device */
	keypad_data = devm_kzalloc(dev, sizeof(*keypad_data), GFP_KERNEL);
	if (!keypad_data)
		return -ENOMEM;

	keypad_data->client = client;
	keypad_data->row_shift = row_shift;
	keypad_data->input = input;

	i2c_set_clientdata(client, keypad_data);

	/* Initialize the chip or fail if chip isn't present */
	error = tca8424_configure(keypad_data, rows, cols);
	if (error < 0)
		return error;

	/* Configure input device 
	input = devm_input_allocate_device(dev);
	if (!input)
		return -ENOMEM;*/

	input = input_allocate_device();
	if (!input) {
		error = -ENOMEM;
		return error;
	}
	printk("2-----row = %d,cols = %d\n",rows,cols);


	input->phys = "tca8424-keys/input0";
	input->name = client->name;
	input->id.bustype = BUS_I2C;
	input->id.vendor  = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0001;

	input->keycode = keymap_data->keymap;
	printk("3----------%d,keymap[0]=%d | %d\n",keymap_data->keymap_size,keymap_data->keymap[1],KEY(0, 6, KEY_RESERVED));

	matrix_keypad_build_keymap(keymap_data, row_shift, input->keycode, input->keybit);
	if (!input->keybit) {
		dev_err(dev, "Failed to build keymap\n");
		return error;
	}
	
	if (rep)
		__set_bit(EV_REP, input->evbit);
	input_set_capability(input, EV_MSC, MSC_SCAN);

	input_set_drvdata(input, keypad_data);

	irq = client->irq;
	if (irq_is_gpio)
		irq = gpio_to_irq(irq);

	printk("5----------%d,%d\n",irq,!tca8424_irq_handler);
	error = devm_request_threaded_irq(dev, irq, NULL, tca8424_irq_handler,
					  IRQF_TRIGGER_FALLING |
//						IRQF_SHARED |
						IRQF_ONESHOT,
					  client->name, keypad_data);
	if (error) {
		dev_err(dev, "Unable to claim irq %d; error %d\n",
			client->irq, error);
		return error;
	}

	error = input_register_device(input);
	if (error) {
		dev_err(dev, "Unable to register input device, error: %d\n",
			error);
		return error;
	}
	printk("[TCA8424] tca8424_keypad_probe.\n");
	return 0;
}
insmod 之后的信息是: [ 30.554067] tca8424_keypad 2-003b: tca8424_read_byte failed, reg: 514, error: -5 [ 30.563805] tca8424_keypad: probe of 2-003b failed with error -5 另外probe里面读写i2c应该也没有问题吧?需要配置一些寄存器之类的,读写i2c也可以看出i2c是否正常
Creator_莫言 2014-12-12
  • 打赏
  • 举报
回复
引用 1 楼 echolog 的回复:
1.要查I2C地址是7Bit还是8bit 2.从设备的供电情况
设备地址是7位的,最后一位是读写标志位
fly 100% 2014-12-12
  • 打赏
  • 举报
回复
你的代码不是很全 不过在probe里面一般还是不会去读写的啊
echolog 2014-12-11
  • 打赏
  • 举报
回复
1.要查I2C地址是7Bit还是8bit 2.从设备的供电情况

1,319

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧