Ejemplo n.º 1
0
static int saa7111_write_block(struct saa7111 *dev,
	       unsigned const char *data, unsigned int len)
{
	int ack = -1;
	unsigned subaddr;

	while (len > 1) {
		LOCK_I2C_BUS(dev->bus);
		i2c_start(dev->bus);
		i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
		ack = i2c_sendbyte(dev->bus, (subaddr = *data++), I2C_DELAY);
		ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
		len -= 2;
		while (len > 1 && *data == ++subaddr) {
			data++;
			ack =
			    i2c_sendbyte(dev->bus,
					 (dev->reg[subaddr] =
					  *data++), I2C_DELAY);
			len -= 2;
		}
		i2c_stop(dev->bus);
		UNLOCK_I2C_BUS(dev->bus);
	}
	return ack;
}
Ejemplo n.º 2
0
static void i2c_attach_device(struct i2c_bus *bus, struct i2c_driver *driver)
{
	struct i2c_device *device;
	int i,j,ack=1;
	unsigned char addr;
	LOCK_FLAGS;
    
	/* probe for device */
	LOCK_I2C_BUS(bus);
	for (addr = driver->addr_l; addr <= driver->addr_h; addr += 2) 
	{
		i2c_start(bus);
		ack = i2c_sendbyte(bus,addr,0);
		i2c_stop(bus);
		if (!ack)
			break;
	}
	UNLOCK_I2C_BUS(bus);
	if (ack)
		return;

	/* got answer */
	for (i = 0; i < I2C_DEVICE_MAX; i++)
		if (NULL == driver->devices[i])
			break;
	if (I2C_DEVICE_MAX == i)
		return;

	for (j = 0; j < I2C_DEVICE_MAX; j++)
		if (NULL == bus->devices[j])
			break;
	if (I2C_DEVICE_MAX == j)
		return;

	if (NULL == (device = kmalloc(sizeof(struct i2c_device),GFP_KERNEL)))
		return;
	device->bus = bus;
	device->driver = driver;
	device->addr = addr;

	/* Attach */
	
	if (driver->attach(device)!=0) 
	{
		kfree(device);
		return;
	}
	driver->devices[i] = device;
	driver->devcount++;
	bus->devices[j] = device;
	bus->devcount++;

	if (bus->attach_inform)
		bus->attach_inform(bus,driver->id);
	REGPRINT(printk("i2c: device attached: %s (addr=0x%02x, bus=%s, driver=%s)\n",device->name,addr,bus->name,driver->name));
}
Ejemplo n.º 3
0
static int saa7185_read(struct saa7185 *dev)
{
	int ack;

	LOCK_I2C_BUS(dev->bus);

	i2c_start(dev->bus);
	i2c_sendbyte(dev->bus, dev->addr | 1, I2C_DELAY);
	ack = i2c_readbyte(dev->bus, 1);
	i2c_stop(dev->bus);
	UNLOCK_I2C_BUS(dev->bus);
	return ack;
}
Ejemplo n.º 4
0
static
int saa7110_read(struct saa7110* decoder)
{
    int data;

    LOCK_I2C_BUS(decoder->bus);
    i2c_start(decoder->bus);
    i2c_sendbyte(decoder->bus, decoder->addr, I2C_DELAY);
    i2c_start(decoder->bus);
    i2c_sendbyte(decoder->bus, decoder->addr | 1, I2C_DELAY);
    data = i2c_readbyte(decoder->bus, 1);
    i2c_stop(decoder->bus);
    UNLOCK_I2C_BUS(decoder->bus);
    return data;
}
Ejemplo n.º 5
0
/* ----------------------------------------------------------------------- */
static
int saa7110_write(struct saa7110 *decoder, unsigned char subaddr, unsigned char data)
{
    int ack;

    LOCK_I2C_BUS(decoder->bus);
    i2c_start(decoder->bus);
    i2c_sendbyte(decoder->bus, decoder->addr, I2C_DELAY);
    i2c_sendbyte(decoder->bus, subaddr, I2C_DELAY);
    ack = i2c_sendbyte(decoder->bus, data, I2C_DELAY);
    i2c_stop(decoder->bus);
    decoder->reg[subaddr] = data;
    UNLOCK_I2C_BUS(decoder->bus);
    return ack;
}
Ejemplo n.º 6
0
static int saa7111_read(struct saa7111 *dev, unsigned char subaddr)
{
	int data;

	LOCK_I2C_BUS(dev->bus);
	i2c_start(dev->bus);
	i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
	i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
	i2c_start(dev->bus);
	i2c_sendbyte(dev->bus, dev->addr | 1, I2C_DELAY);
	data = i2c_readbyte(dev->bus, 1);
	i2c_stop(dev->bus);
	UNLOCK_I2C_BUS(dev->bus);
	return data;
}
Ejemplo n.º 7
0
static int bt856_write(struct bt856 *dev, unsigned char subaddr,
		       unsigned char data)
{
	int ack;

	LOCK_I2C_BUS(dev->bus);

	i2c_start(dev->bus);
	i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
	i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
	ack = i2c_sendbyte(dev->bus, data, I2C_DELAY);
	dev->reg[subaddr] = data;
	i2c_stop(dev->bus);
	UNLOCK_I2C_BUS(dev->bus);
	return ack;
}
Ejemplo n.º 8
0
int i2c_register_bus(struct i2c_bus *bus)
{
	int i,ack;
	LOCK_FLAGS;

	memset(bus->devices,0,sizeof(bus->devices));
	bus->devcount = 0;

	for (i = 0; i < I2C_BUS_MAX; i++)
		if (NULL == busses[i])
			break;
	if (I2C_BUS_MAX == i)
		return -ENOMEM;

	busses[i] = bus;
	bus_count++;
	REGPRINT(printk("i2c: bus registered: %s\n",bus->name));
	
	MOD_INC_USE_COUNT;

	if (scan) 
	{
		/* scan whole i2c bus */
		LOCK_I2C_BUS(bus);
		for (i = 0; i < 256; i+=2) 
		{
			i2c_start(bus);
			ack = i2c_sendbyte(bus,i,0);
			i2c_stop(bus);
			if (!ack) 
			{
				printk(KERN_INFO "i2c: scanning bus %s: found device at addr=0x%02x\n",
					bus->name,i);
			}
		}
		UNLOCK_I2C_BUS(bus);
	}

	/* probe available drivers */
	for (i = 0; i < I2C_DRIVER_MAX; i++)
		if (drivers[i])
			i2c_attach_device(bus,drivers[i]);
	return 0;
}
Ejemplo n.º 9
0
static
int saa7110_write_block(struct saa7110* decoder, unsigned const char *data, unsigned int len)
{
    unsigned subaddr = *data;

    LOCK_I2C_BUS(decoder->bus);
    i2c_start(decoder->bus);
    i2c_sendbyte(decoder->bus,decoder->addr,I2C_DELAY);
    while (len-- > 0) {
        if (i2c_sendbyte(decoder->bus,*data,0)) {
            i2c_stop(decoder->bus);
            UNLOCK_I2C_BUS(decoder->bus);
            return -EAGAIN;
        }
        decoder->reg[subaddr++] = *data++;
    }
    i2c_stop(decoder->bus);
    UNLOCK_I2C_BUS(decoder->bus);

    return 0;
}