Ejemplo n.º 1
0
/* i2c_index can be from 0 - 2 */
void setup_i2c(unsigned i2c_index, int speed, int slave_addr,
		struct i2c_pads_info *p)
{
	if (i2c_index >= ARRAY_SIZE(i2c_bases))
		return;
	/* Enable i2c clock */
	enable_i2c_clk(1, i2c_index);
	/* Make sure bus is idle */
	force_idle_bus(p);
	bus_i2c_init(i2c_bases[i2c_index], speed, slave_addr,
			force_idle_bus, p);
}
Ejemplo n.º 2
0
/* i2c_index can be from 0 - 2 */
int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
	      struct i2c_pads_info *p)
{
	char name[9];
	int ret;

	if (i2c_index >= ARRAY_SIZE(i2c_bases))
		return -EINVAL;

	snprintf(name, sizeof(name), "i2c_sda%01d", i2c_index);
	ret = gpio_request(p->sda.gp, name);
	if (ret)
		return ret;

	snprintf(name, sizeof(name), "i2c_scl%01d", i2c_index);
	ret = gpio_request(p->scl.gp, name);
	if (ret)
		goto err_req;

	/* Enable i2c clock */
	ret = enable_i2c_clk(1, i2c_index);
	if (ret)
		goto err_clk;

	/* Make sure bus is idle */
	ret = force_idle_bus(p);
	if (ret)
		goto err_idle;

	bus_i2c_init(i2c_bases[i2c_index], speed, slave_addr,
			force_idle_bus, p);

	return 0;

err_idle:
err_clk:
	gpio_free(p->scl.gp);
err_req:
	gpio_free(p->sda.gp);

	return ret;
}