2010-09-01 07:39:25 I2C help
Martin Jensby (DENMARK)
Message: 93018
Hi
Hope you can help me out a little bit
I am trying to write a driver that basically is irq driven.
What I am trying to accomplish is when I get the irq I want to read an I2C device
I don't know what I am doing wrong but when I try to modprobe or insmod my module I never get the probe print
and if I trigger and IRQ the driver obviously stack traces.
Futher more I can't seem to find any information as to how I add the I2C address of the device.
I have been looking at the ad7879.c driver for reference.
Thank you
My code is as the following
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/interrupt.h>
static struct i2c_device_id capsense_touch_wheel_idtable[] = {
{ "capsense_touch_wheel" },
{ }
};
MODULE_DEVICE_TABLE(i2c, capsense_touch_wheel_idtable);
static irqreturn_t capsense_touch_wheel_handler(int irq, void *dev_id)
{
printk("irq handled dev_id %d\n", dev_id);
struct i2c_client *client = dev_id;
int ret = i2c_smbus_read_byte(client);
printk("read from i2c 0x%x\n", ret);
return IRQ_HANDLED;
}
static int __devinit capsense_touch_wheel_probe(struct i2c_client *client, const struct i2c_device_id *id) {
int err = -ENOMEM;
printk("probing...\n");
/* We want to trigger on the falling egde */
err = set_irq_type(IRQ_PG10, IRQF_TRIGGER_FALLING);
if(err)
return err;
else
printk("irq type set ok\n");
/* Request the IRQ */
err = request_irq(IRQ_PG10, capsense_touch_wheel_handler, 0, "Touch wheel", NULL);
if(err)
return err;
else
printk("request IRQ_PG10 ok\n");
return 0;
}
static int __devexit capsense_touch_wheel_remove(struct i2c_client *client) {
printk("removing...\n");
free_irq(IRQ_PG10, NULL);
return 0;
}
static struct i2c_driver capsense_touch_wheel_driver = {
.driver = {
.name = "capsense_touch_wheel",
},
.probe = capsense_touch_wheel_probe,
.remove = capsense_touch_wheel_remove,
.id_table = capsense_touch_wheel_idtable,
};
static int __init capsense_touch_wheel_init(void)
{
printk("init...\n");
return i2c_add_driver(&capsense_touch_wheel_driver);
};
static void __exit capsense_touch_wheel_exit(void)
{
printk("exit...\n");
i2c_del_driver(&capsense_touch_wheel_driver);
};
module_init(capsense_touch_wheel_init);
module_exit(capsense_touch_wheel_exit);
QuoteReplyEditDelete
2010-09-01 08:32:58 Re: I2C help
Aaron Wu (CHINA)
Message: 93024
see if file like arch/blackfin/mach-bf518/boards/ezbrd.c will help you
QuoteReplyEditDelete
2010-09-01 10:23:53 Re: I2C help
Martin Jensby (DENMARK)
Message: 93029
I have added the following lines to my board file
{
I2C_BOARD_INFO("capsense_touch_wheel", 0x19),
.irq = IRQ_PG10,
},
in the I2C section, but I still only see the init line.
I guess the string is what ties the address to the driver I am trying to write.
QuoteReplyEditDelete
2010-09-01 10:50:25 Re: I2C help
Martin Jensby (DENMARK)
Message: 93030
Apparently very long strings doesn't work, as I should have thought of before.
But now I'm getting my probe
Thank you for your help
QuoteReplyEditDelete
2010-09-02 02:43:58 Re: I2C help
Sonic Zhang (CHINA)
Message: 93045
You can't do call I2C api from IRQ handler directly. Do it in a workqueue activated in the IRQ handler.
QuoteReplyEditDelete
2010-09-02 08:51:49 Re: I2C help
Martin Jensby (DENMARK)
Message: 93074
Hi
I changed it to work before reading you post.
And my driver now works as I expect.
Thank you for all your help