Exemple #1
0
static int intel_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs)
{
	struct intel_i2c *i2c = dev_get_priv(bus);
	struct i2c_msg *dmsg, *omsg, dummy;

	debug("i2c_xfer: %d messages\n", nmsgs);

	memset(&dummy, 0, sizeof(struct i2c_msg));

	/*
	 * We expect either two messages (one with an offset and one with the
	 * actucal data) or one message (just data)
	 */
	if (nmsgs > 2 || nmsgs == 0) {
		debug("%s: Only one or two messages are supported", __func__);
		return -EIO;
	}

	omsg = nmsgs == 1 ? &dummy : msg;
	dmsg = nmsgs == 1 ? msg : msg + 1;

	if (dmsg->flags & I2C_M_RD)
		return smbus_block_read(i2c->base, dmsg->addr, &dmsg->buf[0],
					omsg->buf[0], dmsg->len);
	else
		return smbus_block_write(i2c->base, dmsg->addr, &dmsg->buf[1],
					 dmsg->buf[0], dmsg->len - 1);
}
Exemple #2
0
static void ics954309_init(struct device *dev)
{
    struct drivers_ics_954309_config *config;
    u8 initdata[12];

    if (!dev->enabled || dev->path.type != DEVICE_PATH_I2C)
        return;

    config = dev->chip_info;

    initdata[0] = config->reg0;
    initdata[1] = config->reg1;
    initdata[2] = config->reg2;
    initdata[3] = config->reg3;
    initdata[4] = config->reg4;
    initdata[5] = config->reg5;
    initdata[6] = config->reg6;
    initdata[7] = config->reg7;
    initdata[8] = config->reg8;
    initdata[9] = config->reg9;
    initdata[10] = config->reg10;
    initdata[11] = config->reg11;

    smbus_block_write(dev, 0, 12, initdata);
}