[Wrong e-mail address first time, sorry for that]
On Tuesday 15 December 2009 09:47:22 Albert Burbea wrote:
> Hi everybody,

Hi,

> I would like to know how can I use an I2C device inside a device driver.
> The problem is that I wish to leave the I2C available to other application
> on the platform, and I do not wish to do add_driver every time I need
> access to the I2C from the driver. Actually I need a handle that is always
> open in the driver.

I use something like this for my touchscreen driver:

static int davinci_tsc2004_read(u8 size, u8 * val, u16 addr)
{
        struct i2c_adapter *adap;
        int err;
        struct i2c_msg msg[1];

        adap = i2c_get_adapter(1);
        if (!adap)
                return -ENODEV;

        msg->addr = addr;
        msg->flags = I2C_M_RD;
        msg->len = size;
        msg->buf = val;

        err = i2c_transfer(adap, msg, 1);
        if (err >= 0)
                return 0;

        return err;
}

Write operation is smilar, just using 0 instead of I2C_M_RD.

> Also, can I use the I2C driver in an isr handling code?

I don't think so, though I don't known new threaded interrupt handlers.

You should schedule a workqueue in your isr handler and use i2c calls in 
workqueue. Again from my touchscreendriver:

static void tsc_workqueue_handler(struct work_struct *work)
{
        /* Actual I2C stuff */
}
DECLARE_WORK(tsc_wq, tsc_workqueue_handler);
static irqreturn_t tsc2004_ts_irq_handler(int irq, void *dev_id)
{
        /*
         * Schedule the workqueue for I2C transfers
         */
        schedule_work(&tsc_wq);

        return IRQ_HANDLED;
}

Best regards,
Caglar

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to