Beispiel #1
0
struct i2c_client_t * i2c_client_alloc(const char * i2cbus, int addr, int flags)
{
	struct i2c_client_t * client;
	struct i2c_t * i2c;

	i2c = search_bus_i2c(i2cbus);
	if(!i2c)
		return NULL;

	if(flags & I2C_M_TEN)
	{
		/* 10-bit address, all values are valid */
		if(addr > 0x3ff)
			return NULL;
	}
	else
	{
		/*
		 * 7-bit address, reject the general call address
		 *
		 * Reserved addresses per I2C specification:
		 *  0x00       General call address / START byte
		 *  0x01       CBUS address
		 *  0x02       Reserved for different bus format
		 *  0x03       Reserved for future purposes
		 *  0x04-0x07  Hs-mode master code
		 *  0x78-0x7b  10-bit slave addressing
		 *  0x7c-0x7f  Reserved for future purposes
		 */
		if(addr < 0x08 || addr > 0x77)
			return NULL;
	}

	client = malloc(sizeof(struct i2c_client_t));
	if(!client)
		return NULL;

	client->i2c = i2c;
	client->addr = addr;
	client->flags = flags;

	return client;
}
Beispiel #2
0
static bool_t realview_unregister_i2c_bus(struct resource_t * res)
{
	struct i2c_t * i2c;
	char name[64];

	snprintf(name, sizeof(name), "%s.%d", res->name, res->id);

	i2c = search_bus_i2c(name);
	if(!i2c)
		return FALSE;

	if(!unregister_bus_i2c(i2c))
		return FALSE;

	free(i2c->priv);
	free(i2c->name);
	free(i2c);
	return TRUE;
}