本帖最后由 yueyesighhz 于 2014-12-17 15:12 编辑
我用TI的TCA8424,在board文件中定义如下:
static struct imxi2c_platform_data mxci2c_data = {
.bitrate = 20000,
};
static struct tca8424_keypad_platform_data tca8424_date = {
.keymap_data = &tca8424_mkdata,
.rows=16,
.cols=8,
.rep=1,
.irq_is_gpio=1,
};
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
},
};
设备地址是7位的,可以肯定是3b。照我的理解这样注册之后,就应该可以和i2c通信了,但是在probe函数中读写i2c就会失败。查看日子是没有ack。
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;
#if 1
/* 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_DATA)) {
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;
// printk("^^^^^^^^^^^\n",keypad_data->);
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;
#endif
/* Configure input device
input = devm_input_allocate_device(dev);
if (!input)
return -ENOMEM;*/
keypad_data->input = input;
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;
}
里面的tca8424_configure()函数就有读写i2c:
error = i2c_smbus_write_byte_data(keypad_data->client,REG_COMMAND_REG_L,COMMAND_RESET);
if(error < 0)
printk("reset device error!\n");
串口打印:
[ 38.293434] i2c i2c-2: master_xfer[0] W, addr=0x43, len=2
[ 38.301546] i2c i2c-2: <i2c_imx_xfer>
[ 38.305247] i2c i2c-2: <i2c_imx_start>
[ 38.309079] i2c i2c-2: <i2c_imx_bus_busy>
[ 38.313105] i2c i2c-2: <i2c_imx_xfer> transfer message: 0
[ 38.318522] i2c i2c-2: <i2c_imx_xfer> CONTROL: IEN=1, IIEN=1, MSTA=1, MTX=1, TXAK=1, RSTA=0
[ 38.326890] i2c i2c-2: <i2c_imx_xfer> STATUS: ICF=1, IAAS=0, IBB=1, IAL=0, SRW=0, IIF=0, RXAK=1
[ 38.335660] i2c i2c-2: <i2c_imx_write> write slave address: addr=0x86
[ 38.342748] i2c i2c-2: <i2c_imx_trx_complete> TRX complete
[ 38.348252] i2c i2c-2: <i2c_imx_acked> No ACK
[ 38.352619] i2c i2c-2: <i2c_imx_stop>
[ 38.356291] i2c i2c-2: <i2c_imx_bus_busy>
[ 38.360313] i2c i2c-2: <i2c_imx_xfer> exit with: error: -5
[ 38.365815] tca8424_keypad 2-0043: tca8424_write_byte failed, reg: 1536, val: 27, error: -5
请问可能是什么原因导致从设备没有返回ACK呢?
|