diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-09-16 15:44:19 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-19 23:30:03 +0000 |
commit | 883dd51006600d78ccfc6c6ff73a66943492538e (patch) | |
tree | d1912eee4a95dfa385a87d7bbbca59a55fa2b137 /board/host/charger.c | |
parent | a7f5224a83ac58b569a0a3c3c95549d38f448171 (diff) | |
download | chrome-ec-883dd51006600d78ccfc6c6ff73a66943492538e.tar.gz |
cleanup: move test mocks to board/host and remove unused mocks
Now that we have a better test framework in place, mock
implementations go in either chip/host/ or board/host/, depending on
whether they're mocking chip or common/board functionality. Move the
remaining mocks there. Also, several mocks were neither compiled nor
used, and haven't kept pace with other refactoring; delete those.
BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all board; pass all unit tests
Change-Id: Ie2a81c3ccd4506679192d979aa87fe7ed6c1c5a0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/169873
Diffstat (limited to 'board/host/charger.c')
-rw-r--r-- | board/host/charger.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/board/host/charger.c b/board/host/charger.c new file mode 100644 index 0000000000..f63eebbea3 --- /dev/null +++ b/board/host/charger.c @@ -0,0 +1,137 @@ +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Mock battery charger driver. + */ + +#include "charger.h" +#include "console.h" +#include "common.h" +#include "smart_battery.h" +#include "uart.h" +#include "util.h" + +static const struct charger_info mock_charger_info = { + .name = "MockCharger", + .voltage_max = 19200, + .voltage_min = 1024, + .voltage_step = 16, + .current_max = 8192, + .current_min = 128, + .current_step = 128, + .input_current_max = 8064, + .input_current_min = 128, + .input_current_step = 128, +}; + +#define OPTION_CHARGE_INHIBIT (1 << 0) + +static uint32_t mock_option = 0; +static uint32_t mock_current = 0; +static uint32_t mock_voltage = 0; + +const struct charger_info *charger_get_info(void) +{ + return &mock_charger_info; +} + + +int charger_get_status(int *status) +{ + *status = CHARGER_LEVEL_2; + if (mock_option & CHARGE_FLAG_INHIBIT_CHARGE) + *status |= CHARGER_CHARGE_INHIBITED; + + return EC_SUCCESS; +} + + +int charger_set_mode(int mode) +{ + if (mode & CHARGE_FLAG_INHIBIT_CHARGE) + mock_option |= OPTION_CHARGE_INHIBIT; + else + mock_option &= ~OPTION_CHARGE_INHIBIT; + return EC_SUCCESS; +} + + +int charger_get_current(int *current) +{ + *current = mock_current; + return EC_SUCCESS; +} + + +int charger_set_current(int current) +{ + const struct charger_info *info = charger_get_info(); + + if (current > 0 && current < info->current_min) + current = info->current_min; + if (current > info->current_max) + current = info->current_max; + + if (mock_current != current) + uart_printf("Charger set current: %d\n", current); + mock_current = current; + return EC_SUCCESS; +} + +int charger_get_voltage(int *voltage) +{ + *voltage = mock_voltage; + return EC_SUCCESS; +} + + +int charger_set_voltage(int voltage) +{ + mock_voltage = voltage; + uart_printf("Charger set voltage: %d\n", voltage); + return EC_SUCCESS; +} + + +int charger_get_option(int *option) +{ + return EC_SUCCESS; +} + + +int charger_set_option(int option) +{ + return EC_SUCCESS; +} + + +int charger_manufacturer_id(int *id) +{ + return EC_SUCCESS; +} + + +int charger_device_id(int *id) +{ + return EC_SUCCESS; +} + + +int charger_get_input_current(int *input_current) +{ + return EC_SUCCESS; +} + + +int charger_set_input_current(int input_current) +{ + return EC_SUCCESS; +} + + +int charger_post_init(void) +{ + mock_current = CONFIG_CHARGER_INPUT_CURRENT; + return EC_SUCCESS; +} |