diff options
Diffstat (limited to 'src/soc/nvidia')
-rw-r--r-- | src/soc/nvidia/tegra/i2c.c | 18 | ||||
-rw-r--r-- | src/soc/nvidia/tegra/i2c.h | 2 | ||||
-rw-r--r-- | src/soc/nvidia/tegra124/i2c.c | 2 | ||||
-rw-r--r-- | src/soc/nvidia/tegra132/i2c.c | 2 |
4 files changed, 22 insertions, 2 deletions
diff --git a/src/soc/nvidia/tegra/i2c.c b/src/soc/nvidia/tegra/i2c.c index 1d5df3c342..2ba1700730 100644 --- a/src/soc/nvidia/tegra/i2c.c +++ b/src/soc/nvidia/tegra/i2c.c @@ -194,8 +194,14 @@ static int i2c_transfer_segment(unsigned bus, unsigned chip, int restart, int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count) { struct i2c_seg *seg = segments; - int i; + + if (bus >= g_num_i2c_buses) { + printk(BIOS_ERR, "%s: ERROR: invalid I2C bus (%u)\n", __func__, + bus); + return -1; + } + for (i = 0; i < count; seg++, i++) { if (i2c_transfer_segment(bus, seg->chip, i < count - 1, seg->read, seg->buf, seg->len)) @@ -206,7 +212,15 @@ int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count) void i2c_init(unsigned bus) { - struct tegra_i2c_regs * const regs = tegra_i2c_info[bus].base; + struct tegra_i2c_regs *regs; + + if (bus >= g_num_i2c_buses) { + printk(BIOS_ERR, "%s: ERROR: invalid I2C bus (%u)\n", __func__, + bus); + return; + } + + regs = tegra_i2c_info[bus].base; write32(®s->cnfg, I2C_CNFG_PACKET_MODE_EN); } diff --git a/src/soc/nvidia/tegra/i2c.h b/src/soc/nvidia/tegra/i2c.h index 9d7de14a1e..e81fd1c3e8 100644 --- a/src/soc/nvidia/tegra/i2c.h +++ b/src/soc/nvidia/tegra/i2c.h @@ -172,4 +172,6 @@ struct tegra_i2c_regs { }; check_member(tegra_i2c_regs, config_load, 0x8C); +extern unsigned g_num_i2c_buses; + #endif /* __SOC_NVIDIA_TEGRA_I2C_H__ */ diff --git a/src/soc/nvidia/tegra124/i2c.c b/src/soc/nvidia/tegra124/i2c.c index a7eee686b0..824862b27d 100644 --- a/src/soc/nvidia/tegra124/i2c.c +++ b/src/soc/nvidia/tegra124/i2c.c @@ -53,3 +53,5 @@ struct tegra_i2c_bus_info tegra_i2c_info[] = { .reset_func = &clock_reset_x } }; + +unsigned g_num_i2c_buses = ARRAY_SIZE(tegra_i2c_info); diff --git a/src/soc/nvidia/tegra132/i2c.c b/src/soc/nvidia/tegra132/i2c.c index dc85806967..b0ab31a563 100644 --- a/src/soc/nvidia/tegra132/i2c.c +++ b/src/soc/nvidia/tegra132/i2c.c @@ -53,3 +53,5 @@ struct tegra_i2c_bus_info tegra_i2c_info[] = { .reset_func = &clock_reset_x } }; + +unsigned g_num_i2c_buses = ARRAY_SIZE(tegra_i2c_info); |