diff options
author | Doug Anderson <dianders@chromium.org> | 2011-10-20 17:03:04 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2011-10-25 12:36:17 -0700 |
commit | f9d0e1ed66643829ae641a4e32ab9efa53126ba7 (patch) | |
tree | cd122e0050f44b2167403627577e5d55c6b38126 /board | |
parent | 3ae7bbe4138144f8767c56d6212b8c4c042b94c5 (diff) |
pmu: Make pmu_read() and pmu_write() set the bus number
This means that callers of pmu_read() and pmu_write() don't
need to manually set the bus number.
This also removes the side effect where pmu_set_nominal() could
end up changing the current i2c bus number.
BUG=chromium-os:21540
TEST=Compiled; sanity check on Seaboard.
Change-Id: I1e4abdb5b2f06e9e3bada3e709280f6092d15005
Signed-off-by: Doug Anderson <dianders@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/10461
Diffstat (limited to 'board')
-rw-r--r-- | board/nvidia/common/pmu.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/board/nvidia/common/pmu.c b/board/nvidia/common/pmu.c index 30e2de172f7..266d2c5cc61 100644 --- a/board/nvidia/common/pmu.c +++ b/board/nvidia/common/pmu.c @@ -52,31 +52,49 @@ int pmu_read(int reg) { int i; uchar data; + int retval = -1; + int old_bus_num; + + old_bus_num = i2c_get_bus_num(); + i2c_set_bus_num(DVC_I2C_BUS_NUMBER); for (i = 0; i < MAX_I2C_RETRY; ++i) { - if (!i2c_read(PMU_I2C_ADDRESS, reg, 1, &data, 1)) - return (int)data; + if (!i2c_read(PMU_I2C_ADDRESS, reg, 1, &data, 1)) { + retval = (int)data; + goto exit; + } /* i2c access failed, retry */ udelay(100); } - return -1; +exit: + i2c_set_bus_num(old_bus_num); + return retval; } int pmu_write(int reg, uchar *data, uint len) { - int i; + int i; + int retval = -1; + int old_bus_num; + + old_bus_num = i2c_get_bus_num(); + i2c_set_bus_num(DVC_I2C_BUS_NUMBER); for (i = 0; i < MAX_I2C_RETRY; ++i) { - if (!i2c_write(PMU_I2C_ADDRESS, reg, 1, data, len)) - return 0; + if (!i2c_write(PMU_I2C_ADDRESS, reg, 1, data, len)) { + retval = 0; + goto exit; + } /* i2c access failed, retry */ udelay(100); } - return -1; +exit: + i2c_set_bus_num(old_bus_num); + return retval; } #ifdef CONFIG_TEGRA_CLOCK_SCALING @@ -317,9 +335,6 @@ int pmu_set_nominal(void) if (vdd_init_nominal_table()) return -1; - /* select current i2c bus to DVC */ - i2c_set_bus_num(DVC_I2C_BUS_NUMBER); - /* Set SM1 in PWM-only mode */ if (pmu_set_pwm_mode(SM1_PWM_BIT)) return -1; |