static int oaktrail_hdmi_i2c_access(struct i2c_adapter *adap,
				struct i2c_msg *pmsg,
				int num)
{
	struct oaktrail_hdmi_dev *hdmi_dev = i2c_get_adapdata(adap);
	struct hdmi_i2c_dev *i2c_dev = hdmi_dev->i2c_dev;
	int i;

	mutex_lock(&i2c_dev->i2c_lock);

	/* Enable i2c unit */
	HDMI_WRITE(HDMI_ICRH, 0x00008760);

	/* Enable irq */
	hdmi_i2c_irq_enable(hdmi_dev);
	for (i = 0; i < num; i++) {
		if (pmsg->len && pmsg->buf) {
			if (pmsg->flags & I2C_M_RD)
				xfer_read(adap, pmsg);
			else
				xfer_write(adap, pmsg);
		}
		pmsg++;         /* next message */
	}

	/* Disable irq */
	hdmi_i2c_irq_disable(hdmi_dev);

	mutex_unlock(&i2c_dev->i2c_lock);

	return i;
}
Esempio n. 2
0
static int i2c_jz_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int count)
{
    int i, ret = 0;
    struct i2c_jz *i2c = adap->algo_data;

#ifdef CONFIG_I2C_DEBUG_INFO
    if (i2c->debug > DEBUG_WARN) {
        printk("\n\n\n");
        dev_info(&(i2c->adap.dev),
                 "%s, Begin master xfer, want to transfer msg count is %d\n",
                 __func__, count);
    }
#endif
    clk_enable(i2c->clk);

    i2c_writel(i2c, I2C_TAR, msg->addr);

    for (i = 0; i < count; i++, msg++) {
        enum msg_end_type end_type = MSG_END_STOP;
        if (i < (count - 1)) {
            if (msg[i + 1].flags & I2C_M_NOSTART) {
                end_type = MSG_END_CONTINUE;	/* have no STOP and START */
            } else {
                end_type = MSG_END_REPEAT_START;	/* have no STOP but have RESTART */
            }
        }

        INIT_COMPLETION(i2c->complete);

#ifdef CONFIG_I2C_DEBUG_INFO
        if (i2c->debug > DEBUG_WARN)
            dev_info(&(i2c->adap.dev),
                     "%s, Now transfer msg: %d\n", __func__, i);
#endif
        if (msg->flags & I2C_M_RD) {
            ret = xfer_read(i2c, msg->buf, msg->len, end_type);
        } else {
            ret = xfer_write(i2c, msg->buf, msg->len, end_type);
        }
        if (ret < 0) {
            clk_disable(i2c->clk);
            goto ERR;
        }
    }

    if (i2c_disable_clk(i2c)) {
        ret = -ETIMEDOUT;
        goto ERR;
    }

#ifdef CONFIG_I2C_DEBUG_INFO
    if (i2c->debug > DEBUG_WARN)
        dev_info(&(i2c->adap.dev),
                 "%s, Transfer msg over\n\n\n", __func__);
#endif

ERR:
    return ret ? : i;
}