int i2c_set_bus_speed(unsigned int speed) { struct i2c_bus *i2c_bus; i2c_bus = &i2c_controllers[i2c_bus_num]; i2c_bus->speed = speed; i2c_init_controller(i2c_bus); return 0; }
/* * Process a list of nodes, adding them to our list of I2C ports. * * @param blob fdt blob * @param node_list list of nodes to process (any <=0 are ignored) * @param count number of nodes to process * @param is_dvc 1 if these are DVC ports, 0 if standard I2C * @return 0 if ok, -1 on error */ static int process_nodes(const void *blob, int node_list[], int count, int is_dvc) { struct i2c_bus *i2c_bus; int i; /* build the i2c_controllers[] for each controller */ for (i = 0; i < count; i++) { int node = node_list[i]; if (node <= 0) continue; i2c_bus = &i2c_controllers[i]; i2c_bus->id = i; if (i2c_get_config(blob, node, i2c_bus)) { printf("i2c_init_board: failed to decode bus %d\n", i); return -1; } i2c_bus->is_dvc = is_dvc; if (is_dvc) { i2c_bus->control = &((struct dvc_ctlr *)i2c_bus->regs)->control; } else { i2c_bus->control = &i2c_bus->regs->control; } debug("%s: controller bus %d at %p, periph_id %d, speed %d: ", is_dvc ? "dvc" : "i2c", i, i2c_bus->regs, i2c_bus->periph_id, i2c_bus->speed); i2c_init_controller(i2c_bus); debug("ok\n"); i2c_bus->inited = 1; /* Mark position as used */ node_list[i] = -1; } return 0; }
void i2c_init_board(void) { struct i2c_bus *i2c_bus; int i; enum periph_id i2c_periph_ids[CONFIG_SYS_MAX_I2C_BUS] = { PERIPH_ID_DVC_I2C, PERIPH_ID_I2C1, PERIPH_ID_I2C2, PERIPH_ID_I2C3, #if defined(CONFIG_TEGRA3) PERIPH_ID_I2C4, #endif }; u32 *i2c_bus_base[CONFIG_SYS_MAX_I2C_BUS] = { #if defined(CONFIG_TEGRA2) (u32 *)NV_PA_DVC_BASE, (u32 *)NV_PA_I2C1_BASE, (u32 *)NV_PA_I2C2_BASE, (u32 *)NV_PA_I2C3_BASE, #endif #if defined(CONFIG_TEGRA3) (u32 *)NV_PA_I2C5_BASE, (u32 *)NV_PA_I2C1_BASE, (u32 *)NV_PA_I2C2_BASE, (u32 *)NV_PA_I2C3_BASE, (u32 *)NV_PA_I2C4_BASE, #endif }; #if defined(CONFIG_TEGRA2) /* pinmux_configs based on the pinmux configuration */ int pinmux_configs[CONFIG_SYS_MAX_I2C_BUS] = { CONFIG_I2CP_PIN_MUX, /* for I2CP (DVC I2C) */ CONFIG_I2C1_PIN_MUX, /* for I2C1 */ CONFIG_I2C2_PIN_MUX, /* for I2C2 */ CONFIG_I2C3_PIN_MUX /* for I2C3 */ }; #endif /* build the i2c_controllers[] for each controller */ for (i = 0; i < CONFIG_SYS_MAX_I2C_BUS; ++i) { i2c_bus = &i2c_controllers[i]; i2c_bus->id = i; i2c_bus->periph_id = i2c_periph_ids[i]; i2c_bus->regs = (struct i2c_ctlr *)i2c_bus_base[i]; #if defined(CONFIG_TEGRA2) i2c_bus->pinmux_config = pinmux_configs[i]; if (i2c_bus->periph_id == PERIPH_ID_DVC_I2C) { i2c_bus->control = &((struct dvc_ctlr *)i2c_bus->regs)->control; i2c_bus->use_dvc_ctlr = 1; } else #endif i2c_bus->control = &i2c_bus->regs->control; i2c_init_controller(i2c_bus, I2CSPEED_KHZ); } }